org.gcube.common.core.state
Class GCUBEStatefulResource<RESOURCEID>

java.lang.Object
  extended by org.gcube.common.core.utils.handlers.GCUBEServiceClientImpl
      extended by org.gcube.common.core.state.GCUBEStatefulResource<RESOURCEID>
Type Parameters:
RESOURCEID - the type of the resource identifier.
All Implemented Interfaces:
GCUBEServiceClient, org.globus.wsrf.Resource
Direct Known Subclasses:
GCUBELocalResource, GCUBEWSResource

public abstract class GCUBEStatefulResource<RESOURCEID>
extends GCUBEServiceClientImpl
implements org.globus.wsrf.Resource

Partial implementation of stateful entities managed by gCube services. In particular, a GCUBEStatefulResource is an identifiable, initialisable, and removable entity.

Author:
Fabio Simeoni (University of Strathclyde)

Nested Class Summary
static class GCUBEStatefulResource.LOCK
          Enumeration of the lock types associated with the resource.
static class GCUBEStatefulResource.TaskContext
          Used internally to group contextual information about launched tasks.
 
Field Summary
protected  GCUBELog logger
          Instance logger.
protected static org.apache.axis.components.uuid.UUIDGen uuidGen
          String generator for local resource identifiers.
 
Constructor Summary
GCUBEStatefulResource()
           
 
Method Summary
 RESOURCEID getID()
          Returns the resource identifier.
 GCUBEReadWriteLock getLock()
          Returns a GCUBEReadWriteLock to grant synchronised access to the resource.
 Map<String,GCUBEStatefulResource.TaskContext> getScheduledTasks()
          Returns the tasks associated with the resource.
 GCUBEScope getScope()
          Returns the scope in which interactions ought to take place.
abstract  GCUBEServiceContext getServiceContext()
          Returns the context of the service associated with the resource.
protected abstract  void initialise(RESOURCEID id, Object... params)
          Used internally to initialise the resource with a given identifier and from given parameters.
<T> void
launchTask(String taskName, GCUBEHandler<T> task, Long delay, GCUBEScheduledHandler.Mode mode)
          Launches a scheduled task associated with the WS-Resource.
protected  void onRemove()
          Invoked by GCUBEResourceHome in the process of removing the resource.
 void setID(RESOURCEID id)
          Invoked by the GCUBEResourceHome of the resource to set its identifier.
 void setPersistenceDelegate(GCUBEPersistenceDelegate<RESOURCEID,? extends GCUBEStatefulResource<RESOURCEID>> delegate)
          Invoked by the GCUBEResourceHome of the resource to set the GCUBEPersistenceDelegate that is responsible for the serialisation and deserialisation of the resource to and from long-term storage.
 void stopTask(String taskName)
          Stops a scheduled task associated with the resource.
 void store()
          Serialises the resource to long term storage using its associated GCUBEPersistenceDelegate.
 
Methods inherited from class org.gcube.common.core.utils.handlers.GCUBEServiceClientImpl
getPortTypeMap, setPortTypeMap
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

uuidGen

protected static final org.apache.axis.components.uuid.UUIDGen uuidGen
String generator for local resource identifiers.


logger

protected final GCUBELog logger
Instance logger.

Constructor Detail

GCUBEStatefulResource

public GCUBEStatefulResource()
Method Detail

getID

public RESOURCEID getID()
Returns the resource identifier.

Returns:
the identifier.

setID

public void setID(RESOURCEID id)
Invoked by the GCUBEResourceHome of the resource to set its identifier.

Parameters:
id - the identifier.

initialise

protected abstract void initialise(RESOURCEID id,
                                   Object... params)
                            throws Exception
Used internally to initialise the resource with a given identifier and from given parameters.

Parameters:
id - the identifier, or null if a new one should be generated.
params - (optional) the initialisation parameters.
Throws:
Exception - if the resource could not be initialised.

getServiceContext

public abstract GCUBEServiceContext getServiceContext()
Returns the context of the service associated with the resource.

Returns:
the context.

setPersistenceDelegate

public void setPersistenceDelegate(GCUBEPersistenceDelegate<RESOURCEID,? extends GCUBEStatefulResource<RESOURCEID>> delegate)
Invoked by the GCUBEResourceHome of the resource to set the GCUBEPersistenceDelegate that is responsible for the serialisation and deserialisation of the resource to and from long-term storage.

Parameters:
delegate - the delegate.

store

public void store()
Serialises the resource to long term storage using its associated GCUBEPersistenceDelegate.

Throws:
org.globus.wsrf.ResourceException - if the resource could not be serialised.

onRemove

protected void onRemove()
                 throws org.globus.wsrf.ResourceException
Invoked by GCUBEResourceHome in the process of removing the resource.

Throws:
org.globus.wsrf.ResourceException - if the resource could not be removed.

getLock

public GCUBEReadWriteLock getLock()
Returns a GCUBEReadWriteLock to grant synchronised access to the resource.

Client threads are responsible for releasing the lock when they are finished with the resource. (typically from within a finally block).

Returns:
the lock.
See Also:
GCUBEReadWriteLock

launchTask

public <T> void launchTask(String taskName,
                           GCUBEHandler<T> task,
                           Long delay,
                           GCUBEScheduledHandler.Mode mode)
                throws Exception
Launches a scheduled task associated with the WS-Resource.

Parameters:
taskName - the unique name of the task.
task - the task.
delay - the time interval between two runs of the task, in seconds.
mode - the eager or lazy scheduling mode of the task.
Throws:
Exception - if the task could not be launched.

getScheduledTasks

public Map<String,GCUBEStatefulResource.TaskContext> getScheduledTasks()
Returns the tasks associated with the resource.

Returns:
the task, indexed by name.

stopTask

public void stopTask(String taskName)
              throws Exception
Stops a scheduled task associated with the resource.

Parameters:
taskName - the name of the task.
Throws:
Exception - if the task could not be stopped.

getScope

public GCUBEScope getScope()
Returns the scope in which interactions ought to take place. This is used by service handler to inject endpoints into the cache in a scope-sensitive manner.

Typically, this is delegated to a GCUBEScopeManager .

Specified by:
getScope in interface GCUBEServiceClient
Overrides:
getScope in class GCUBEServiceClientImpl
Returns:
the scope, or null if interactions should not to be scoped.


Copyright © 2012. All Rights Reserved.