org.aselect.system.storagemanager.handler
Class MemoryStorageHandler

java.lang.Object
  extended by org.aselect.system.storagemanager.handler.MemoryStorageHandler
All Implemented Interfaces:
IStorageHandler

public class MemoryStorageHandler
extends java.lang.Object
implements IStorageHandler

memory storage handler.

Description:
The MemoryStorageHandler uses a Hashtable for storing objects in memory.

In the MemoryStorageHandler an additional Hashtable is created in which information about the stored record is kept:

 
  Hashtable htStorage { 
        key: Object xKey 
        value: Hashtable htStorageContainer {
                key: String "timestamp" value: Long xTimestamp
                key: String "contents" value: Object xValue } 
  }
  
 


Concurrency issues:
-

Author:
Alfa & Ariss

Field Summary
static java.lang.String MODULE
          The module name.
 
Constructor Summary
MemoryStorageHandler()
           
 
Method Summary
 void cleanup(java.lang.Long lTimestamp)
          Removes the objects from memory table that have been expired.
 boolean containsKey(java.lang.Object oKey)
          Checks if the supplied key already exists in the Hashtable

 void destroy()
          Clear the storage Hashtable.
 java.lang.Object get(java.lang.Object oKey)
          Get a object from memory.
 java.util.Hashtable getAll()
          Get all objects from memory table.
 long getCount()
          Returns the number of objects stored in memory.
 long getTimestamp(java.lang.Object oKey)
          Retrieve an object its timestamp from storage.
 void init(java.lang.Object oConfigSection, ConfigManager oConfigManager, SystemLogger systemLogger, SAMAgent oSAMAgent)
          Initialize the MemoryStorageHandler.
 boolean isMaximum(long lItemCount)
          Checks if the configured maximum items is reached.
 void put(java.lang.Object oKey, java.lang.Object oValue, java.lang.Long lTimestamp)
          Put object in memory.
 void remove(java.lang.Object oKey)
          Remove an object from memory storage.
 void removeAll()
          Remove all objects from memmory table.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

MODULE

public static final java.lang.String MODULE
The module name.

See Also:
Constant Field Values
Constructor Detail

MemoryStorageHandler

public MemoryStorageHandler()
Method Detail

init

public void init(java.lang.Object oConfigSection,
                 ConfigManager oConfigManager,
                 SystemLogger systemLogger,
                 SAMAgent oSAMAgent)
          throws ASelectStorageException
Initialize the MemoryStorageHandler.

Description: Initalises the MemoryStorageHandler:
Concurrency issues:
-

Preconditions:
systemLogger != null

Postconditions:

Specified by:
init in interface IStorageHandler
Parameters:
oConfigSection - The section within the configuration file in which the parameters for the IStorageHandler can be found.
oConfigManager - The configuration.
systemLogger - The logger for system entries.
oSAMAgent - The SAM agant to use.
Throws:
ASelectStorageException - If initialisation fails.
See Also:
IStorageHandler.init(java.lang.Object, org.aselect.system.configmanager.ConfigManager, org.aselect.system.logging.SystemLogger, org.aselect.system.sam.agent.SAMAgent)

get

public java.lang.Object get(java.lang.Object oKey)
                     throws ASelectStorageException
Get a object from memory.

Specified by:
get in interface IStorageHandler
Parameters:
oKey - The identifier of the object that needs to be stored.
Returns:
The stored object.
Throws:
ASelectStorageException - If retrieving fails.
See Also:
IStorageHandler.get(java.lang.Object)

getTimestamp

public long getTimestamp(java.lang.Object oKey)
                  throws ASelectStorageException
Retrieve an object its timestamp from storage.

Specified by:
getTimestamp in interface IStorageHandler
Parameters:
oKey - The identifier of the object that needs to be obtained from the storage.
Returns:
The timestamp of the stored object.
Throws:
ASelectStorageException - If retrieving fails.
See Also:
IStorageHandler.getTimestamp(java.lang.Object)

getCount

public long getCount()
              throws ASelectStorageException
Returns the number of objects stored in memory.

Specified by:
getCount in interface IStorageHandler
Returns:
The number of all stored object.
Throws:
ASelectStorageException - If retrieving fails.
See Also:
IStorageHandler.getCount()

getAll

public java.util.Hashtable getAll()
                           throws ASelectStorageException
Get all objects from memory table.

Specified by:
getAll in interface IStorageHandler
Returns:
A Hashtable containing all stored object as key/value.
Throws:
ASelectStorageException - If retrieving fails.
See Also:
IStorageHandler.getAll()

put

public void put(java.lang.Object oKey,
                java.lang.Object oValue,
                java.lang.Long lTimestamp)
         throws ASelectStorageException
Put object in memory.

Specified by:
put in interface IStorageHandler
Parameters:
oKey - The identifier of the object that needs to be stored.
oValue - The object that needs to be stored.
lTimestamp - The time at which the object is stored.
Throws:
ASelectStorageException - If storing fails.
See Also:
IStorageHandler.put(java.lang.Object, java.lang.Object, java.lang.Long)

remove

public void remove(java.lang.Object oKey)
            throws ASelectStorageException
Remove an object from memory storage.

Specified by:
remove in interface IStorageHandler
Parameters:
oKey - The identifier of the object that needs to be removed.
Throws:
ASelectStorageException - If removal fails.
See Also:
IStorageHandler.remove(java.lang.Object)

removeAll

public void removeAll()
               throws ASelectStorageException
Remove all objects from memmory table.

Specified by:
removeAll in interface IStorageHandler
Throws:
ASelectStorageException - if removal fails.
See Also:
IStorageHandler.removeAll()

cleanup

public void cleanup(java.lang.Long lTimestamp)
             throws ASelectStorageException
Removes the objects from memory table that have been expired.

Specified by:
cleanup in interface IStorageHandler
Parameters:
lTimestamp - The expiration time.
Throws:
ASelectStorageException - If cleaning fails.
See Also:
IStorageHandler.cleanup(java.lang.Long)

destroy

public void destroy()
Clear the storage Hashtable.

Specified by:
destroy in interface IStorageHandler
See Also:
IStorageHandler.destroy()

isMaximum

public boolean isMaximum(long lItemCount)
                  throws ASelectStorageException
Checks if the configured maximum items is reached.

Specified by:
isMaximum in interface IStorageHandler
Parameters:
lItemCount - number of items that will be checked if it is the maximum
Returns:
TRUE if storage maximum is reached
Throws:
ASelectStorageException - if io error occurred with physical storage
See Also:
IStorageHandler.isMaximum(long)

containsKey

public boolean containsKey(java.lang.Object oKey)
                    throws ASelectStorageException
Checks if the supplied key already exists in the Hashtable

Specified by:
containsKey in interface IStorageHandler
Parameters:
oKey - The unique key that will be checked for existance
Returns:
TRUE if the key exists
Throws:
ASelectStorageException - if IO error occurred with physical storage
See Also:
IStorageHandler.containsKey(java.lang.Object)


Copyright © 2008 SURFnet BV. All Rights Reserved.