You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nutch.apache.org by si...@apache.org on 2006/06/15 22:53:15 UTC

svn commit: r414681 - /lucene/nutch/trunk/src/java/org/apache/nutch/protocol/ProtocolFactory.java

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 {@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());
     } 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)



Re: [Nutch-cvs] svn commit: r414681 - /lucene/nutch/trunk/src/java/org/apache/nutch/protocol/ProtocolFactory.java

Posted by Sami Siren <ss...@gmail.com>.
>> +
>> +      if (conf.getObject(protocolName) != null) {
>> +        return (Protocol) conf.getObject(protocolName);
>> +      } else {
>> +        Extension extension = findExtension(protocolName);
>> +        if (extension == null) {
>> +          throw new ProtocolNotFound(protocolName);
>> +        }
>>   
>
>
> I'm somewhat worried about the possible clash in the conf name-space 
> -  usually, when we store Object's in Configuration instance, we use 
> their full class name, or at least a long and most probably unique 
> string. In this case, we use just "http", "https", "ftp", "file" and 
> so on ... Would it make sense if in this special case we used the 
> X_POINT + protocolName as the unique string?
>
> Perhaps I'm worrying too much ... ;)
>
I changed the code as you proposed. In the long run I would like to see 
this kind of caching stuff refactored to either Configuration
or to the plugin system or perhaps if we start using some kind of 
component container then there.

--
 Sami Siren

Re: [Nutch-cvs] svn commit: r414681 - /lucene/nutch/trunk/src/java/org/apache/nutch/protocol/ProtocolFactory.java

Posted by Jérôme Charron <je...@gmail.com>.
> I'm somewhat worried about the possible clash in the conf name-space -
> usually, when we store Object's in Configuration instance, we use their
> full class name, or at least a long and most probably unique string. In
> this case, we use just "http", "https", "ftp", "file" and so on ...
> Would it make sense if in this special case we used the X_POINT +
> protocolName as the unique string?

+1
(why not using directly the extension id ?)


-- 
http://motrech.free.fr/
http://www.frutch.org/

Re: [Nutch-cvs] svn commit: r414681 - /lucene/nutch/trunk/src/java/org/apache/nutch/protocol/ProtocolFactory.java

Posted by Andrzej Bialecki <ab...@getopt.org>.
siren@apache.org wrote:
> 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
>
>   
[...]
> +
> +      if (conf.getObject(protocolName) != null) {
> +        return (Protocol) conf.getObject(protocolName);
> +      } else {
> +        Extension extension = findExtension(protocolName);
> +        if (extension == null) {
> +          throw new ProtocolNotFound(protocolName);
> +        }
>   

I'm somewhat worried about the possible clash in the conf name-space -  
usually, when we store Object's in Configuration instance, we use their 
full class name, or at least a long and most probably unique string. In 
this case, we use just "http", "https", "ftp", "file" and so on ... 
Would it make sense if in this special case we used the X_POINT + 
protocolName as the unique string?

Perhaps I'm worrying too much ... ;)

-- 
Best regards,
Andrzej Bialecki     <><
 ___. ___ ___ ___ _ _   __________________________________
[__ || __|__/|__||\/|  Information Retrieval, Semantic Web
___|||__||  \|  ||  |  Embedded Unix, System Integration
http://www.sigram.com  Contact: info at sigram dot com