Author: siren
Date: Thu Jun 15 13:53:14 2006
New Revision: 414681
URL: http://svn.apache.org/viewvc?rev=414681&view=rev
Log:
protocols are now instantiated and configured only once
Modified:
lucene/nutch/trunk/src/java/org/apache/nutch/protocol/ProtocolFactory.java
Modified:
lucene/nutch/trunk/src/java/org/apache/nutch/protocol/ProtocolFactory.java
URL:
http://svn.apache.org/viewvc/lucene/nutch/trunk/src/java/org/apache/nutch/protocol/ProtocolFactory.java?rev=414681&r1=414680&r2=414681&view=diff
==============================================================================
--- lucene/nutch/trunk/src/java/org/apache/nutch/protocol/ProtocolFactory.java
(original)
+++ lucene/nutch/trunk/src/java/org/apache/nutch/protocol/ProtocolFactory.java
Thu Jun 15 13:53:14 2006
@@ -47,38 +47,33 @@
}
/** Returns the appropriate [EMAIL PROTECTED] 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());
} catch (PluginRuntimeException e) {
throw new ProtocolNotFound(urlString, e.toString());
}
- }
-
- 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)