gr.uoa.di.madgik.commons.state.store.data
Class StateStoreData

java.lang.Object
  extended by gr.uoa.di.madgik.commons.state.store.data.StateStoreData

public class StateStoreData
extends java.lang.Object

Class responsible of handling the persistency and retrieval of the actual state data clients want to persiste with the State Store Repository. This class dows not keep any internal state and is instanciated every time a new operation needs to be perofrmed on the repository payload data. The operations this class provides are not thread safe and even though it represents a shared resource it does not provide any kind of of resource locking policy. This is left to the wrapping class, StateManager. This class needs a value kith key EncodingCharset in the ConfigurationManager representing the charaset name to use during alphanumeric storage and retrieval through Put(gr.uoa.di.madgik.commons.state.store.registry.StateStoreRegistryKey, java.lang.String) and GetAlphanumeric(gr.uoa.di.madgik.commons.state.store.registry.StateStoreRegistryKey)

Author:
gpapanikos

Constructor Summary
StateStoreData(StateStoreInfo Info)
          Creates a new instance
 
Method Summary
 java.lang.String GetAlphanumeric(StateStoreRegistryKey Key)
          Retrieves the actual payload referenced by the provided metadata entry and returns it as the expected type.
 byte[] GetByteArray(StateStoreRegistryKey Key)
          Retrieves the actual payload referenced by the provided metadata entry and returns it as the expected type.
 java.io.File GetFile(StateStoreRegistryKey Key)
          Retrieves the actual payload referenced by the provided metadata entry and returns it as the expected type.
 ISerializable GetISerializable(StateStoreRegistryKey Key)
          Retrieves the actual payload referenced by the provided metadata entry and returns it as the expected type.
 java.io.Serializable GetSerializable(StateStoreRegistryKey Key)
          Retrieves the actual payload referenced by the provided metadata entry and returns it as the expected type.
 java.io.File MoveToClean(java.util.Map<java.lang.String,StateStoreRegistryKey> registry)
          In case of deletes and updates in the registry and data file, there will be data kept in the file that are no longer needed but simply remain increrasing the size of the repository files.
 void Put(StateStoreRegistryKey Key, byte[] bytearray)
          Appends the provided payload to the repository data file.
 void Put(StateStoreRegistryKey Key, java.io.File file)
          Appends the provided payload to the repository data file.
 void Put(StateStoreRegistryKey Key, ISerializable obj)
          Appends the provided payload to the repository data file.
 void Put(StateStoreRegistryKey Key, java.io.Serializable obj)
          Appends the provided payload to the repository data file.
 void Put(StateStoreRegistryKey Key, java.lang.String Alphanumeric)
          Appends the provided payload to the repository data file.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

StateStoreData

public StateStoreData(StateStoreInfo Info)
Creates a new instance

Parameters:
Info - The repository persistency files information
Method Detail

Put

public void Put(StateStoreRegistryKey Key,
                java.lang.String Alphanumeric)
         throws java.lang.Exception
Appends the provided payload to the repository data file. The provided metadata StateStoreRegistryKey entry is updated with the offsets of the stored data

Parameters:
Key - The metadata entry representing the data.
Alphanumeric - The payload to store as a sequence of bytes using the configuration value with key EncodingCharset from the ConfigurationManager
Throws:
java.lang.Exception - the store could not be performed

GetAlphanumeric

public java.lang.String GetAlphanumeric(StateStoreRegistryKey Key)
                                 throws java.lang.Exception
Retrieves the actual payload referenced by the provided metadata entry and returns it as the expected type.

Parameters:
Key - The metadate entry referencing the data to retrieve
Returns:
The payload after decoding it using the value with key EncodingCharset from the ConfigurationManager back to a string from a byte array
Throws:
java.lang.Exception - The retrieval could not be performed

Put

public void Put(StateStoreRegistryKey Key,
                byte[] bytearray)
         throws java.lang.Exception
Appends the provided payload to the repository data file. The provided metadata StateStoreRegistryKey entry is updated with the offsets of the stored data

Parameters:
Key - The metadata entry representing the data.
bytearray - The payload to store as a sequence of bytes
Throws:
java.lang.Exception - The store could not be performed

GetByteArray

public byte[] GetByteArray(StateStoreRegistryKey Key)
                    throws java.lang.Exception
Retrieves the actual payload referenced by the provided metadata entry and returns it as the expected type.

Parameters:
Key - The metadate entry referencing the data to retrieve
Returns:
The payload
Throws:
java.lang.Exception - The retrieval could not be performed

Put

public void Put(StateStoreRegistryKey Key,
                ISerializable obj)
         throws java.lang.Exception
Appends the provided payload to the repository data file. The provided metadata StateStoreRegistryKey entry is updated with the offsets of the stored data

Parameters:
Key - The metadata entry representing the data.
obj - The object to store serializing it through ISerializable.Serialize()
Throws:
java.lang.Exception - The store could not be performed

GetISerializable

public ISerializable GetISerializable(StateStoreRegistryKey Key)
                               throws java.lang.Exception
Retrieves the actual payload referenced by the provided metadata entry and returns it as the expected type.

Parameters:
Key - The metadate entry referencing the data to retrieve
Returns:
The object instantiated with its default constructor and populated through the ISerializable.Deserialize(byte[])
Throws:
java.lang.Exception - The retrieval could not be performed

Put

public void Put(StateStoreRegistryKey Key,
                java.io.Serializable obj)
         throws java.lang.Exception
Appends the provided payload to the repository data file. The provided metadata StateStoreRegistryKey entry is updated with the offsets of the stored data

Parameters:
Key - The metadata entry representing the data.
obj - The object to store serializing it through an ObjectOutputStream
Throws:
java.lang.Exception - The store could not be performed

GetSerializable

public java.io.Serializable GetSerializable(StateStoreRegistryKey Key)
                                     throws java.lang.Exception
Retrieves the actual payload referenced by the provided metadata entry and returns it as the expected type.

Parameters:
Key - The metadate entry referencing the data to retrieve
Returns:
The object retrieved using an ObjectInputStream
Throws:
java.lang.Exception - The retrieval could not be performed

Put

public void Put(StateStoreRegistryKey Key,
                java.io.File file)
         throws java.lang.Exception
Appends the provided payload to the repository data file. The provided metadata StateStoreRegistryKey entry is updated with the offsets of the stored data

Parameters:
Key - The metadata entry representing the data.
file - The file whose payload to retrieve and store
Throws:
java.lang.Exception - The store could not be performed

GetFile

public java.io.File GetFile(StateStoreRegistryKey Key)
                     throws java.lang.Exception
Retrieves the actual payload referenced by the provided metadata entry and returns it as the expected type.

Parameters:
Key - The metadate entry referencing the data to retrieve
Returns:
The temporary file created where the payload is stored as it is retrieved by the repository data file
Throws:
java.lang.Exception - The retrieval could not be performed

MoveToClean

public java.io.File MoveToClean(java.util.Map<java.lang.String,StateStoreRegistryKey> registry)
                         throws java.lang.Exception
In case of deletes and updates in the registry and data file, there will be data kept in the file that are no longer needed but simply remain increrasing the size of the repository files. This method reorganizes the data file into a new temporary file it creates that holds only the needed valid data records. During the process each entry that is valid as provided by the caller it is persisted in the new clean file. The metadata entries provided are also updated to point to the new offsets where their respective data are stored. This leaves the registry part of the repository in an inconsistend state until the file that the StateStoreInfo points to as the data repository file is deleted and replaced with the file that this method returns

Parameters:
registry - the in memeory structure holding the entries that should be kept from the data file
Returns:
The file created holding the new clean file to be used as the repository data file
Throws:
java.lang.Exception - The clean operation could not be performed