org.gcube.common.core.utils.handlers
Class GCUBEHandler<HANDLED>

java.lang.Object
  extended by org.gcube.common.core.utils.handlers.GCUBEHandler<HANDLED>
Type Parameters:
HANDLED - the type of the handled object.
All Implemented Interfaces:
GCUBEIHandler<HANDLED>
Direct Known Subclasses:
GCUBEComplexHandler, GCUBEHandlerConnector, GCUBEScheduledHandler, GCUBEServiceHandler, GCUBETestProbe, LocalMonitor

public abstract class GCUBEHandler<HANDLED>
extends Object
implements GCUBEIHandler<HANDLED>

A partial implementation of GCUBEIHandler.

In particular, a GCUBEHandler:

Author:
Fabio Simeoni (University of Strathclyde)

Field Summary
protected  HANDLED handled
          The handled object.
protected  GCUBELog logger
          Object logger.
protected  GCUBEProducer<Topic,Object> producer
          Internal event producer.
 
Constructor Summary
GCUBEHandler()
          Creates an instance.
GCUBEHandler(HANDLED handled)
          Creates an instance with a given handled object.
 
Method Summary
 void clearBlackboard()
          Clears the blackboard.
 Map<String,Object> getBlackboard()
          Returns the blackboard.
 HANDLED getHandled()
          Returns the handled object.
 String getId()
          Returns the identifier of the handler.
 GCUBELog getLogger()
          Returns the logger.
 String getName()
          Returns the name of the handler, by default, the name of its class.
 GCUBEScopeManager getScopeManager()
          Returns the scope manager of the handler.
 GCUBESecurityManager getSecurityManager()
          Returns the security manager of the handler.
 State getState()
          See Lifetime.getState().
protected
<TOPIC extends Topic>
void
notify(TOPIC topic, Event<TOPIC,?> e)
          Notifies all subscribed monitors of an Event about an associated Topic.
abstract  void run()
          Executes the task implemented by the handler.
 void setBlackboard(Map<String,Object> state)
          Sets the blackboard.
 void setHandled(HANDLED handled)
          Sets the handled object.
 void setLogger(GCUBELog logger)
          Sets the logger.
 void setName(String name)
          Sets the name of the handler.
 void setScopeManager(GCUBEScopeManager manager)
          Sets a scope manager for the handler.
 void setSecurityManager(GCUBESecurityManager manager)
          Sets a security manager for the handler.
 void setState(State state)
          Sets the state of the handler.
 void subscribe(Monitor monitor, Topic... topics)
          Subscribes a Monitor to one or more Topics.
 void undo()
          Reverts the actions of the handler.
 void unsubscribe(Monitor monitor, Topic... topics)
          Unsubscribes a Monitor from one or more Topics.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

logger

protected GCUBELog logger
Object logger.


handled

protected HANDLED handled
The handled object.


producer

protected GCUBEProducer<Topic,Object> producer
Internal event producer.

Constructor Detail

GCUBEHandler

public GCUBEHandler()
Creates an instance.


GCUBEHandler

public GCUBEHandler(HANDLED handled)
Creates an instance with a given handled object.

Parameters:
handled - the handled object.
Method Detail

setLogger

public void setLogger(GCUBELog logger)
Sets the logger.

Specified by:
setLogger in interface GCUBEIHandler<HANDLED>
Parameters:
logger - the logger.

getLogger

public GCUBELog getLogger()
Returns the logger.

Specified by:
getLogger in interface GCUBEIHandler<HANDLED>
Returns:
the logger.

run

public abstract void run()
                  throws Exception
Executes the task implemented by the handler.

Specified by:
run in interface GCUBEIHandler<HANDLED>
Throws:
Exception - if the execution of the task does not complete normally.

getHandled

public HANDLED getHandled()
Returns the handled object.

Specified by:
getHandled in interface GCUBEIHandler<HANDLED>
Returns:
the handled object.

setHandled

public void setHandled(HANDLED handled)
Sets the handled object.

Specified by:
setHandled in interface GCUBEIHandler<HANDLED>
Parameters:
handled - the handled object.

getBlackboard

public Map<String,Object> getBlackboard()
Returns the blackboard.

Specified by:
getBlackboard in interface GCUBEIHandler<HANDLED>
Returns:
the blackboard.

setBlackboard

public void setBlackboard(Map<String,Object> state)
Sets the blackboard.

Specified by:
setBlackboard in interface GCUBEIHandler<HANDLED>
Parameters:
state - the blackboard.

clearBlackboard

public void clearBlackboard()
Clears the blackboard.

Specified by:
clearBlackboard in interface GCUBEIHandler<HANDLED>

getId

public String getId()
Returns the identifier of the handler.

Specified by:
getId in interface GCUBEIHandler<HANDLED>
Returns:
the identifier.

getName

public String getName()
Returns the name of the handler, by default, the name of its class.

Specified by:
getName in interface GCUBEIHandler<HANDLED>
Returns:
the name.

setName

public void setName(String name)
Sets the name of the handler.

Specified by:
setName in interface GCUBEIHandler<HANDLED>
Parameters:
name - the name.

undo

public void undo()
Reverts the actions of the handler. By default, it simply debug-logs the invocation. If required, override as per handler semantics. For robustness, do not assume the invocation occurs after the execution of the handler.

Specified by:
undo in interface GCUBEIHandler<HANDLED>

subscribe

public void subscribe(Monitor monitor,
                      Topic... topics)
Subscribes a Monitor to one or more Topics.

Specified by:
subscribe in interface GCUBEIHandler<HANDLED>
Parameters:
monitor - the monitor.
topics - (optional) the topics. If omitted, the monitor is subscribed to Topic.LifetimeTopic.

unsubscribe

public void unsubscribe(Monitor monitor,
                        Topic... topics)
Unsubscribes a Monitor from one or more Topics.

Specified by:
unsubscribe in interface GCUBEIHandler<HANDLED>
Parameters:
monitor - the monitor.
topics - (optional) the topics. If omitted, the monitor is subscribed to Topic.LifetimeTopic.

notify

protected <TOPIC extends Topic> void notify(TOPIC topic,
                                            Event<TOPIC,?> e)
Notifies all subscribed monitors of an Event about an associated Topic.

Parameters:
(optional) - the topic.
e - the event.

getState

public State getState()
See Lifetime.getState().


setState

public void setState(State state)
              throws IllegalArgumentException,
                     IllegalStateException
Sets the state of the handler.

Parameters:
state - the state.
Throws:
IllegalArgumentException - if the state is null
IllegalStateException - if the handler cannot transition to the state from its current state.

setSecurityManager

public void setSecurityManager(GCUBESecurityManager manager)
Sets a security manager for the handler.

Specified by:
setSecurityManager in interface GCUBEIHandler<HANDLED>
Parameters:
manager - the manager.

setScopeManager

public void setScopeManager(GCUBEScopeManager manager)
Sets a scope manager for the handler.

Specified by:
setScopeManager in interface GCUBEIHandler<HANDLED>
Parameters:
manager - the manager.

getSecurityManager

public GCUBESecurityManager getSecurityManager()
Returns the security manager of the handler.

Specified by:
getSecurityManager in interface GCUBEIHandler<HANDLED>
Returns:
the manager.

getScopeManager

public GCUBEScopeManager getScopeManager()
Returns the scope manager of the handler.

Specified by:
getScopeManager in interface GCUBEIHandler<HANDLED>
Returns:
the manager.


Copyright © 2012. All Rights Reserved.