org.gcube.common.core.plugins
Class GCUBEPluginManager<PLUGINCONTEXT extends GCUBEPluginContext>

java.lang.Object
  extended by org.gcube.common.core.plugins.GCUBEPluginManager<PLUGINCONTEXT>

public abstract class GCUBEPluginManager<PLUGINCONTEXT extends GCUBEPluginContext>
extends Object

Partial implementation of plugin managers. A plugin manager handles the registration, un-registration, and persistence of plugins for and on behalf of a service.

Author:
Fabio Simeoni (University of Strathclyde)

Nested Class Summary
static class GCUBEPluginManager.PluginAlreadyRegisteredException
          Plugin already registered exception
static class GCUBEPluginManager.PluginConsumer<PLUGINCONTEXT extends GCUBEPluginContext>
          Base class for consumers of plugin management events.
 class GCUBEPluginManager.PluginEvent
          A model of plugin management events with a plugin context payload.
static class GCUBEPluginManager.PluginTopic
          Enumeration of plugin management topics.
 
Field Summary
protected  GCUBEServiceContext context
          The context of the associated service.
protected  GCUBELog logger
          Class logger.
protected static String PLUGIN_PROFILE_SUFFIX
          Suffix of plugin serialisations
protected  Map<String,PLUGINCONTEXT> plugins
          The list of registered plugins.
static String PLUGINS_DIRECTORY_NAME
          Plugin directory name
protected  GCUBEProducer<GCUBEPluginManager.PluginTopic,PLUGINCONTEXT> producer
          The inner producer of plugin management event.
 
Constructor Summary
GCUBEPluginManager()
           
 
Method Summary
 void deregisterPlugin(String name)
          DeRegister a plugin from the manager.
protected abstract  Class<PLUGINCONTEXT> getMainClass()
          Returns the type of GCUBEPluginContext expected by the associated service.
 Map<String,PLUGINCONTEXT> getPlugins()
          Returns the contexts of all the plugins that are currently registered with the manager.
protected abstract  GCUBEPortTypeContext[] getPortTypeContexts()
          Returns the contexts of the port-types of the associated service, so as to configure type mappings for them if any are provided by plugins via the associated GCUBEPluginContext).
 void initialise(GCUBEServiceContext context, GCUBEPluginManagerProfile managerProfile)
          Initialises the manager with the context of the associated service.
 void registerPlugin(GCUBEService plugin, boolean... persisted)
          Register a plugin with the manager.
 void setLogger(GCUBELog logger)
          Sets the instance logger.
 void subscribe(GCUBEPluginManager.PluginConsumer<PLUGINCONTEXT> c, GCUBEPluginManager.PluginTopic... topics)
          Subscribes a consumer to one or more registration events.
 void unsubscribe(GCUBEPluginManager.PluginConsumer<PLUGINCONTEXT> c, GCUBEPluginManager.PluginTopic... topics)
          Unsubscribes a consumer from one or more registration events.
 PLUGINCONTEXT validateMainClass(Class<?> contextClass)
          Validates and instantiate the main class of the plugin.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

logger

protected GCUBELog logger
Class logger.


PLUGINS_DIRECTORY_NAME

public static final String PLUGINS_DIRECTORY_NAME
Plugin directory name

See Also:
Constant Field Values

context

protected GCUBEServiceContext context
The context of the associated service.


plugins

protected Map<String,PLUGINCONTEXT extends GCUBEPluginContext> plugins
The list of registered plugins.


PLUGIN_PROFILE_SUFFIX

protected static final String PLUGIN_PROFILE_SUFFIX
Suffix of plugin serialisations

See Also:
Constant Field Values

producer

protected GCUBEProducer<GCUBEPluginManager.PluginTopic,PLUGINCONTEXT extends GCUBEPluginContext> producer
The inner producer of plugin management event.

Constructor Detail

GCUBEPluginManager

public GCUBEPluginManager()
Method Detail

setLogger

public void setLogger(GCUBELog logger)
Sets the instance logger.

Parameters:
logger - the logger.

initialise

public void initialise(GCUBEServiceContext context,
                       GCUBEPluginManagerProfile managerProfile)
                throws Exception
Initialises the manager with the context of the associated service.

Parameters:
context - the context.
managerProfile - the profile of the plugin manager.
Throws:
Exception - if the manager could not be initialised.

getMainClass

protected abstract Class<PLUGINCONTEXT> getMainClass()
Returns the type of GCUBEPluginContext expected by the associated service.

Returns:
the type.

validateMainClass

public PLUGINCONTEXT validateMainClass(Class<?> contextClass)
                                                           throws Exception
Validates and instantiate the main class of the plugin.

By default, the class is valid if it is compatible with GCUBEPluginContext and can be reflectively instantiated. Subclasses may extend the default implementation to guarantee that further constraints are met (e.g. that it implements required interfaces).

Returns:
an instance of the main classtrue if the main class is valid, false otherwise.
Throws:
Exception - if the class is not valid.

getPlugins

public Map<String,PLUGINCONTEXT> getPlugins()
Returns the contexts of all the plugins that are currently registered with the manager.

Returns:
the plugin contexts, indexed by name.

registerPlugin

public void registerPlugin(GCUBEService plugin,
                           boolean... persisted)
                    throws GCUBEPluginManager.PluginAlreadyRegisteredException,
                           Exception
Register a plugin with the manager.

Parameters:
plugin - the GCUBEService resource that models the plugin.
persisted - (optional) true if the plugin ought to be persisted (default), false otherwise.
Throws:
GCUBEPluginManager.PluginAlreadyRegisteredException - if the plugin is already registered
Exception - if the plugin could not be registered.

deregisterPlugin

public void deregisterPlugin(String name)
                      throws Exception
DeRegister a plugin from the manager.

Parameters:
name - the name of the plugin.
Throws:
Exception - if the plugin did not exist or could not be deregistered.

getPortTypeContexts

protected abstract GCUBEPortTypeContext[] getPortTypeContexts()
Returns the contexts of the port-types of the associated service, so as to configure type mappings for them if any are provided by plugins via the associated GCUBEPluginContext).

Returns:
the contexts.

subscribe

public void subscribe(GCUBEPluginManager.PluginConsumer<PLUGINCONTEXT> c,
                      GCUBEPluginManager.PluginTopic... topics)
Subscribes a consumer to one or more registration events.

Parameters:
c - the consumer.
topics - (optional) topics the topics, all if omitted.

unsubscribe

public void unsubscribe(GCUBEPluginManager.PluginConsumer<PLUGINCONTEXT> c,
                        GCUBEPluginManager.PluginTopic... topics)
Unsubscribes a consumer from one or more registration events.

Parameters:
c - the consumer.
topics - (optional) topics the topics, all if omitted.


Copyright © 2013. All Rights Reserved.