Suggestions on plugin repository

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Suggestions on plugin repository

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
Reply | Threaded
Open this post in threaded view
|

Re: Suggestions on plugin repository

Stefan Groschupf-2
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
>

Reply | Threaded
Open this post in threaded view
|

Re: Suggestions on plugin repository

Thomas Jaeger
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