From 0727bb1e63061cd875495446e7d4979a8c411e5a Mon Sep 17 00:00:00 2001 From: det Date: Wed, 11 Jun 2008 18:43:12 +0000 Subject: [PATCH] rework of console message handling; add of debugging output git-svn-id: https://svn.berlios.de/svnroot/repos/yacy/trunk@4914 6c8d7289-2bf4-0310-a012-ef5d649a1542 --- source/de/anomic/tools/diskUsage.java | 113 ++++++++++++++++---- source/de/anomic/yacy/resourceObserver.java | 6 ++ 2 files changed, 99 insertions(+), 20 deletions(-) diff --git a/source/de/anomic/tools/diskUsage.java b/source/de/anomic/tools/diskUsage.java index 80f21710f..2a136cf30 100644 --- a/source/de/anomic/tools/diskUsage.java +++ b/source/de/anomic/tools/diskUsage.java @@ -49,14 +49,19 @@ package de.anomic.tools; import java.io.BufferedReader; import java.io.File; import java.io.IOException; +import java.io.InputStream; import java.io.InputStreamReader; import java.util.ArrayList; import java.util.HashMap; +import java.util.Iterator; +// FIXME entfernen +import de.anomic.server.logging.serverLog; import de.anomic.plasma.plasmaSwitchboard; public class diskUsage { - +// FIXME entfernen + private serverLog log = new serverLog("DISK USAGE"); private static final HashMap diskUsages = new HashMap(); private static final ArrayList allVolumes = new ArrayList(); @@ -71,6 +76,7 @@ public class diskUsage { private static boolean usable; private static String windowsCommand; private static String errorMessage; + private static boolean consoleError; // Unix-like @@ -215,28 +221,21 @@ public class diskUsage { if (usedOS != TRU64 && usedOS != HAIKU) processArgs.add("-l"); - ProcessBuilder processBuilder = new ProcessBuilder(processArgs); - Process process; - try { - process = processBuilder.start(); - } catch (IOException e){ - errorMessage = "The system command df returned with an error"; - usable = false; - return; - } - - BufferedReader bufferedReader = new BufferedReader(new InputStreamReader (process.getInputStream ())); - String line; - while (true) { - try { - line = bufferedReader.readLine (); - } catch (IOException e) { + ArrayList lines = getConsoleOutput(processArgs); + if (consoleError) { + errorMessage = "df:"; + Iterator iter = lines.iterator(); + while (iter.hasNext()){ + errorMessage += "\n" + iter.next(); usable = false; return; } - if (line == null) - break; - if (! line.startsWith ("/")) + } + + Iterator iter = lines.iterator(); + while (iter.hasNext()){ + String line = iter.next(); + if (! line.startsWith ("/")) continue; String[] tokens = line.split(" ++", 6); if (tokens.length < 6) @@ -445,5 +444,79 @@ nextLine: } } } + + + private ArrayList getConsoleOutput (ArrayList processArgs) { + ArrayList list = new ArrayList(); + ProcessBuilder processBuilder = new ProcessBuilder(processArgs); + Process process = null; + consoleInterface inputStream = null; + consoleInterface errorStream = null; + consoleError = false; + + try { + process = processBuilder.start();; + + inputStream = new consoleInterface(process.getInputStream()); + errorStream = new consoleInterface(process.getErrorStream()); + + inputStream.start(); + errorStream.start(); + + int retval = process.waitFor(); + + } catch(IOException iox) { + consoleError = true; + log.logWarning("logpoint 0 " + iox.getMessage()); + list.add(iox.getMessage()); + return list; + } catch(InterruptedException ix) { + consoleError = true; + log.logWarning("logpoint 1 " + ix.getMessage()); + list.add(ix.getMessage()); + return list; + } + list = inputStream.getOutput(); + if (list.isEmpty()) { + consoleError = true; + log.logWarning("logpoint 2 "); + return errorStream.getOutput(); + } else + return list; + } + + public class consoleInterface extends Thread + { + private InputStream stream; + private boolean getInputStream; + private ArrayList output; + + public consoleInterface (InputStream stream) + { + this.stream = stream; + output = new ArrayList(); + } + + public void run() { + try { + InputStreamReader input = new InputStreamReader(stream); + BufferedReader buffer = new BufferedReader(input); + String line = null; + int tries = 1000; + while (tries-- > 0) { + if (buffer.ready()) + break; + } + log.logInfo("logpoint 3 " + tries + " tries"); + while((line = buffer.readLine()) != null) { + output.add(line); + } + } catch(IOException ix) { log.logWarning("logpoint 4 " + ix.getMessage());} + } + + public ArrayList getOutput(){ + return output; + } + } } diff --git a/source/de/anomic/yacy/resourceObserver.java b/source/de/anomic/yacy/resourceObserver.java index 5f009b2d9..90133ef06 100644 --- a/source/de/anomic/yacy/resourceObserver.java +++ b/source/de/anomic/yacy/resourceObserver.java @@ -108,6 +108,12 @@ public final class resourceObserver { sb.pauseCrawlJob(plasmaSwitchboard.CRAWLJOB_REMOTE_TRIGGERED_CRAWL); } } + else { + if (du.getUsable ()) + this.log.logInfo("run completed; everything in order"); + else + this.log.logInfo("The observer is out of order"); + } return true; }