You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@nutch.apache.org by Thomas Jaeger <nu...@thjaeger.org> on 2006/01/14 12:01:44 UTC
Suggestions on plugin repository
Hi all,
some thoughts about the plugin package:
Currently the method Extension.getExtensionInstance returns a new
instance of an extension each time it is called. If an extension is a
singleton, each extension has to implement the singleton pattern.
My suggestion:
Add an instance cache to the Extension class. If an extension is marked
as a singleton, getExtensionInstance would always return the same instance.
Whether an extension is a singleton or not is determined by the
plugin.xml, for example:
<implementation id="org.apache.nutch.protocol.httpclient.Http"
class="org.apache.nutch.protocol.httpclient.Http"
singleton="true"
protocolName="https"/>
To be compatible with the current implementation, the singleton
attribute would not be required and the default value is false.
Main advantages I see:
- singleton code in extensions would disappear, the code is getting more
readable and smaller
-- static variable access would disappear (think of concurrency and
classloader issues)
- Instance control is handed over to the plugin "container"
- it's possible to have two instances of a singleton for testing purposes
What do you think?
Thomas
Re: Suggestions on plugin repository
Posted by Thomas Jaeger <nu...@thjaeger.org>.
Hi Stefan,
Stefan Groschupf wrote:
> to realize singletons you have to use a plugin class implementation
> that hosts all resources you want to share within your extension objects.
> Extension objects are not singletons since they are many times used in
> a multithreaded environment. So just move all our fields you would have
> in a singleton to your custom plugin class implementation and verify
> that you are able to handle multithreaded resources access and you are
> done.
Ok, i'm currently learning by reading the source, so sorry for asking
dump questions ;)
I first looked into httpclient.Http and there is a singleton pattern for
HttpClient in it. So I thought it is a good idea to have extensions as
singletons and i didn't looked at the Plugin class (which is already
cached)...
But my next question now is: Why isn't there any class inheriting Plugin
(as far as i can see)? And why isn't there a custom Plugin for
httpclient.Http, which hosts access to HttpClient and
MultiThreadedHttpConnectionManager?
Thomas
Re: Suggestions on plugin repository
Posted by Stefan Groschupf <sg...@media-style.com>.
Hi Thomas,
to realize singletons you have to use a plugin class implementation
that hosts all resources you want to share within your extension
objects.
Extension objects are not singletons since they are many times used
in a multithreaded environment. So just move all our fields you would
have in a singleton to your custom plugin class implementation and
verify that you are able to handle multithreaded resources access and
you are done.
HTH
Stefan
Am 14.01.2006 um 12:01 schrieb Thomas Jaeger:
> Hi all,
>
> some thoughts about the plugin package:
>
> Currently the method Extension.getExtensionInstance returns a new
> instance of an extension each time it is called. If an extension is a
> singleton, each extension has to implement the singleton pattern.
>
> My suggestion:
> Add an instance cache to the Extension class. If an extension is
> marked
> as a singleton, getExtensionInstance would always return the same
> instance.
> Whether an extension is a singleton or not is determined by the
> plugin.xml, for example:
> <implementation id="org.apache.nutch.protocol.httpclient.Http"
>
> class="org.apache.nutch.protocol.httpclient.Http"
> singleton="true"
> protocolName="https"/>
> To be compatible with the current implementation, the singleton
> attribute would not be required and the default value is false.
>
> Main advantages I see:
> - singleton code in extensions would disappear, the code is getting
> more
> readable and smaller
> -- static variable access would disappear (think of concurrency and
> classloader issues)
> - Instance control is handed over to the plugin "container"
> - it's possible to have two instances of a singleton for testing
> purposes
>
>
> What do you think?
> Thomas
>