org.gcube.common.core.persistence
Class GCUBEPersistenceDelegate<RESOURCEID,RESOURCE extends GCUBEStatefulResource<RESOURCEID>>

java.lang.Object
  extended by org.gcube.common.core.persistence.GCUBEPersistenceDelegate<RESOURCEID,RESOURCE>
Type Parameters:
RESOURCE - the resource type.
RESOURCEID - the type of the resource identifier.
Direct Known Subclasses:
GCUBEFilePersistenceDelegate, GCUBENoPersistenceDelegate

public abstract class GCUBEPersistenceDelegate<RESOURCEID,RESOURCE extends GCUBEStatefulResource<RESOURCEID>>
extends Object

A partial implementation of persistence delegates for GCUBStatefulResources.

A persistence delegate is responsible for the deserialisation and serialisation of resources of a given type from and to some form of long-term storage, as well as for the removal of resource serialisations. It is intended to work in strict collaboration with the associated GCUBEStatefulResources and their GCUBEResourceHome, and clients should not interface it directly. In particular:

-) the initialisation of the delegate is triggered by resource homes as part of their own initialisation; -) the deserialisation of resource serialisations is triggered by resource homes at the point of resource access, transparently to their clients;
-) the removal of resource serialisations is triggered by resource homes, in response to explicit requests from their clients (cf. GCUBEResourceHome.remove(Object));
-) the serialisation of resources is triggered by resources themselves, in response to explicit requests from their clients (cf. GCUBEStatefulResource.store());

Author:
Fabio Simeoni (University of Strathclyde)

Field Summary
protected  GCUBELog logger
          Instance logger.
 
Constructor Summary
GCUBEPersistenceDelegate()
           
 
Method Summary
abstract  Collection<RESOURCEID> getResourceIdentifiers()
          Returns the identifiers of all the resources serialised by the delegate.
 void initialise(GCUBEResourceHome<? super RESOURCEID,RESOURCEID,RESOURCE> home)
          Initialises the delegate from the GCUBEResourceHome of the associated resources.
 void load(RESOURCE resource, boolean firstLoad)
          Deserialises the state of an uninitialised resource.
protected abstract  void onLoad(RESOURCE resource, boolean firstLoad)
          Invoked by load(GCUBEStatefulResource, boolean) to deserialise a resource.
protected abstract  void onRemove(RESOURCE resource)
          Invoked by remove(GCUBEStatefulResource) to remove the serialisation of a resource.
protected abstract  void onStore(RESOURCE resource)
          Invoked by store(GCUBEStatefulResource) to serialise a resource.
 void remove(RESOURCE resource)
          Removes the serialisation of a resource.
 void store(RESOURCE resource)
          Serialises the state of a resource.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

logger

protected final GCUBELog logger
Instance logger.

Constructor Detail

GCUBEPersistenceDelegate

public GCUBEPersistenceDelegate()
Method Detail

initialise

public void initialise(GCUBEResourceHome<? super RESOURCEID,RESOURCEID,RESOURCE> home)
                throws Exception
Initialises the delegate from the GCUBEResourceHome of the associated resources.

Parameters:
home - the home.
Throws:
Exception - if the delegate could not be initialised.

load

public void load(RESOURCE resource,
                 boolean firstLoad)
          throws Exception
Deserialises the state of an uninitialised resource.

Parameters:
firstLoad - true if the resource has not been previously loaded since the container last booted, false otherwise.
resource - the resource.
Throws:
Exception - if the resource could not be deserialised.

store

public void store(RESOURCE resource)
Serialises the state of a resource.

Parameters:
resource - the resource.

remove

public void remove(RESOURCE resource)
Removes the serialisation of a resource.

Parameters:
resource - the resource.

onLoad

protected abstract void onLoad(RESOURCE resource,
                               boolean firstLoad)
                        throws Exception
Invoked by load(GCUBEStatefulResource, boolean) to deserialise a resource. Implement in accordance with resource and serialisation semantics.

Parameters:
firstLoad - true if the resource has not been previously loaded since the container last booted, false otherwise.
Throws:
Exception - if the resource could not be deserialised.
See Also:
load(GCUBEStatefulResource, boolean)

onStore

protected abstract void onStore(RESOURCE resource)
                         throws Exception
Invoked by store(GCUBEStatefulResource) to serialise a resource. Implement in accordance with serialisation and resource semantics.

Throws:
Exception - if the resource could not be serialised.
See Also:
store(GCUBEStatefulResource)

onRemove

protected abstract void onRemove(RESOURCE resource)
                          throws Exception
Invoked by remove(GCUBEStatefulResource) to remove the serialisation of a resource. Implement in accordance with serialisation and resource semantics.

Throws:
Exception - if the resource serialisation could not be removed.
See Also:
remove(GCUBEStatefulResource)

getResourceIdentifiers

public abstract Collection<RESOURCEID> getResourceIdentifiers()
Returns the identifiers of all the resources serialised by the delegate.

Returns:
the identifiers.


Copyright © 2013. All Rights Reserved.