idok-commit AT lists.psi.ch
Subject: Commit emails of the iDok project
List archive
[idok-commit] idok commit r348 - trunk/java/ch/idok/dmsd/impl/extractor/microsoft
Chronological Thread
- From: "AFS account Stadler Hans Christian" <stadler_h AT savannah.psi.ch>
- To: idok-commit AT lists.psi.ch
- Subject: [idok-commit] idok commit r348 - trunk/java/ch/idok/dmsd/impl/extractor/microsoft
- Date: Mon, 23 Mar 2009 11:39:11 +0100
- List-archive: <https://lists.web.psi.ch/pipermail/idok-commit/>
- List-id: Commit emails of the iDok project <idok-commit.lists.psi.ch>
Author: stadler_h
Date: Mon Mar 23 11:39:11 2009
New Revision: 348
Log:
Killing OO if it cannot be shutdown properly (e.g. if it is in an infinite
loop); Improved property handling
Modified:
trunk/java/ch/idok/dmsd/impl/extractor/microsoft/MSOfficeExtractorFactory.java
trunk/java/ch/idok/dmsd/impl/extractor/microsoft/OOProcess.java
Modified:
trunk/java/ch/idok/dmsd/impl/extractor/microsoft/MSOfficeExtractorFactory.java
==============================================================================
---
trunk/java/ch/idok/dmsd/impl/extractor/microsoft/MSOfficeExtractorFactory.java
(original)
+++
trunk/java/ch/idok/dmsd/impl/extractor/microsoft/MSOfficeExtractorFactory.java
Mon Mar 23 11:39:11 2009
@@ -100,7 +100,12 @@
* @brief Maximum delay in ms for process startup
*/
private long processStartupTimeout = 5000;
-
+
+ /**
+ * @brief Timeout for idle input streams
+ */
+ long streamReaderTimeout = 20000;
+
/**
* @brief Class implementing a thread for reading an error stream.
*/
@@ -146,7 +151,7 @@
}
/**
- * @brief Run method that reads the error stream.
+ * @brief Run method that reads the input stream.
*/
public void run() {
Throwable ex = null;
@@ -162,7 +167,7 @@
if (stopNow)
break;
}
- if (System.currentTimeMillis() - now > 20000) {
+ if (System.currentTimeMillis() - now >
streamReaderTimeout) {
logger.warning("See no point in idling any
longer");
break;
}
@@ -284,7 +289,7 @@
if (len < 0) {
break;
} else if (len == 0) {
- Thread.sleep(1000);
+ Thread.sleep(10);
} else {
length -= len;
offset += len;
@@ -468,17 +473,31 @@
}
}
+ /**
+ * @brief Get long valued system property
+ * @param name System property name
+ * @param def Default value
+ * @return Long value of the system property
+ * @throws DmsException If the long value cannot be parsed correctly
+ */
+ public static long getLong(String name, long def) throws DmsException {
+ try {
+ return Long.parseLong(System.getProperty(name,
Long.toString(def)));
+ } catch (NumberFormatException ex) {
+ throw new DmsException(ErrorType.BAD_ARG, name, "Invalid system
property value",
+ "The system property " + name + " doesn't have a value
of type long", ex);
+ }
+ }
+
/** @see ContentExtractorFactory.initialize() */
public void initialize(Config config) throws DmsException {
try {
logger = config.getLogger("dmsd.impl.extractor.microsoft");
logger.finest("Initializing extractor factory for MS Office
Documents.");
- interruptDelay =
Long.parseLong(System.getProperty("ch.idok.dmsd.impl.extractor.microsoft.interruptdelay",
- Long.toString(interruptDelay)));
- processKillTimeout =
Long.parseLong(System.getProperty("ch.idok.dmsd.impl.extractor.microsoft.killtimeout",
- Long.toString(processKillTimeout)));
- processStartupTimeout =
Long.parseLong(System.getProperty("ch.idok.dmsd.impl.extractor.microsoft.starttimeout",
- Long.toString(processStartupTimeout)));
+ interruptDelay =
getLong("ch.idok.dmsd.impl.extractor.microsoft.interruptDelay",
interruptDelay);
+ processKillTimeout =
getLong("ch.idok.dmsd.impl.extractor.microsoft.processKillTimeout",
processKillTimeout);
+ processStartupTimeout =
getLong("ch.idok.dmsd.impl.extractor.microsoft.processStartupTimeout",
processStartupTimeout);
+ streamReaderTimeout =
getLong("ch.idok.dmsd.impl.extractor.microsoft.streamReaderTimeout",
streamReaderTimeout);
initOO();
Runtime.getRuntime().addShutdownHook(new Thread (new Runnable() {
@Override
@@ -495,13 +514,8 @@
docType);
config.registerContentExtractor(msfac.getMimeType(), msfac);
}
- } catch (NumberFormatException ex) {
- DmsException.throwIt(ErrorType.BAD_ARG, this, "Initialization
error.",
- "One of the following properties has no long value:\n" +
- "ch.idok.dmsd.impl.extractor.microsoft.interruptdelay\n"
+
- "ch.idok.dmsd.impl.extractor.microsoft.starttimeout\n" +
- "ch.idok.dmsd.impl.extractor.microsoft.killtimeout",
- ex);
+ } catch (DmsException ex) {
+ throw ex;
} catch (Throwable th) {
DmsException.throwIt(ErrorType.INTERNAL, this, "Bug detected",
Util.stackTraceToString(th), th);
}
Modified: trunk/java/ch/idok/dmsd/impl/extractor/microsoft/OOProcess.java
==============================================================================
--- trunk/java/ch/idok/dmsd/impl/extractor/microsoft/OOProcess.java
(original)
+++ trunk/java/ch/idok/dmsd/impl/extractor/microsoft/OOProcess.java Mon
Mar 23 11:39:11 2009
@@ -70,6 +70,11 @@
private int desktopTerminationDelay = 1000;
/**
+ * @brief Timeout for orderly OO shutdown
+ */
+ private int desktopTerminationTimeout = 1000;
+
+ /**
* @brief Delay in ms after terminating the OO desktop
*/
private int processKillDelay = 2000;
@@ -219,7 +224,10 @@
screen =
System.getProperty("ch.idok.dmsd.impl.extractor.microsoft.screen", screen);
desktopTerminationDelay = Integer.parseInt(
System.getProperty("ch.idok.dmsd.impl.extractor.microsoft.desktoptTerminationDelay",
- Integer.toString(processKillDelay)));
+ Integer.toString(desktopTerminationDelay)));
+ desktopTerminationTimeout = Integer.parseInt(
+
System.getProperty("ch.idok.dmsd.impl.extractor.microsoft.desktoptTerminationTimeout",
+ Integer.toString(desktopTerminationTimeout)));
processKillDelay = Integer.parseInt(
System.getProperty("ch.idok.dmsd.impl.extractor.microsoft.processKillDelay",
Integer.toString(processKillDelay)));
@@ -244,7 +252,7 @@
}
}));
} catch (Throwable th) {
- logger.warning("Unable to set all properties");
+ logger.warning("Initialization error\n" +
Util.stackTraceToString(th));
}
}
@@ -255,13 +263,17 @@
void stop() {
if (desktop != null) {
logger.finest("Terminating desktop");
+ Timer timer = new Timer();
try {
+ timer.schedule(new ProcessTimeout(soffice, logger),
desktopTerminationTimeout);
desktop.terminate();
+ timer.cancel();
Thread.sleep(desktopTerminationDelay);
} catch (Throwable th) {
logger.finer("Can't terminate OO desktop\n"+th);
}finally {
desktop = null;
+ timer.cancel();
}
}
if (soffice != null) {
- [idok-commit] idok commit r348 - trunk/java/ch/idok/dmsd/impl/extractor/microsoft, AFS account Stadler Hans Christian, 03/23/2009
Archive powered by MHonArc 2.6.19.