public class StateManager extends Object
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| Constructor and Description |
|---|
StateManager() |
| Modifier and Type | Method and Description |
|---|---|
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 Boolean |
Contains(String key)
Checks if the provided key is contained in the State Store Repository.
|
static StateStoreRegistryKey.EntryType |
ContainsType(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(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 String |
GetAlphanumeric(String Key)
Retrieves the payload associated with the provided key as an alphanumeric string
|
static byte[] |
GetByteArray(String Key)
Retrieves the payload associated with the provided key as a byte array
|
static File |
GetFile(String Key)
Retrieves the payload associated with the provided key as a file whose content is teh stored data
|
static ISerializable |
GetISerializable(String Key)
Retrieves the payload associated with the provided key as an object
|
static Serializable |
GetSerializable(String Key)
Retrieves the payload associated with the provided key as an object
|
static String |
GetStateStoreInfo()
Retrieves a string representation of the
StateStoreInfo |
static Boolean |
Put(String key,
byte[] bytearray)
Adds or updates the
StateStoreRegistryKey referenced by the providede key. |
static Boolean |
Put(String key,
File file)
Adds or updates the
StateStoreRegistryKey referenced by the providede key. |
static Boolean |
Put(String key,
ISerializable obj)
Adds or updates the
StateStoreRegistryKey referenced by the providede key. |
static Boolean |
Put(String key,
Serializable obj)
Adds or updates the
StateStoreRegistryKey referenced by the providede key. |
static Boolean |
Put(String key,
String Alphanumeric)
Adds or updates the
StateStoreRegistryKey referenced by the providede key. |
public static String GetStateStoreInfo()
StateStoreInfoStateStoreInfopublic static boolean Delete(String Key) throws Exception
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 returnedKey - The key whose entry should be marked as inactivefalse 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)Exception - The delete could not be performedpublic static Boolean Contains(String key)
StateStoreRegistryKey is active.key - The key to check fortrue if thekey is associated with an existing and active entry,false otherwisepublic static StateStoreRegistryKey.EntryType ContainsType(String key) throws Exception
Contains(java.lang.String)
dictates, this method returns the type of data the entry storeskey - The key to check if it is associtated with an entryStateStoreRegistryKey.GetTypeOfEntry()Exception - The key was not foundpublic static String GetAlphanumeric(String Key) throws Exception
Key - The key whose value to retrieveException - The retrieval could not be accomplishedpublic static File GetFile(String Key) throws Exception
Key - The key whose value to retrieveException - The retrieval could not be accomplishedpublic static byte[] GetByteArray(String Key) throws Exception
Key - The key whose value to retrieveException - The retrieval could not be accomplishedpublic static Serializable GetSerializable(String Key) throws Exception
Key - The key whose value to retrieveException - The retrieval could not be accomplishedpublic static ISerializable GetISerializable(String Key) throws Exception
Key - The key whose value to retrieveException - The retrieval could not be accomplishedpublic static Boolean Put(String key, String Alphanumeric) throws Exception
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)
callkey - The key to associate the provided payload withAlphanumeric - The payload to storeStateStoreRegistry.Put(gr.uoa.di.madgik.commons.state.store.registry.StateStoreRegistryKey, gr.uoa.di.madgik.commons.state.store.StateStoreInfo)Exception - The addition could not be performedpublic static Boolean Put(String key, byte[] bytearray) throws Exception
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)
callkey - The key to associate the provided payload withbytearray - The payload to storeStateStoreRegistry.Put(gr.uoa.di.madgik.commons.state.store.registry.StateStoreRegistryKey, gr.uoa.di.madgik.commons.state.store.StateStoreInfo)Exception - The addition could not be performedpublic static Boolean Put(String key, ISerializable obj) throws Exception
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)
callkey - The key to associate the provided payload withobj - The object to storeStateStoreRegistry.Put(gr.uoa.di.madgik.commons.state.store.registry.StateStoreRegistryKey, gr.uoa.di.madgik.commons.state.store.StateStoreInfo)Exception - The addition could not be performedpublic static Boolean Put(String key, Serializable obj) throws Exception
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)
callkey - The key to associate the provided payload withobj - The object to storeStateStoreRegistry.Put(gr.uoa.di.madgik.commons.state.store.registry.StateStoreRegistryKey, gr.uoa.di.madgik.commons.state.store.StateStoreInfo)Exception - The addition could not be performedpublic static Boolean Put(String key, File file) throws Exception
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)
callkey - The key to associate the provided payload withfile - The file whose payload to storeStateStoreRegistry.Put(gr.uoa.di.madgik.commons.state.store.registry.StateStoreRegistryKey, gr.uoa.di.madgik.commons.state.store.StateStoreInfo)Exception - The addition could not be performedpublic static void Compact()
throws Exception
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 StateStoreInfoException - The cleanup could not be perofrmedCopyright © 2018. All Rights Reserved.