RESOURCE - the type of GCUBEStatefulResource.RESOURCEID - the type of the GCUBEStatefulResource identifier.LEGACYID - the legacy identifier type. Used to retrofit the design to Globus technology while insulating clients from it.public abstract class GCUBEResourceHome<LEGACYID,RESOURCEID extends LEGACYID,RESOURCE extends GCUBEStatefulResource<RESOURCEID>> extends Object implements org.globus.wsrf.jndi.Initializable
GCUBEStatefulResources.
It creates, retrieves, and removes resources parametrically with respect to their type. Resource management can occur in either one of four different modes:
TRANSIENT: resources are maintained exclusively in memory (default mode);
HARDPERSISTENT: resources can be serialised to storage by configuration of a
GCUBEPersistenceDelegate. At the reboot of the container
all resource serialisations are transparently restored to memory.
CACHEDPERSISTENT: resources can be serialised to storage by configuration of a
GCUBEPersistenceDelegate and remain in memory for a time
that is proportional to the frequency of usage and and the amount of available memory.
Resources that are not found in memory but exist on storage are transparently restored to memory.
SOFTPERSISTENT: resources can be serialised to storage
by configuration of a GCUBEPersistenceDelegate and remain in memory for a time
that is proportional to the amount of available memory.
Resources that are not found in memory but exist on storage are transparently restored to memory.
The four modes above reflect different trade-offs between the efficiency of resource access (which decreases
from the first to the fourth) and the efficiency of in-memory storage (which increases from the first to
the fourth). In all cases, the mode of operation is derived from configuration (cf. onInitialisation()).
| Modifier and Type | Class and Description |
|---|---|
protected static class |
GCUBEResourceHome.Mode
Enumerates management modes.
|
| Modifier and Type | Field and Description |
|---|---|
protected org.globus.wsrf.utils.cache.LRUCache |
cache
Memory cache for persistent resources.
|
protected org.gcube.common.core.state.GCUBEResourceHome.LockManager |
lockManager
A manager of locks on resources identifiers.
|
protected GCUBELog |
logger
Instance logger.
|
protected GCUBEResourceHome.Mode |
mode
The management mode.
|
protected GCUBEPersistenceDelegate<RESOURCEID,RESOURCE> |
persistenceDelegate
The class of the persistence delegate for the managed resources.
|
protected Class<RESOURCE> |
resourceClass
The class of the managed resources.
|
protected List<RESOURCEID> |
resourceLog
List of identifiers of resources created in the home's lifetime.
|
| Constructor and Description |
|---|
GCUBEResourceHome() |
| Modifier and Type | Method and Description |
|---|---|
protected void |
add(RESOURCE resource)
Adds a resource to the home.
|
RESOURCE |
create(Object... params)
Creates a resource from a set of initialisation parameters.
|
RESOURCE |
create(RESOURCEID id,
Object... params)
Returns a resource with a given identifier from a set of initialisation parameters,
creating it if it does not exist.
|
protected RESOURCE |
createInternal(RESOURCEID id,
Object... params)
Used internally to create a resource from an identifier and a set of initialisation parameters.
|
RESOURCE |
find(LEGACYID id)
Returns a resource from its identifier.
|
protected RESOURCE |
get(LEGACYID id)
Returns a resource from its identifier, deserialising it from storage if it is in a persistent
state.
|
Collection<? extends RESOURCEID> |
getIdentifiers()
Returns the identifiers of all resources ever created by the home.
|
String |
getResourceClass()
Returns the class of the resources managed by the home.
|
protected Collection<? extends RESOURCE> |
getResources()
Returns the resources that are held in memory at the point of invocation.
|
abstract GCUBEServiceContext |
getServiceContext()
Returns the associated
GCUBEServiceContext. |
void |
initialize()
Invoked by the container at startup, it subscribes a
GCUBEResourceHome.HomeConsumer to lifetime events
of the Running Instance. |
protected RESOURCE |
newInstance()
Used internally to obtain an uninitialised resource.
|
protected void |
onFailure()
Invoked when the Running Instance fails.
|
protected void |
onInitialisation()
Invoked during initialisation of the Running Instance to initialise the home.
|
protected void |
onLoad(RESOURCE resource,
boolean firstLoad)
Invoked after successfully loading a resource from storage.
|
protected void |
onReady()
Invoked when the Running Instance is ready to operate.
|
protected boolean |
onRemove(RESOURCE resource)
Invoked as a precondition to the removal of a resource.
|
protected void |
onReuse(RESOURCE resource)
Invoked when a resource is reused across two or more calls to
create(Object, Object...) . |
protected void |
onStateChange()
Invoked upon a change to the RI's stateful resources, if any.
|
protected void |
onUpdate()
Invoked when the Runnning Instance is updated.
|
protected void |
postInitialise(RESOURCE resource)
Invoked during the creation of a resource and after its initialisation.
|
protected void |
preInitialise(RESOURCE resource)
Invoked during the creation of a resource and before its initialisation.
|
void |
remove(LEGACYID id)
Removes a resource with a given identifier.
|
protected void |
remove(RESOURCE resource)
Removes a resource from the home.
|
protected RESOURCE |
reuse(RESOURCEID id,
Object... params)
Returns a resource with a given identifier.
|
void |
setCacheTimeout(long timeout)
Sets the timeout in milliseconds of the cache used by the home.
|
void |
setPersistenceDelegateClass(String clazz)
Sets the name of the class of the persistence delegate for the resources managed by the home.
|
void |
setResourceClass(String clazz)
Sets the name of the class of the resources managed by the home.
|
protected final GCUBELog logger
protected volatile Class<RESOURCE extends GCUBEStatefulResource<RESOURCEID>> resourceClass
protected volatile GCUBEPersistenceDelegate<RESOURCEID extends LEGACYID,RESOURCE extends GCUBEStatefulResource<RESOURCEID>> persistenceDelegate
protected volatile GCUBEResourceHome.Mode mode
protected volatile org.globus.wsrf.utils.cache.LRUCache cache
protected final org.gcube.common.core.state.GCUBEResourceHome.LockManager lockManager
protected final List<RESOURCEID extends LEGACYID> resourceLog
public final void initialize()
throws Exception
GCUBEResourceHome.HomeConsumer to lifetime events
of the Running Instance.initialize in interface org.globus.wsrf.jndi.InitializableException - if initialisation fails.public void setResourceClass(String clazz) throws ClassNotFoundException
clazz - the class name.ClassNotFoundException - if the class name could not be resolved.public String getResourceClass()
public void setPersistenceDelegateClass(String clazz) throws Exception
clazz - the class name.ClassNotFoundException - if the class name could not be resolved.Exceptionpublic void setCacheTimeout(long timeout)
timeout - the timeout.public abstract GCUBEServiceContext getServiceContext()
GCUBEServiceContext.protected void onInitialisation()
throws Exception
<resource name="[name]" type="[FQN of a subclass of GCUBEResourceHome]">
<resourceParams>
<parameter>
<name>factory</name>
<value>org.globus.wsrf.jndi.BeanFactory</value>
</parameter>
<parameter>
<name>resourceClass</name>
<value>[FQN of a concrete subclass of GCUBEStatefulResource]</value>
</parameter>
<parameter>
<name>persistenceDelegateClass</name>
<value>[FQN of a concrete subclass of GCUBEPersistenceDelegate]</value>
</parameter>
<parameter>
<name>cacheTimeout</name>
<value>[seconds]</value>
</parameter>
</resourceParams>
</resource>
where:
-) the name of the JNDI resource and its resourceClass parameter may be further
constrained by subclasses.
-) persistenceDelegateClass and cacheTimeout are optional and related.
If neither is present, the mode of operation is TRANSIENT.
If the first is present but the second is absent, then the mode of operation is SOFTPERSISTENT.
If both are present, then the mode of operation is
HARDPERSISTENT if the second has a value of 0 and CACHEDPERSISTENT
in all other cases.
Finally, the second cannot occur without the first.
Exception - if the callback did not complete successfully (causes service failure).protected void onReady()
throws Exception
Exception - if the callback did not complete successfully and the service ought to fail as a result.protected void onUpdate()
throws Exception
Exception - if the callback did not complete successfully and the service ought to fail as a result.protected void onStateChange()
throws Exception
Exception - if the callback did not complete successfully and the service ought to fail as a result.protected void onFailure()
throws Exception
Exception - if the callback did not complete successfully and the service ought to fail as a result.protected RESOURCE newInstance() throws org.globus.wsrf.ResourceException
org.globus.wsrf.ResourceException - if the resource could not be created.protected void add(RESOURCE resource)
resource - the resource.protected RESOURCE get(LEGACYID id) throws org.globus.wsrf.ResourceException, org.globus.wsrf.NoSuchResourceException
It is invoked by find(id) and remove(id)
after they have acquired a reentrant lock on the resource identifier.
id - the identifier.org.globus.wsrf.ResourceException - if the resource cannot be found.org.globus.wsrf.NoSuchResourceExceptionfind(Object),
remove(Object)protected void remove(RESOURCE resource) throws org.globus.wsrf.ResourceException
resource - the resource.org.globus.wsrf.ResourceExceptionprotected Collection<? extends RESOURCE> getResources()
public Collection<? extends RESOURCEID> getIdentifiers()
public RESOURCE create(Object... params) throws org.globus.wsrf.ResourceException
params - (optional) the initialisation parameters.org.globus.wsrf.ResourceException - if the resource could neither be reused or created.create(Object, Object...)public RESOURCE create(RESOURCEID id, Object... params) throws org.globus.wsrf.ResourceException
id - the identifier, or null.params - (optional) the initialisation parameters.org.globus.wsrf.ResourceException - if the resource could neither be reused or created.onReuse(GCUBEStatefulResource),
reuse(Object, Object...)protected RESOURCE reuse(RESOURCEID id, Object... params) throws org.globus.wsrf.ResourceException
id - the identifier.params - (optional) the initialisation parameters.org.globus.wsrf.ResourceException - if the resource could not be reused.protected RESOURCE createInternal(RESOURCEID id, Object... params) throws org.globus.wsrf.ResourceException
id - the identifier, or null.params - (optional) the initialisation parameters.org.globus.wsrf.ResourceException - if the resource could not be created.public RESOURCE find(LEGACYID id) throws org.globus.wsrf.ResourceException, org.globus.wsrf.NoSuchResourceException
id - the identifier.org.globus.wsrf.ResourceException - if no resource with the given identifier can be found.org.globus.wsrf.NoSuchResourceExceptionpublic void remove(LEGACYID id) throws org.globus.wsrf.ResourceException
id - the identifier.org.globus.wsrf.NoSuchResourceException - if no resource exists with the given identifier.org.globus.wsrf.InvalidResourceKeyException - if the identifier is invalid.org.globus.wsrf.ResourceException - if the resource exists but could not be removed.protected void preInitialise(RESOURCE resource) throws org.globus.wsrf.ResourceException
If overriding this method, please note that the resource may not have been assigned an identifier yet.
resource - the resource.org.globus.wsrf.ResourceException - if the resource could not be pre-initialised.protected void postInitialise(RESOURCE resource) throws org.globus.wsrf.ResourceException
resource - the resource.org.globus.wsrf.ResourceException - if the resource could not be post-initialised.protected void onReuse(RESOURCE resource) throws org.globus.wsrf.ResourceException
create(Object, Object...) .resource - the resource.org.globus.wsrf.ResourceException - if the resource could not be reused.protected void onLoad(RESOURCE resource, boolean firstLoad) throws org.globus.wsrf.ResourceException
resource - the resource.firstLoad - true if this is the first time the resource is loaded since the last container reboot.org.globus.wsrf.ResourceException - if the resource could not loaded.protected boolean onRemove(RESOURCE resource) throws org.globus.wsrf.ResourceException
resource - the resource.org.globus.wsrf.ResourceException - if the precondition could not be verified.Copyright © 2015. All Rights Reserved.