You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tika.apache.org by ju...@apache.org on 2011/01/17 12:17:51 UTC
svn commit: r1059877 - in
/tika/trunk/tika-core/src/main/java/org/apache/tika: fork/ForkServer.java
parser/ParseContext.java
Author: jukka
Date: Mon Jan 17 11:17:51 2011
New Revision: 1059877
URL: http://svn.apache.org/viewvc?rev=1059877&view=rev
Log:
TIKA-416: Out-of-process text extraction
Make ParseContext more lightweight for easier serialization.
Some ForkServer javadocs.
Modified:
tika/trunk/tika-core/src/main/java/org/apache/tika/fork/ForkServer.java
tika/trunk/tika-core/src/main/java/org/apache/tika/parser/ParseContext.java
Modified: tika/trunk/tika-core/src/main/java/org/apache/tika/fork/ForkServer.java
URL: http://svn.apache.org/viewvc/tika/trunk/tika-core/src/main/java/org/apache/tika/fork/ForkServer.java?rev=1059877&r1=1059876&r2=1059877&view=diff
==============================================================================
--- tika/trunk/tika-core/src/main/java/org/apache/tika/fork/ForkServer.java (original)
+++ tika/trunk/tika-core/src/main/java/org/apache/tika/fork/ForkServer.java Mon Jan 17 11:17:51 2011
@@ -43,9 +43,18 @@ class ForkServer extends ClassLoader {
public static final byte FIND_RESOURCES = 3;
+ /**
+ * Starts a forked server process.
+ *
+ * @param args command line arguments, ignored
+ * @throws Exception if the server could not be started
+ */
public static void main(String[] args) throws Exception {
ForkServer server =
new ForkServer(System.in, System.out);
+
+ // Set the server instance as the context class loader
+ // to make classes from the parent process available
Thread.currentThread().setContextClassLoader(server);
// Redirect standard input and output streams to prevent
@@ -53,6 +62,7 @@ class ForkServer extends ClassLoader {
System.setIn(new ByteArrayInputStream(new byte[0]));
System.setOut(System.err);
+ // Start processing request
server.run();
}
@@ -62,6 +72,14 @@ class ForkServer extends ClassLoader {
private int count = 0;
+ /**
+ * Sets up a forked server instance using the given stdin/out
+ * communication channel.
+ *
+ * @param input input stream for reading from the parent process
+ * @param output output stream for writing to the parent process
+ * @throws IOException if the server instance could not be created
+ */
public ForkServer(InputStream input, OutputStream output)
throws IOException {
this.input = new DataInputStream(input);
Modified: tika/trunk/tika-core/src/main/java/org/apache/tika/parser/ParseContext.java
URL: http://svn.apache.org/viewvc/tika/trunk/tika-core/src/main/java/org/apache/tika/parser/ParseContext.java?rev=1059877&r1=1059876&r2=1059877&view=diff
==============================================================================
--- tika/trunk/tika-core/src/main/java/org/apache/tika/parser/ParseContext.java (original)
+++ tika/trunk/tika-core/src/main/java/org/apache/tika/parser/ParseContext.java Mon Jan 17 11:17:51 2011
@@ -38,23 +38,48 @@ import org.xml.sax.SAXNotSupportedExcept
*/
public class ParseContext implements Serializable {
- /**
- * Serial version UID.
- */
+ /** Serial version UID. */
private static final long serialVersionUID = -5921436862145826534L;
- private final Map<Class<?>, Object> context =
- new HashMap<Class<?>, Object>();
+ /** Map of objects in this context */
+ private final Map<String, Object> context = new HashMap<String, Object>();
+ /**
+ * Adds the given value to the context as an implementation of the given
+ * interface.
+ *
+ * @param key the interface implemented by the given value
+ * @param value the value to be added, or <code>null</code> to remove
+ */
public <T> void set(Class<T> key, T value) {
- context.put(key, value);
+ if (value != null) {
+ context.put(key.getName(), value);
+ } else {
+ context.remove(key.getName());
+ }
}
+ /**
+ * Returns the object in this context that implements the given interface.
+ *
+ * @param key the interface implemented by the requested object
+ * @return the object that implements the given interface,
+ * or <code>null</code> if not found
+ */
@SuppressWarnings("unchecked")
public <T> T get(Class<T> key) {
- return (T) context.get(key);
+ return (T) context.get(key.getName());
}
+ /**
+ * Returns the object in this context that implements the given interface,
+ * or the given default value if such an object is not found.
+ *
+ * @param key the interface implemented by the requested object
+ * @param defaultValue value to return if the requested object is not found
+ * @return the object that implements the given interface,
+ * or the given default value if not found
+ */
public <T> T get(Class<T> key, T defaultValue) {
T value = get(key);
if (value != null) {