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/03 19:13:36 UTC

svn commit: r1054696 - in /tika/trunk/tika-core/src/main/java/org/apache/tika/config: LoadErrorHandler.java ServiceLoader.java

Author: jukka
Date: Mon Jan  3 18:13:36 2011
New Revision: 1054696

URL: http://svn.apache.org/viewvc?rev=1054696&view=rev
Log:
TIKA-569: More fault-tolerant loading of parsers and detectors

Add javadocs for the LoadErrorHandler interface

Modified:
    tika/trunk/tika-core/src/main/java/org/apache/tika/config/LoadErrorHandler.java
    tika/trunk/tika-core/src/main/java/org/apache/tika/config/ServiceLoader.java

Modified: tika/trunk/tika-core/src/main/java/org/apache/tika/config/LoadErrorHandler.java
URL: http://svn.apache.org/viewvc/tika/trunk/tika-core/src/main/java/org/apache/tika/config/LoadErrorHandler.java?rev=1054696&r1=1054695&r2=1054696&view=diff
==============================================================================
--- tika/trunk/tika-core/src/main/java/org/apache/tika/config/LoadErrorHandler.java (original)
+++ tika/trunk/tika-core/src/main/java/org/apache/tika/config/LoadErrorHandler.java Mon Jan  3 18:13:36 2011
@@ -19,15 +19,39 @@ package org.apache.tika.config;
 import java.util.logging.Level;
 import java.util.logging.Logger;
 
+/**
+ * Interface for error handling strategies in service class loading.
+ * You can implement this interface for a custom error handling mechanism,
+ * or use one of the predefined strategies.
+ *
+ * @since Apache Tika 0.9
+ */
 public interface LoadErrorHandler {
 
+    /**
+     * Handles a problem encountered when trying to load the specified
+     * service class. The implementation can log or otherwise process
+     * the given error information. If the method returns normally, then
+     * the service loader simply skips this class and continues with the
+     * next one.
+     *
+     * @param classname name of the service class
+     * @param throwable the encountered problem
+     */
     void handleLoadError(String classname, Throwable throwable);
 
+    /**
+     * Strategy that simply ignores all problems.
+     */
     LoadErrorHandler IGNORE = new LoadErrorHandler() {
         public void handleLoadError(String classname, Throwable throwable) {
         }
     };
 
+    /**
+     * Strategy that logs warnings of all problems using a {@link Logger}
+     * created using the given class name.
+     */
     LoadErrorHandler WARN = new LoadErrorHandler() {
         public void handleLoadError(String classname, Throwable throwable) {
             Logger.getLogger(classname).log(
@@ -35,6 +59,11 @@ public interface LoadErrorHandler {
         }
     };
 
+    /**
+     * Strategy that throws a {@link RuntimeException} with the given
+     * throwable as the root cause, thus interrupting the entire service
+     * loading operation.
+     */
     LoadErrorHandler THROW = new LoadErrorHandler() {
         public void handleLoadError(String classname, Throwable throwable) {
             throw new RuntimeException("Unable to load " + classname, throwable);

Modified: tika/trunk/tika-core/src/main/java/org/apache/tika/config/ServiceLoader.java
URL: http://svn.apache.org/viewvc/tika/trunk/tika-core/src/main/java/org/apache/tika/config/ServiceLoader.java?rev=1054696&r1=1054695&r2=1054696&view=diff
==============================================================================
--- tika/trunk/tika-core/src/main/java/org/apache/tika/config/ServiceLoader.java (original)
+++ tika/trunk/tika-core/src/main/java/org/apache/tika/config/ServiceLoader.java Mon Jan  3 18:13:36 2011
@@ -108,13 +108,13 @@ public class ServiceLoader {
             Set<String> names = new HashSet<String>();
 
             try {
-                String path = "META-INF/services/" + service.getName();
-                Enumeration<URL> resources = loader.getResources(path);
+                String name = service.getName();
+                Enumeration<URL> resources = loader.getResources("META-INF/services/" + name);
                 for (URL resource : Collections.list(resources)) {
                     try {
                         names.addAll(getServiceClassNames(resource));
                     } catch (IOException e) {
-                        handler.handleLoadError(service.getName(), e);
+                        handler.handleLoadError(name, e);
                     }
                 }
             } catch (IOException ignore) {