gr.uoa.di.madgik.commons.state.store.registry
Class StateStoreRegistry

java.lang.Object
  extended by gr.uoa.di.madgik.commons.state.store.registry.StateStoreRegistry

public class StateStoreRegistry
extends java.lang.Object

This class is the in memory registry of all entries persisted with the State Store Repository. It is used to store metadata information on the available state entries and to retrieve them along with their attached data. The repository does not store any of the actual data the clients provide. In the repository the metadata needed to retrieve the payload stored internally are kept. 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

Author:
gpapanikos

Constructor Summary
StateStoreRegistry()
          Creates a new instance
 
Method Summary
 java.lang.Boolean Contains(java.lang.String Key)
          Checks is the provided key is contained in the in memory structure regardless of whether or not it is active or not
 java.lang.Boolean Delete(java.lang.String Key, StateStoreInfo info)
          Effectivly deletes any StateStoreRegistryKey entry from the State Store Registry that is associated with the provided key.
 void Deserialize(StateStoreInfo info)
          This methdo initializes the in memory data structure from the State Store registry persistency files deserializing the entries found there.
 StateStoreRegistryKey Get(java.lang.String Key)
          Retrieves the StateStoreRegistryKey that is associated with the provided key from the in memory data structure if the key is found in the structure.
 java.util.Map<java.lang.String,StateStoreRegistryKey> GetDictionary()
          Retrieved the dictionary data structure used to store the StateStoreRegistryKey entries
 java.io.File MoveToClean()
          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 increraqsing the size of the repository files.
 java.lang.Boolean Put(StateStoreRegistryKey Key, StateStoreInfo info)
          Adds a StateStoreRegistryKey in the internal data structure.
 void StoreUpdate(StateStoreInfo info, StateStoreRegistryKey entry, boolean update)
          This method stores a new record, or updates an existing one in the state store registry repository file.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

StateStoreRegistry

public StateStoreRegistry()
Creates a new instance

Method Detail

GetDictionary

public java.util.Map<java.lang.String,StateStoreRegistryKey> GetDictionary()
Retrieved the dictionary data structure used to store the StateStoreRegistryKey entries

Returns:
the internal data structure to iterate over entries

Put

public java.lang.Boolean Put(StateStoreRegistryKey Key,
                             StateStoreInfo info)
                      throws java.lang.Exception
Adds a StateStoreRegistryKey in the internal data structure. If the key as retrieved from StateStoreRegistryKey.GetKey() already exists, the entry it points to is replaced with the provided one. Once the StateStoreRegistryKey is inserted in the in memory data structure, it is also persisted in the State Store Registry file. If the entry already existed, it is simply updated there.

Parameters:
Key - The entry to insert or update
info - Information conserning the peristency repositories
Returns:
true if the entries key was not present in the dicitonary before this insert, false otherwise
Throws:
java.lang.Exception - The insert / update could not be updated

Contains

public java.lang.Boolean Contains(java.lang.String Key)
Checks is the provided key is contained in the in memory structure regardless of whether or not it is active or not

Parameters:
Key - the key to check if it is contained
Returns:
true if the key is contained in the in memory data structure, false otherwise

Get

public StateStoreRegistryKey Get(java.lang.String Key)
Retrieves the StateStoreRegistryKey that is associated with the provided key from the in memory data structure if the key is found in the structure.

Parameters:
Key - The key to search for
Returns:
the entry associated with the provided key or null if it is not found

Delete

public java.lang.Boolean Delete(java.lang.String Key,
                                StateStoreInfo info)
                         throws java.lang.Exception
Effectivly deletes any StateStoreRegistryKey entry from the State Store Registry that is associated with the provided key. The entry is set as inactive using StateStoreRegistryKey.Deactivate() and the change is reflected in the registry persistency file

Parameters:
Key - THe key to delete
info - State Store Registry persistency information
Returns:
true if the update was successful, or false if the key was not found
Throws:
java.lang.Exception - The update could not be performed

Deserialize

public void Deserialize(StateStoreInfo info)
                 throws java.lang.Exception
This methdo initializes the in memory data structure from the State Store registry persistency files deserializing the entries found there. If no data file is found, the registry file is also cleaned. Semilarly. if no registry file is found, the data fiule is also cleaned.

Parameters:
info - The State Store repository persistency files
Throws:
java.lang.Exception - The deserialization could not be performed

MoveToClean

public java.io.File MoveToClean()
                         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 increraqsing the size of the repository files. This method reorganizes the registry file into a new temporary file it creates that holds only the needed valid metadata records. During the process each entry that is valid and persisted in the new clean file is also updated in its in memory representation to point to its new position in the new file. This laves the registry part of the repository in an inconsistend state until the file that the StateStoreInfo points to as the registry repository file is deleted and replaced with the file that this method returns

Returns:
The file created holding the new clean file to be used as the repository registry file
Throws:
java.lang.Exception - The clean operation could not be performed

StoreUpdate

public void StoreUpdate(StateStoreInfo info,
                        StateStoreRegistryKey entry,
                        boolean update)
                 throws java.lang.Exception
This method stores a new record, or updates an existing one in the state store registry repository file.

Parameters:
info - The state store repository persistency files
entry - the entry to persist
update - Whether or not to update or store as new the provided entry
Throws:
java.lang.Exception - the stroe / update could not be performed