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

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

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

A partial specialisation of GCUBEPersistenceDelegate suitable for file storage.

Author:
Fabio Simeoni (University of Strathclyde)

Field Summary
 
Fields inherited from class org.gcube.common.core.persistence.GCUBEPersistenceDelegate
logger
 
Constructor Summary
GCUBEFilePersistenceDelegate()
           
 
Method Summary
protected abstract  File getFileFromResource(RESOURCE resource)
          Returns the file serialisation of a resource.
protected abstract  RESOURCEID getIDFromFileName(String s)
          Returns a resource identifier from a string.
 Collection<RESOURCEID> getResourceIdentifiers()
          Returns the identifiers of all the resources serialised by the delegate.
protected  File getStorageRoot()
          Returns the root directory for file storage.
protected abstract  String getSuffix()
          Returns the suffix for resource file serialisations.
 void initialise(GCUBEResourceHome<? super RESOURCEID,RESOURCEID,RESOURCE> home)
          Initialises the delegate from the GCUBEResourceHome of the associated resources.
protected  void onLoad(RESOURCE resource, boolean firstLoad)
          Invoked by GCUBEPersistenceDelegate.load(GCUBEStatefulResource, boolean) to deserialise a resource.
protected  void onLoad(RESOURCE resource, ObjectInputStream stream)
          Deserialises the state of resource from a ObjectInputStream.
protected  void onRemove(RESOURCE resource)
          Invoked by GCUBEPersistenceDelegate.remove(GCUBEStatefulResource) to remove the serialisation of a resource.
protected  void onStore(RESOURCE resource)
          Invoked by GCUBEPersistenceDelegate.store(GCUBEStatefulResource) to serialise a resource.
protected  void onStore(RESOURCE resource, ObjectOutputStream stream)
          Serialises the state of a resource into a ObjectOutputStream.
 
Methods inherited from class org.gcube.common.core.persistence.GCUBEPersistenceDelegate
load, remove, store
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

GCUBEFilePersistenceDelegate

public GCUBEFilePersistenceDelegate()
Method Detail

getStorageRoot

protected File getStorageRoot()
Returns the root directory for file storage.

Returns:
the root.

initialise

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

Overrides:
initialise in class GCUBEPersistenceDelegate<RESOURCEID,RESOURCE extends GCUBEStatefulResource<RESOURCEID>>
Parameters:
home - the home.
Throws:
Exception - if the delegate could not be initialised.

onLoad

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

Specified by:
onLoad in class GCUBEPersistenceDelegate<RESOURCEID,RESOURCE extends GCUBEStatefulResource<RESOURCEID>>
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:
GCUBEPersistenceDelegate.load(GCUBEStatefulResource, boolean)

onStore

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

Specified by:
onStore in class GCUBEPersistenceDelegate<RESOURCEID,RESOURCE extends GCUBEStatefulResource<RESOURCEID>>
Throws:
Exception - if the resource could not be serialised.
See Also:
GCUBEPersistenceDelegate.store(GCUBEStatefulResource)

onLoad

protected void onLoad(RESOURCE resource,
                      ObjectInputStream stream)
               throws Exception
Deserialises the state of resource from a ObjectInputStream. Extends in accordance with resource semantics.

Parameters:
stream - the stream.
Throws:
Exception - if the stream could not be processed.

onStore

protected void onStore(RESOURCE resource,
                       ObjectOutputStream stream)
                throws Exception
Serialises the state of a resource into a ObjectOutputStream. Extend in accordance with resource semantics.

Parameters:
stream - the stream.
Throws:
Exception - if the stream could not be processed.

onRemove

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

Specified by:
onRemove in class GCUBEPersistenceDelegate<RESOURCEID,RESOURCE extends GCUBEStatefulResource<RESOURCEID>>
Throws:
IOException
See Also:
GCUBEPersistenceDelegate.remove(GCUBEStatefulResource)

getResourceIdentifiers

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

Specified by:
getResourceIdentifiers in class GCUBEPersistenceDelegate<RESOURCEID,RESOURCE extends GCUBEStatefulResource<RESOURCEID>>
Returns:
the identifiers.

getFileFromResource

protected abstract File getFileFromResource(RESOURCE resource)
Returns the file serialisation of a resource.

Returns:
the file serialisation.

getSuffix

protected abstract String getSuffix()
Returns the suffix for resource file serialisations.

Returns:
the suffix

getIDFromFileName

protected abstract RESOURCEID getIDFromFileName(String s)
Returns a resource identifier from a string.

Parameters:
s - the string.
Returns:
the identifier.


Copyright © 2012. All Rights Reserved.