de.cesr.lara.components.container.memory.impl
Class LDefaultMemory<PropertyType extends LaraProperty<? extends PropertyType,?>>

java.lang.Object
  extended by de.cesr.lara.components.container.memory.impl.LDefaultMemory<PropertyType>
Type Parameters:
PropertyType -
All Implemented Interfaces:
LaraContainer<PropertyType>, LaraMemory<PropertyType>, LaraStorageListener, Iterable<PropertyType>
Direct Known Subclasses:
LDefaultLimitedCapacityMemory

public class LDefaultMemory<PropertyType extends LaraProperty<? extends PropertyType,?>>
extends Object
implements LaraMemory<PropertyType>, LaraStorageListener

TODO memory observer pattern!


Nested Class Summary
 
Nested classes/interfaces inherited from interface de.cesr.lara.components.container.storage.LaraStorageListener
LaraStorageListener.StorageEvent
 
Field Summary
 
Fields inherited from interface de.cesr.lara.components.container.memory.LaraMemory
UNLIMITED_RETENTION
 
Fields inherited from interface de.cesr.lara.components.container.LaraContainer
UNLIMITED_CAPACITY
 
Constructor Summary
LDefaultMemory()
           
LDefaultMemory(int defaultRetentionTime)
           
LDefaultMemory(int defaultRetentionTime, String name)
           
LDefaultMemory(String name)
           
 
Method Summary
 void addMemoryPropertyObserver(LaraMemoryListener.MemoryEvent eventType, LaraMemoryListener listener)
          Adds a given LaraMemoryListener for the specified LaraMemoryListener.MemoryEvent
 void clear()
          Clears the memory, i.e. removes all properties.
 boolean contains(Class<?> propertyType, String key)
          Checks whether the memory contains a property of the given type with the given key.
 boolean contains(PropertyType property)
          Checks whether the memory contains the given LaraProperty.
 boolean contains(PropertyType property, String key)
          Checks whether the memory contains the given LaraProperty with the given key.
 boolean contains(String key)
          Checks whether the memory contains a LaraProperty with the given key.
 boolean contains(String key, int timestamp)
          Checks whether the memory contains a LaraProperty with the given key for the given time stamp.
protected  LaraStorage<PropertyType> createBackingStorage()
          Overwrite this method in order to change the storage to be used by the memory.
 PropertyType forget(PropertyType propertyToRemove)
          Removes the specified property from this memory.
 PropertyType forget(String key, int step)
          Removes the property with the specified key that was memorised in step from this memory.
 Collection<PropertyType> forgetAll(Collection<PropertyType> propertiesToBeRemoved)
          Removes all properties in the specified collection from this memory.
 Collection<PropertyType> forgetAll(String key)
          Removes all properties that are identified by the specified key.
 Set<String> getAllPropertyKeys()
          Returns a set of Strings that represent the keys of properties memorised in the memory such that any property in the memory is represented.
 int getCapacity()
          Returns the capacity of this container, i.e. the number of items that can be stored or LaraContainer.UNLIMITED_CAPACITY (the default) if it is (virtually) unlimited.
 int getDefaultRetentionTime()
          Return the default retention time
 String getName()
          Returns the name of this memory
 int getRetentionTime(PropertyType property)
          Returns the remaining retention time for the given property.
 int getSize()
          Returns the current size, i.e. the number of items currently stored.
 boolean isEmpty()
          Returns true, if and only if this container is empty.
 boolean isFull()
          Returns true, if and only if this container is full (see also LaraCapacityManager).
 Iterator<PropertyType> iterator()
           
 void memorize(PropertyType propertyToMemorize)
          Tries to add the specified property to this memory applying the default retention time.
 void memorize(PropertyType propertyToMemorize, int retentionTime)
          Tries to add the specified property to this memory with the given retention time.
<RequestPropertyType extends PropertyType>
RequestPropertyType
recall(Class<RequestPropertyType> propertyType, String key)
          Generic method that returns the most recently memorised property that is of the specified type (including sub types) and identified with key.
<RequestPropertyType extends PropertyType>
RequestPropertyType
recall(Class<RequestPropertyType> propertyType, String key, int step)
          Generic method that returns the first property found that is of the specified type (including sub types), was memorised in step and identified with key.
 PropertyType recall(String key)
          Generic method that returns the most recently memorised property that is identified with key.
 PropertyType recall(String key, int step)
          Generic method that returns the first property that was memorised in step and identified with key .
<RequestPropertyType extends PropertyType>
Collection<RequestPropertyType>
recallAll(Class<RequestPropertyType> propertyType)
          Generic method that returns a collection of all properties found that are of the specified type (including sub types).
<RequestPropertyType extends PropertyType>
Collection<RequestPropertyType>
recallAll(Class<RequestPropertyType> propertyType, String key)
          Generic method that returns a collection of all properties found that are of the specified type (including sub types)and are identified by key.
 Collection<PropertyType> recallAll(String key)
          Generic method that returns a collection of all properties found that are identified by key.
 void refresh(PropertyType propertyToRefresh)
          Tries to refresh the specified property in this memory applying the default retention time.
 void refresh(PropertyType propertyToRefresh, int retentionTime)
          Refreshes the property from this memory and assigns the given retention time.
 void refresh(String key)
          Refreshes the property with the specified key that was memorised last from this memory.
 void refresh(String key, int step)
          Refreshes the property with the specified key that was memorised in step from this memory.
 void refresh(String key, int step, int retentionTime)
          Refreshes the property with the specified key that was memorised last from this memory and assigns the given retention time.
 void removeMemoryPropertyObserver(LaraMemoryListener.MemoryEvent eventType, LaraMemoryListener listener)
           
 void setDefaultRetentionTime(int defaultRetentionTime)
          Sets the default retention time
 void storageEventOccured(LaraStorageListener.StorageEvent event, LaraProperty<?,?> property)
           
 String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

LDefaultMemory

public LDefaultMemory()

LDefaultMemory

public LDefaultMemory(int defaultRetentionTime)
Parameters:
defaultRetentionTime -

LDefaultMemory

public LDefaultMemory(int defaultRetentionTime,
                      String name)
Parameters:
defaultRetentionTime -
name - the memory's name

LDefaultMemory

public LDefaultMemory(String name)
Parameters:
name - the memory's name
Method Detail

addMemoryPropertyObserver

public void addMemoryPropertyObserver(LaraMemoryListener.MemoryEvent eventType,
                                      LaraMemoryListener listener)
Description copied from interface: LaraMemory
Adds a given LaraMemoryListener for the specified LaraMemoryListener.MemoryEvent

Specified by:
addMemoryPropertyObserver in interface LaraMemory<PropertyType extends LaraProperty<? extends PropertyType,?>>
Parameters:
eventType - the category of memory property events the listeners shall be registered for
listener - the listener to be registered
See Also:
LaraMemory.addMemoryPropertyObserver(de.cesr.lara.components.container.memory.LaraMemoryListener.MemoryEvent, de.cesr.lara.components.container.memory.LaraMemoryListener)

clear

public void clear()
           throws LRemoveException
Description copied from interface: LaraMemory
Clears the memory, i.e. removes all properties.

Specified by:
clear in interface LaraMemory<PropertyType extends LaraProperty<? extends PropertyType,?>>
Throws:
LRemoveException

contains

public boolean contains(Class<?> propertyType,
                        String key)
Description copied from interface: LaraMemory
Checks whether the memory contains a property of the given type with the given key.

Specified by:
contains in interface LaraMemory<PropertyType extends LaraProperty<? extends PropertyType,?>>
Returns:
true if such a property is contained
See Also:
LaraMemory.contains(java.lang.Class, java.lang.String)

contains

public boolean contains(PropertyType property)
Description copied from interface: LaraMemory
Checks whether the memory contains the given LaraProperty.

Specified by:
contains in interface LaraMemory<PropertyType extends LaraProperty<? extends PropertyType,?>>
Returns:
true if such a property is contained
See Also:
LaraMemory.contains(de.cesr.lara.components.LaraProperty)

contains

public boolean contains(PropertyType property,
                        String key)
Description copied from interface: LaraMemory
Checks whether the memory contains the given LaraProperty with the given key.

Specified by:
contains in interface LaraMemory<PropertyType extends LaraProperty<? extends PropertyType,?>>
Returns:
true if such a property is contained
See Also:
LaraMemory.contains(de.cesr.lara.components.LaraProperty, java.lang.String)

contains

public boolean contains(String key)
Description copied from interface: LaraMemory
Checks whether the memory contains a LaraProperty with the given key.

Specified by:
contains in interface LaraMemory<PropertyType extends LaraProperty<? extends PropertyType,?>>
Returns:
true if such a property is contained
See Also:
LaraMemory.contains(java.lang.String)

contains

public boolean contains(String key,
                        int timestamp)
Description copied from interface: LaraMemory
Checks whether the memory contains a LaraProperty with the given key for the given time stamp.

Specified by:
contains in interface LaraMemory<PropertyType extends LaraProperty<? extends PropertyType,?>>
Returns:
true if such a property is contained
See Also:
LaraMemory.contains(java.lang.String, int)

forget

public PropertyType forget(PropertyType propertyToRemove)
                                                                   throws LRemoveException
Description copied from interface: LaraMemory
Removes the specified property from this memory.

Specified by:
forget in interface LaraMemory<PropertyType extends LaraProperty<? extends PropertyType,?>>
Parameters:
propertyToRemove - the property to be removed.
Returns:
the property that was forgotten
Throws:
LRemoveException

forget

public PropertyType forget(String key,
                           int step)
                                                                   throws LRemoveException
Description copied from interface: LaraMemory
Removes the property with the specified key that was memorised in step from this memory.

Specified by:
forget in interface LaraMemory<PropertyType extends LaraProperty<? extends PropertyType,?>>
Parameters:
key - identifier for the property to be removed.
step - the step in which the property to be removed was memorised.
Returns:
the property that was forgotten
Throws:
LRemoveException

forgetAll

public Collection<PropertyType> forgetAll(Collection<PropertyType> propertiesToBeRemoved)
                                                                                  throws LRemoveException
Description copied from interface: LaraMemory
Removes all properties in the specified collection from this memory.

Specified by:
forgetAll in interface LaraMemory<PropertyType extends LaraProperty<? extends PropertyType,?>>
Parameters:
propertiesToBeRemoved - the properties to be removed
Returns:
the properties that were forgotten
Throws:
LRemoveException

forgetAll

public Collection<PropertyType> forgetAll(String key)
                                                                                  throws LRemoveException
Description copied from interface: LaraMemory
Removes all properties that are identified by the specified key.

Specified by:
forgetAll in interface LaraMemory<PropertyType extends LaraProperty<? extends PropertyType,?>>
Parameters:
key - key identifier for the properties to be removed.
Returns:
the properties that were forgotten
Throws:
LRemoveException

getAllPropertyKeys

public Set<String> getAllPropertyKeys()
Description copied from interface: LaraMemory
Returns a set of Strings that represent the keys of properties memorised in the memory such that any property in the memory is represented.

Specified by:
getAllPropertyKeys in interface LaraMemory<PropertyType extends LaraProperty<? extends PropertyType,?>>
Returns:
set of keys that represent a property memorised in the memory
See Also:
LaraMemory.getAllPropertyKeys()

getCapacity

public int getCapacity()
Description copied from interface: LaraContainer
Returns the capacity of this container, i.e. the number of items that can be stored or LaraContainer.UNLIMITED_CAPACITY (the default) if it is (virtually) unlimited.

Specified by:
getCapacity in interface LaraContainer<PropertyType extends LaraProperty<? extends PropertyType,?>>
Returns:
the capacity of this storage.

getDefaultRetentionTime

public int getDefaultRetentionTime()
Description copied from interface: LaraMemory
Return the default retention time

Specified by:
getDefaultRetentionTime in interface LaraMemory<PropertyType extends LaraProperty<? extends PropertyType,?>>
Returns:
the default retention time

getName

public String getName()
Description copied from interface: LaraMemory
Returns the name of this memory

Specified by:
getName in interface LaraMemory<PropertyType extends LaraProperty<? extends PropertyType,?>>
Returns:
the memory's name
See Also:
LaraMemory.getName()

getRetentionTime

public int getRetentionTime(PropertyType property)
Description copied from interface: LaraMemory
Returns the remaining retention time for the given property.

Specified by:
getRetentionTime in interface LaraMemory<PropertyType extends LaraProperty<? extends PropertyType,?>>
Returns:
the remaining retention time for the given property.

getSize

public int getSize()
Description copied from interface: LaraContainer
Returns the current size, i.e. the number of items currently stored.

Specified by:
getSize in interface LaraContainer<PropertyType extends LaraProperty<? extends PropertyType,?>>
Returns:
the current size, i.e. the number of items currently stored.

isEmpty

public boolean isEmpty()
Description copied from interface: LaraContainer
Returns true, if and only if this container is empty.

Specified by:
isEmpty in interface LaraContainer<PropertyType extends LaraProperty<? extends PropertyType,?>>
Returns:
true, if and only if this container is empty.0

isFull

public boolean isFull()
Description copied from interface: LaraContainer
Returns true, if and only if this container is full (see also LaraCapacityManager).

Specified by:
isFull in interface LaraContainer<PropertyType extends LaraProperty<? extends PropertyType,?>>
Returns:
true, if and only if this container is full.

iterator

public Iterator<PropertyType> iterator()
Specified by:
iterator in interface Iterable<PropertyType extends LaraProperty<? extends PropertyType,?>>

memorize

public void memorize(PropertyType propertyToMemorize)
              throws LContainerFullException,
                     LInvalidTimestampException
Description copied from interface: LaraMemory
Tries to add the specified property to this memory applying the default retention time. In case the memory already contains a property of the same key for the same time-stamp the "old" property is overwritten.

Specified by:
memorize in interface LaraMemory<PropertyType extends LaraProperty<? extends PropertyType,?>>
Parameters:
propertyToMemorize - the property to be memorised.
Throws:
LContainerFullException
LInvalidTimestampException

memorize

public void memorize(PropertyType propertyToMemorize,
                     int retentionTime)
              throws LContainerFullException,
                     LInvalidTimestampException
Description copied from interface: LaraMemory
Tries to add the specified property to this memory with the given retention time. In case the memory already contains a property of the same key for the same time-stamp the "old" property is overwritten.

Specified by:
memorize in interface LaraMemory<PropertyType extends LaraProperty<? extends PropertyType,?>>
Parameters:
propertyToMemorize - the property to be memorised.
Throws:
LContainerFullException
LInvalidTimestampException

recall

public <RequestPropertyType extends PropertyType> RequestPropertyType recall(Class<RequestPropertyType> propertyType,
                                                                             String key)
                                                throws LRetrieveException
Description copied from interface: LaraMemory
Generic method that returns the most recently memorised property that is of the specified type (including sub types) and identified with key.

Specified by:
recall in interface LaraMemory<PropertyType extends LaraProperty<? extends PropertyType,?>>
key - identifier for the property to be retrieved.
Returns:
the most recently memorised property that is of the specified type and identified with key.
Throws:
LRetrieveException
See Also:
LaraMemory.recall(java.lang.Class, java.lang.String)

recall

public <RequestPropertyType extends PropertyType> RequestPropertyType recall(Class<RequestPropertyType> propertyType,
                                                                             String key,
                                                                             int step)
                                                throws LRetrieveException
Description copied from interface: LaraMemory
Generic method that returns the first property found that is of the specified type (including sub types), was memorised in step and identified with key.

Specified by:
recall in interface LaraMemory<PropertyType extends LaraProperty<? extends PropertyType,?>>
key - identifier for the property to be retrieved.
step - step in which the property was memorised.
Returns:
the property of the specified type that was memorised in step and identified with key.
Throws:
LRetrieveException
See Also:
LaraMemory.recall(java.lang.Class, java.lang.String, int)

recall

public PropertyType recall(String key)
                                                                   throws LRetrieveException
Description copied from interface: LaraMemory
Generic method that returns the most recently memorised property that is identified with key.

Specified by:
recall in interface LaraMemory<PropertyType extends LaraProperty<? extends PropertyType,?>>
Parameters:
key - identifier for the property to be retrieved.
Returns:
the most recently memorised property that is identified with key.
Throws:
LRetrieveException

recall

public PropertyType recall(String key,
                           int step)
                                                                   throws LRetrieveException
Description copied from interface: LaraMemory
Generic method that returns the first property that was memorised in step and identified with key .

Specified by:
recall in interface LaraMemory<PropertyType extends LaraProperty<? extends PropertyType,?>>
Parameters:
key - identifier for the property to be retrieved.
step - step in which the property was memorised.
Returns:
the first property that was memorised in step and identified with key.
Throws:
LRetrieveException

recallAll

public <RequestPropertyType extends PropertyType> Collection<RequestPropertyType> recallAll(Class<RequestPropertyType> propertyType)
                                                               throws LRetrieveException
Description copied from interface: LaraMemory
Generic method that returns a collection of all properties found that are of the specified type (including sub types).

Specified by:
recallAll in interface LaraMemory<PropertyType extends LaraProperty<? extends PropertyType,?>>
Returns:
the properties of the specified type that were memorised in step and identified with key.
Throws:
LRetrieveException
See Also:
LaraMemory.recallAll(java.lang.Class, java.lang.String)

recallAll

public <RequestPropertyType extends PropertyType> Collection<RequestPropertyType> recallAll(Class<RequestPropertyType> propertyType,
                                                                                            String key)
                                                               throws LRetrieveException
Description copied from interface: LaraMemory
Generic method that returns a collection of all properties found that are of the specified type (including sub types)and are identified by key.

Specified by:
recallAll in interface LaraMemory<PropertyType extends LaraProperty<? extends PropertyType,?>>
key - identifier for the properties to be retrieved.
Returns:
the properties of the specified type that were memorised in step and identified with key.
Throws:
LRetrieveException
See Also:
LaraMemory.recallAll(java.lang.Class, java.lang.String)

recallAll

public Collection<PropertyType> recallAll(String key)
                                                                                  throws LRetrieveException
Description copied from interface: LaraMemory
Generic method that returns a collection of all properties found that are identified by key.

Specified by:
recallAll in interface LaraMemory<PropertyType extends LaraProperty<? extends PropertyType,?>>
Parameters:
key - identifier for the properties to be retrieved.
Returns:
the properties of the specified type that were stored in step and identified with key.
Throws:
LRetrieveException

refresh

public void refresh(PropertyType propertyToRefresh)
             throws LContainerFullException,
                    LInvalidTimestampException
Description copied from interface: LaraMemory
Tries to refresh the specified property in this memory applying the default retention time.

Specified by:
refresh in interface LaraMemory<PropertyType extends LaraProperty<? extends PropertyType,?>>
Parameters:
propertyToRefresh - the property to be memorised.
Throws:
LContainerFullException
LInvalidTimestampException

refresh

public void refresh(PropertyType propertyToRefresh,
                    int retentionTime)
             throws LInvalidTimestampException,
                    LRemoveException
Description copied from interface: LaraMemory
Refreshes the property from this memory and assigns the given retention time.

Specified by:
refresh in interface LaraMemory<PropertyType extends LaraProperty<? extends PropertyType,?>>
Parameters:
propertyToRefresh - the property to be memorised.
retentionTime - time the property lasts in memory
Throws:
LInvalidTimestampException
LRemoveException

refresh

public void refresh(String key)
             throws LRemoveException
Description copied from interface: LaraMemory
Refreshes the property with the specified key that was memorised last from this memory.

Specified by:
refresh in interface LaraMemory<PropertyType extends LaraProperty<? extends PropertyType,?>>
Parameters:
key - identifier for the property to be refreshed.
Throws:
LRemoveException
See Also:
(SH)

refresh

public void refresh(String key,
                    int step)
             throws LRemoveException
Description copied from interface: LaraMemory
Refreshes the property with the specified key that was memorised in step from this memory.

Specified by:
refresh in interface LaraMemory<PropertyType extends LaraProperty<? extends PropertyType,?>>
Parameters:
key - identifier for the property to be refreshed.
step - the step in which the property to be removed was memorised.
Throws:
LRemoveException

refresh

public void refresh(String key,
                    int step,
                    int retentionTime)
             throws LInvalidTimestampException,
                    LRemoveException
Description copied from interface: LaraMemory
Refreshes the property with the specified key that was memorised last from this memory and assigns the given retention time.

Specified by:
refresh in interface LaraMemory<PropertyType extends LaraProperty<? extends PropertyType,?>>
retentionTime - time the property lasts in memory
Throws:
LInvalidTimestampException
LRemoveException

removeMemoryPropertyObserver

public void removeMemoryPropertyObserver(LaraMemoryListener.MemoryEvent eventType,
                                         LaraMemoryListener listener)
Specified by:
removeMemoryPropertyObserver in interface LaraMemory<PropertyType extends LaraProperty<? extends PropertyType,?>>
Parameters:
eventType - the category of memory property events the listeners shall be removed from
listener - the listener to be removed
See Also:
LaraMemory.removeMemoryPropertyObserver(de.cesr.lara.components.container.memory.LaraMemoryListener.MemoryEvent, de.cesr.lara.components.container.memory.LaraMemoryListener)

setDefaultRetentionTime

public void setDefaultRetentionTime(int defaultRetentionTime)
Description copied from interface: LaraMemory
Sets the default retention time

Specified by:
setDefaultRetentionTime in interface LaraMemory<PropertyType extends LaraProperty<? extends PropertyType,?>>
Parameters:
defaultRetentionTime - the default retention time

storageEventOccured

public void storageEventOccured(LaraStorageListener.StorageEvent event,
                                LaraProperty<?,?> property)
Specified by:
storageEventOccured in interface LaraStorageListener
Parameters:
event - the type of LaraMemoryListener.MemoryEvent that occurred
property - the property that is affected

toString

public String toString()
Overrides:
toString in class Object
Returns:
the entries of this memory

createBackingStorage

protected LaraStorage<PropertyType> createBackingStorage()
Overwrite this method in order to change the storage to be used by the memory.

Returns: