Skip to content

Distributed Peer-to-Peer Web Search Engine and Intranet Search Appliance

removed parser object pool, see also svn 4106

orbiter4fefa5313597
diff --git a/source/de/anomic/plasma/plasmaParser.java b/source/de/anomic/plasma/plasmaParser.java
index d6dadf939..6efd711dc 100644
--- a/source/de/anomic/plasma/plasmaParser.java
+++ b/source/de/anomic/plasma/plasmaParser.java
@@ -65,11 +65,6 @@ import java.util.List;
import java.util.Map;
import java.util.Properties;
import java.util.Set;
-
-import org.apache.commons.pool.KeyedPoolableObjectFactory;
-import org.apache.commons.pool.impl.GenericKeyedObjectPool;
-import org.apache.commons.pool.impl.GenericObjectPool;
-
import de.anomic.htmlFilter.htmlFilterContentScraper;
import de.anomic.htmlFilter.htmlFilterImageEntry;
import de.anomic.htmlFilter.htmlFilterInputStream;
@@ -125,13 +120,6 @@ public final class plasmaParser {
if (bufferedIn != null) try{bufferedIn.close();}catch(Exception e){}
}
}
-
- /**
- * A pool of parsers.
- * @see plasmaParserPool
- * @see plasmaParserFactory
- */
- static plasmaParserPool theParserPool;
/**
* A list of media extensions that should <b>not</b> be handled by the plasmaParser
@@ -188,25 +176,6 @@ public final class plasmaParser {
initAudioExt(extString2extList(audio)); // audio formats
initVideoExt(extString2extList(video)); // video formats
initAppsExt(extString2extList(apps)); // application formats
-
-
- /* ===================================================
- * initializing the parser object pool
- * =================================================== */
- GenericKeyedObjectPool.Config config = new GenericKeyedObjectPool.Config();
-
- // The maximum number of active connections that can be allocated from pool at the same time,
- // 0 for no limit
- config.maxActive = 0;
-
- // The maximum number of idle connections connections in the pool
- // 0 = no limit.
- config.maxIdle = 5;
-
- config.whenExhaustedAction = GenericObjectPool.WHEN_EXHAUSTED_BLOCK;
- config.minEvictableIdleTimeMillis = 30000;
-
- plasmaParser.theParserPool = new plasmaParserPool(new plasmaParserFactory(),config);
/* ===================================================
* loading a list of available parsers
@@ -559,11 +528,6 @@ public final class plasmaParser {
currentConfig.enabledParserList.clear();
}
}
-
- // closing the parser object pool
- try {
- theParserPool.close();
- } catch (Exception e) {/* ignore this */}
}
public plasmaParserDocument parseSource(yacyURL location, String mimeType, String charset, byte[] sourceArray)
@@ -714,7 +678,7 @@ public final class plasmaParser {
} finally {
if (theParser != null) {
- try { plasmaParser.theParserPool.returnObject(mimeType, theParser); } catch (Exception e) { /* ignore this */}
+ theParser = null; // delete object
}
}
}
@@ -801,7 +765,7 @@ public final class plasmaParser {
}
// fetching a new parser object from pool
- Parser theParser = (Parser) theParserPool.borrowObject(parserClassName);
+ Parser theParser = makeParser(parserClassName);
// checking if the created parser really supports the given mimetype
Hashtable supportedMimeTypes = theParser.getSupportedMimeTypes();
@@ -809,7 +773,6 @@ public final class plasmaParser {
parserInfo.incUsageCounter();
return theParser;
}
- theParserPool.returnObject(parserClassName,theParser);
} catch (Exception e) {
System.err.println("ERROR: Unable to load the correct parser for type " + mimeType);
@@ -1070,94 +1033,25 @@ public final class plasmaParser {
return false;
}
-
-}
-final class plasmaParserFactory implements KeyedPoolableObjectFactory {
-
- public plasmaParserFactory() {
- super();
- }
-
- /**
- * @see org.apache.commons.pool.PoolableObjectFactory#makeObject()
- */
- public Object makeObject(Object key) throws Exception {
+ public static Parser makeParser(Object name) throws Exception {
- if (!(key instanceof String))
+ if (!(name instanceof String))
throw new IllegalArgumentException("The object key must be of type string.");
// loading class by name
- Class moduleClass = Class.forName((String)key);
+ Class moduleClass = Class.forName((String)name);
// instantiating class
Parser theParser = (Parser) moduleClass.newInstance();
// setting logger that should by used
- String parserShortName = ((String)key).substring("de.anomic.plasma.parser.".length(),((String)key).lastIndexOf("."));
+ String parserShortName = ((String)name).substring("de.anomic.plasma.parser.".length(),((String)name).lastIndexOf("."));
serverLog theLogger = new serverLog("PARSER." + parserShortName.toUpperCase());
theParser.setLogger(theLogger);
return theParser;
}
-
- /**
- * @see org.apache.commons.pool.PoolableObjectFactory#destroyObject(java.lang.Object)
- */
- public void destroyObject(Object key, Object obj) {
- /*
- if (obj instanceof Parser) {
- Parser theParser = (Parser) obj;
- }
- */
- }
-
- /**
- * @see org.apache.commons.pool.PoolableObjectFactory#validateObject(java.lang.Object)
- */
- public boolean validateObject(Object key, Object obj) {
- if (obj instanceof Parser) {
- //Parser theParser = (Parser) obj;
- return true;
- }
- return true;
- }
-
- /**
- * @param obj
- *
- */
- public void activateObject(Object key, Object obj) {
- //log.debug(" activateObject...");
- }
-
- /**
- * @param obj
- *
- */
- public void passivateObject(Object key, Object obj) {
- //log.debug(" passivateObject..." + obj);
- if (obj instanceof Parser) {
- Parser theParser = (Parser) obj;
- theParser.reset();
- }
- }
-
-}
-
-final class plasmaParserPool extends GenericKeyedObjectPool {
-
- public plasmaParserPool(plasmaParserFactory objFactory, GenericKeyedObjectPool.Config config) {
- super(objFactory, config);
- }
-
-
- public Object borrowObject(Object key) throws Exception {
- return super.borrowObject(key);
- }
-
- public void returnObject(Object key, Object borrowed) throws Exception {
- super.returnObject(key,borrowed);
- }
-}
+
+}
diff --git a/source/de/anomic/plasma/plasmaParserConfig.java b/source/de/anomic/plasma/plasmaParserConfig.java
index 4daf3c483..da96bb52b 100644
--- a/source/de/anomic/plasma/plasmaParserConfig.java
+++ b/source/de/anomic/plasma/plasmaParserConfig.java
@@ -163,7 +163,7 @@ public class plasmaParserConfig {
Parser theParser = null;
try {
// getting the parser
- theParser = (Parser) plasmaParser.theParserPool.borrowObject(((ParserInfo)plasmaParser.availableParserList.get(mimeType)).parserClassName);
+ theParser = plasmaParser.makeParser(((ParserInfo)plasmaParser.availableParserList.get(mimeType)).parserClassName);
// getting a list of mimeTypes that the parser supports
Hashtable parserSupportsMimeTypes = theParser.getSupportedMimeTypes();
@@ -182,7 +182,7 @@ public class plasmaParserConfig {
serverLog.logSevere("PARSER", "error in setEnabledParserList", e);
} finally {
if (theParser != null)
- try { plasmaParser.theParserPool.returnObject(mimeType,theParser); } catch (Exception e) {}
+ theParser = null; // destroy object
}
}
}
diff --git a/source/de/anomic/plasma/plasmaSnippetCache.java b/source/de/anomic/plasma/plasmaSnippetCache.java
index bed84ce1a..7b8628304 100644
--- a/source/de/anomic/plasma/plasmaSnippetCache.java
+++ b/source/de/anomic/plasma/plasmaSnippetCache.java
@@ -829,11 +829,12 @@ public class plasmaSnippetCache {
// try to download the resource using a crawler
plasmaHTCache.Entry entry = plasmaSwitchboard.getSwitchboard().crawlQueues.loadResourceFromWeb(url, (socketTimeout < 0) ? -1 : socketTimeout, true, forText);
+ if (entry == null) return null; // not found in web
// read resource body (if it is there)
byte[] resourceArray = entry.cacheArray();
- // in case that the reosurce was not in ram, read it from disk
+ // in case that the resource was not in ram, read it from disk
if (resourceArray == null) {
resource = plasmaHTCache.getResourceContentStream(url);
contentLength = plasmaHTCache.getResourceContentLength(url);