gr.uoa.di.madgik.commons.state
Class StateManager

java.lang.Object
  extended by gr.uoa.di.madgik.commons.state.StateManager

public class StateManager
extends java.lang.Object

The StateManager class is a utility class serving as the entry point to the State Store Repository utility. Its purpose is to interface between clients and a persistency key-value system to enable clients to stroe state they may need in case of restarts or simply as lognterm or temporary storage without needing to directly interact with the filesystem or other data stores. The utility uses two files in the local filesystem to persist information it needs. One file is used to store metadata on the entries that are stored and the other tha actual payload of the provided entries. The files that are used are retrived through the ConfigurationManager where the StateManager expects to find under the StateManager.StateStoreInfo key an instnace of the StateStoreInfo class holding the files to use. The StateStoreData instnace also expects to find some information in the ConfigurationManager. The actual markup that needs to be stored in the configuration file is shown below

 <param name="EncodingCharset" type="String" generated="false" internal="false">UTF-8</param>
 <param name="StateManager.CleanUpOnInit" type="BooleanPrimitive" generated="false" internal="false">CleanUp data and registry files on initialization</param>
 <param name="StateManager.EntryRegistryPathName" type="String" generated="false" internal="true">path to registry file to use</param>
 <param name="StateManager.EntryRegistryFile" type="Object" generated="false" internal="false" shared="false">
  <class value="java.io.File" />
   <constructor>
    <arguments>
     <arg order="1" name="pathname" param="StateManager.EntryRegistryPathName"/>
    </arguments>
   </constructor>
 </param>
 <param name="StateManager.EntryDataPathName" type="String" generated="false" internal="true">path to data file to use</param>
 <param name="StateManager.EntryDataFile" type="Object" generated="false" internal="false" shared="false">
  <class value="java.io.File" />
   <constructor>
    <arguments>
	   <arg order="1" name="pathname" param="StateManager.EntryDataPathName"/>
    </arguments>
   </constructor>
 </param>
 <param name="StateManager.StateStoreInfo" type="Object" generated="false" internal="false" shared="false">
  <class value="gr.uoa.di.madgik.state.store.StateStoreInfo" />
  <constructor>
   <arguments>
    <arg order="1" name="EntryRegistryFile" param="StateManager.EntryRegistryFile"/>
    <arg order="2" name="EntryDataFile" param="StateManager.EntryDataFile"/>
   </arguments>
  </constructor>
 </param>
 
 
 

Different types of entries can be stored to the State Store Repository whose values will be retrieved and storerd with different ways. These types are the ones depicted by the StateStoreRegistryKey.EntryType enumeration. The StateManager provides serialized access to its resources. TODO Add functionality to compress data before storing them TODO More sophisticated CleanUp initiation policy

Author:
gpapanikos

Constructor Summary
StateManager()
           
 
Method Summary
static void Compact()
          In case of deletes and updates in the registry and data file, there will be data kept in the files that are no longer needed but simply remain increrasing the size of the repository files.
static java.lang.Boolean Contains(java.lang.String key)
          Checks if the provided key is contained in the State Store Repository.
static StateStoreRegistryKey.EntryType ContainsType(java.lang.String key)
          If the provided key is associated in the State Store as the Contains(java.lang.String) dictates, this method returns the type of data the entry stores
static boolean Delete(java.lang.String Key)
          If the priovided key is available in the State Store as dictated by Contains(java.lang.String) the StateStoreRegistry.Delete(java.lang.String, gr.uoa.di.madgik.commons.state.store.StateStoreInfo) method is called and its return value returned.
static java.lang.String GetAlphanumeric(java.lang.String Key)
          Retrieves the payload associated with the provided key as an alphanumeric string
static byte[] GetByteArray(java.lang.String Key)
          Retrieves the payload associated with the provided key as a byte array
static java.io.File GetFile(java.lang.String Key)
          Retrieves the payload associated with the provided key as a file whose content is teh stored data
static ISerializable GetISerializable(java.lang.String Key)
          Retrieves the payload associated with the provided key as an object
static java.io.Serializable GetSerializable(java.lang.String Key)
          Retrieves the payload associated with the provided key as an object
static java.lang.String GetStateStoreInfo()
          Retrieves a string representation of the StateStoreInfo
static java.lang.Boolean Put(java.lang.String key, byte[] bytearray)
          Adds or updates the StateStoreRegistryKey referenced by the providede key.
static java.lang.Boolean Put(java.lang.String key, java.io.File file)
          Adds or updates the StateStoreRegistryKey referenced by the providede key.
static java.lang.Boolean Put(java.lang.String key, ISerializable obj)
          Adds or updates the StateStoreRegistryKey referenced by the providede key.
static java.lang.Boolean Put(java.lang.String key, java.io.Serializable obj)
          Adds or updates the StateStoreRegistryKey referenced by the providede key.
static java.lang.Boolean Put(java.lang.String key, java.lang.String Alphanumeric)
          Adds or updates the StateStoreRegistryKey referenced by the providede key.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

StateManager

public StateManager()
Method Detail

GetStateStoreInfo

public static java.lang.String GetStateStoreInfo()
Retrieves a string representation of the StateStoreInfo

Returns:
The string representation of the StateStoreInfo

Delete

public static boolean Delete(java.lang.String Key)
                      throws java.lang.Exception
If the priovided key is available in the State Store as dictated by Contains(java.lang.String) the StateStoreRegistry.Delete(java.lang.String, gr.uoa.di.madgik.commons.state.store.StateStoreInfo) method is called and its return value returned. Otherwise, false is returned

Parameters:
Key - The key whose entry should be marked as inactive
Returns:
false if the key is not assciated with an entry, otherwise the return value of StateStoreRegistry.Delete(java.lang.String, gr.uoa.di.madgik.commons.state.store.StateStoreInfo)
Throws:
java.lang.Exception - The delete could not be performed

Contains

public static java.lang.Boolean Contains(java.lang.String key)
Checks if the provided key is contained in the State Store Repository. It does not only check if the key is stored in the internal data structuire but also that the associated StateStoreRegistryKey is active.

Parameters:
key - The key to check for
Returns:
true if thekey is associated with an existing and active entry,false otherwise

ContainsType

public static StateStoreRegistryKey.EntryType ContainsType(java.lang.String key)
                                                    throws java.lang.Exception
If the provided key is associated in the State Store as the Contains(java.lang.String) dictates, this method returns the type of data the entry stores

Parameters:
key - The key to check if it is associtated with an entry
Returns:
the type of entry as returned by StateStoreRegistryKey.GetTypeOfEntry()
Throws:
java.lang.Exception - The key was not found

GetAlphanumeric

public static java.lang.String GetAlphanumeric(java.lang.String Key)
                                        throws java.lang.Exception
Retrieves the payload associated with the provided key as an alphanumeric string

Parameters:
Key - The key whose value to retrieve
Returns:
The payload
Throws:
java.lang.Exception - The retrieval could not be accomplished

GetFile

public static java.io.File GetFile(java.lang.String Key)
                            throws java.lang.Exception
Retrieves the payload associated with the provided key as a file whose content is teh stored data

Parameters:
Key - The key whose value to retrieve
Returns:
The File
Throws:
java.lang.Exception - The retrieval could not be accomplished

GetByteArray

public static byte[] GetByteArray(java.lang.String Key)
                           throws java.lang.Exception
Retrieves the payload associated with the provided key as a byte array

Parameters:
Key - The key whose value to retrieve
Returns:
The byte array
Throws:
java.lang.Exception - The retrieval could not be accomplished

GetSerializable

public static java.io.Serializable GetSerializable(java.lang.String Key)
                                            throws java.lang.Exception
Retrieves the payload associated with the provided key as an object

Parameters:
Key - The key whose value to retrieve
Returns:
The object
Throws:
java.lang.Exception - The retrieval could not be accomplished

GetISerializable

public static ISerializable GetISerializable(java.lang.String Key)
                                      throws java.lang.Exception
Retrieves the payload associated with the provided key as an object

Parameters:
Key - The key whose value to retrieve
Returns:
The object
Throws:
java.lang.Exception - The retrieval could not be accomplished

Put

public static java.lang.Boolean Put(java.lang.String key,
                                    java.lang.String Alphanumeric)
                             throws java.lang.Exception
Adds or updates the StateStoreRegistryKey referenced by the providede key. Uses StateStoreRegistry.Put(gr.uoa.di.madgik.commons.state.store.registry.StateStoreRegistryKey, gr.uoa.di.madgik.commons.state.store.StateStoreInfo) and StateStoreData.Put(gr.uoa.di.madgik.commons.state.store.registry.StateStoreRegistryKey, java.lang.String) to update its internal structures. The value returend is the returned by the StateStoreRegistry.Put(gr.uoa.di.madgik.commons.state.store.registry.StateStoreRegistryKey, gr.uoa.di.madgik.commons.state.store.StateStoreInfo) call

Parameters:
key - The key to associate the provided payload with
Alphanumeric - The payload to store
Returns:
The return value of StateStoreRegistry.Put(gr.uoa.di.madgik.commons.state.store.registry.StateStoreRegistryKey, gr.uoa.di.madgik.commons.state.store.StateStoreInfo)
Throws:
java.lang.Exception - The addition could not be performed

Put

public static java.lang.Boolean Put(java.lang.String key,
                                    byte[] bytearray)
                             throws java.lang.Exception
Adds or updates the StateStoreRegistryKey referenced by the providede key. Uses StateStoreRegistry.Put(gr.uoa.di.madgik.commons.state.store.registry.StateStoreRegistryKey, gr.uoa.di.madgik.commons.state.store.StateStoreInfo) and StateStoreData.Put(gr.uoa.di.madgik.commons.state.store.registry.StateStoreRegistryKey, byte[]) to update its internal structures. The value returend is the returned by the StateStoreRegistry.Put(gr.uoa.di.madgik.commons.state.store.registry.StateStoreRegistryKey, gr.uoa.di.madgik.commons.state.store.StateStoreInfo) call

Parameters:
key - The key to associate the provided payload with
bytearray - The payload to store
Returns:
The return value of StateStoreRegistry.Put(gr.uoa.di.madgik.commons.state.store.registry.StateStoreRegistryKey, gr.uoa.di.madgik.commons.state.store.StateStoreInfo)
Throws:
java.lang.Exception - The addition could not be performed

Put

public static java.lang.Boolean Put(java.lang.String key,
                                    ISerializable obj)
                             throws java.lang.Exception
Adds or updates the StateStoreRegistryKey referenced by the providede key. Uses StateStoreRegistry.Put(gr.uoa.di.madgik.commons.state.store.registry.StateStoreRegistryKey, gr.uoa.di.madgik.commons.state.store.StateStoreInfo) and StateStoreData.Put(gr.uoa.di.madgik.commons.state.store.registry.StateStoreRegistryKey, gr.uoa.di.madgik.commons.state.store.data.ISerializable) to update its internal structures. The value returend is the returned by the StateStoreRegistry.Put(gr.uoa.di.madgik.commons.state.store.registry.StateStoreRegistryKey, gr.uoa.di.madgik.commons.state.store.StateStoreInfo) call

Parameters:
key - The key to associate the provided payload with
obj - The object to store
Returns:
The return value of StateStoreRegistry.Put(gr.uoa.di.madgik.commons.state.store.registry.StateStoreRegistryKey, gr.uoa.di.madgik.commons.state.store.StateStoreInfo)
Throws:
java.lang.Exception - The addition could not be performed

Put

public static java.lang.Boolean Put(java.lang.String key,
                                    java.io.Serializable obj)
                             throws java.lang.Exception
Adds or updates the StateStoreRegistryKey referenced by the providede key. Uses StateStoreRegistry.Put(gr.uoa.di.madgik.commons.state.store.registry.StateStoreRegistryKey, gr.uoa.di.madgik.commons.state.store.StateStoreInfo) and StateStoreData.Put(gr.uoa.di.madgik.commons.state.store.registry.StateStoreRegistryKey, java.io.Serializable) to update its internal structures. The value returend is the returned by the StateStoreRegistry.Put(gr.uoa.di.madgik.commons.state.store.registry.StateStoreRegistryKey, gr.uoa.di.madgik.commons.state.store.StateStoreInfo) call

Parameters:
key - The key to associate the provided payload with
obj - The object to store
Returns:
The return value of StateStoreRegistry.Put(gr.uoa.di.madgik.commons.state.store.registry.StateStoreRegistryKey, gr.uoa.di.madgik.commons.state.store.StateStoreInfo)
Throws:
java.lang.Exception - The addition could not be performed

Put

public static java.lang.Boolean Put(java.lang.String key,
                                    java.io.File file)
                             throws java.lang.Exception
Adds or updates the StateStoreRegistryKey referenced by the providede key. Uses StateStoreRegistry.Put(gr.uoa.di.madgik.commons.state.store.registry.StateStoreRegistryKey, gr.uoa.di.madgik.commons.state.store.StateStoreInfo) and StateStoreData.Put(gr.uoa.di.madgik.commons.state.store.registry.StateStoreRegistryKey, java.io.File) to update its internal structures. The value returend is the returned by the StateStoreRegistry.Put(gr.uoa.di.madgik.commons.state.store.registry.StateStoreRegistryKey, gr.uoa.di.madgik.commons.state.store.StateStoreInfo) call

Parameters:
key - The key to associate the provided payload with
file - The file whose payload to store
Returns:
The return value of StateStoreRegistry.Put(gr.uoa.di.madgik.commons.state.store.registry.StateStoreRegistryKey, gr.uoa.di.madgik.commons.state.store.StateStoreInfo)
Throws:
java.lang.Exception - The addition could not be performed

Compact

public static void Compact()
                    throws java.lang.Exception
In case of deletes and updates in the registry and data file, there will be data kept in the files that are no longer needed but simply remain increrasing the size of the repository files. This method reorganizes the registry and data files into new temporary files using StateStoreRegistry.MoveToClean() and StateStoreData.MoveToClean(java.util.Map) methods, updates the StateStoreRegistryKey entries in the registry file, removes the old repository files, and renames the new clean ones to the ones dictated by StateStoreInfo

Throws:
java.lang.Exception - The cleanup could not be perofrmed