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 via email to