Apache Nutch is an extensible and scalable web crawler
protocols are now instantiated and configured only once
Sami Siren65b44ad9ccc7
diff --git a/src/java/org/apache/nutch/protocol/ProtocolFactory.java b/src/java/org/apache/nutch/protocol/ProtocolFactory.javaindex 1a3662681..cc1678ba8 100644--- a/src/java/org/apache/nutch/protocol/ProtocolFactory.java+++ b/src/java/org/apache/nutch/protocol/ProtocolFactory.java@@ -47,19 +47,27 @@ public class ProtocolFactory {}/** Returns the appropriate {@link Protocol} implementation for a url. */- public Protocol getProtocol(String urlString)- throws ProtocolNotFound {+ public Protocol getProtocol(String urlString) throws ProtocolNotFound {try {URL url = new URL(urlString);String protocolName = url.getProtocol();if (protocolName == null)throw new ProtocolNotFound(urlString);- Extension extension = getExtension(protocolName);- if (extension == null)- throw new ProtocolNotFound(protocolName);- Protocol protocol = (Protocol) extension.getExtensionInstance();- protocol.setConf(this.conf);- return protocol;++ if (conf.getObject(protocolName) != null) {+ return (Protocol) conf.getObject(protocolName);+ } else {+ Extension extension = findExtension(protocolName);+ if (extension == null) {+ throw new ProtocolNotFound(protocolName);+ }++ Protocol protocol = (Protocol) extension.getExtensionInstance();++ conf.setObject(protocolName, protocol);++ return protocol;+ }} catch (MalformedURLException e) {throw new ProtocolNotFound(urlString, e.toString());@@ -68,19 +76,6 @@ public class ProtocolFactory {}}- private Extension getExtension(String name)- throws PluginRuntimeException {-- if (this.conf.getObject(name) != null)- return (Extension)this.conf.getObject(name);-- Extension extension = findExtension(name);-- if (extension != null) this.conf.setObject(name, extension);-- return extension;- }-private Extension findExtension(String name)throws PluginRuntimeException {