ti.chimera
Class Plugin.ServiceFactory

java.lang.Object
  extended byti.chimera.ServiceFactoryImpl
      extended byti.chimera.Plugin.ServiceFactory
Enclosing class:
Plugin

public abstract class Plugin.ServiceFactory
extends ti.chimera.ServiceFactoryImpl

Because the garbage collection of a service instance (among other things) is used to determine if a Plugin should be stopped, the Registry cannot hold a reference to the service itself. Instead the service is registered (Plugin#addServiceFactory) via a ServiceFactory which is used by the Registry to create an instance of the Service on demand. The service- factory tracks (via a weak-reference) the lifecycle of the service instance, and uses a Resource to prevent the plugin from being inactive as long as the service instance is in use.

Conceptually this class is an inner-class of Plugin, but in order to keep the file sizes managed, all of it's functionality is actually delegated to ServiceFactoryImpl. This is all subject to change, and once the deprecated methods are removed from Plugin, it is possible that the implementation gets moved into this class and ServiceFactoryImpl goes away.


Constructor Summary
Plugin.ServiceFactory()
           
 
Method Summary
abstract  Service createService()
          Create the service this object is a factory for.
 java.lang.String getName()
          Get the name of the service this is a factory for.
 Service getService()
          Get the service that this factory creates.
 java.lang.String toString()
          For debug...
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Plugin.ServiceFactory

public Plugin.ServiceFactory()
Method Detail

getName

public java.lang.String getName()
Get the name of the service this is a factory for.

Returns:
the service name

getService

public Service getService()
Get the service that this factory creates. This may return an existing service instance, or may create a new one. It will ensure that the plugin is active as long as someone holds a reference to the service instance.

Returns:
the Service object

toString

public java.lang.String toString()
For debug...


createService

public abstract Service createService()
Create the service this object is a factory for. This should create a new instance of the service everytime that it gets called, because nothing other than the client of the service should hold a reference to the service.

Returns:
a newly instantiated Service object.