equip.data
Class MemoryDataStore

java.lang.Object
  extended byequip.data.MemoryDataStore
All Implemented Interfaces:
IDataStore
Direct Known Subclasses:
FileBackedMemoryDataStore

public class MemoryDataStore
extends java.lang.Object
implements IDataStore

Core implementation of IDataStore interface which can hold any data items in memory (only). Factors out state maintainance code previously included in DataDelegate before the introduction of the DataStore internal interface.

Author:
Chris Greenhalgh, 2003-10-27

Nested Class Summary
(package private) static class MemoryDataStore.LeasedItem
           
 
Field Summary
protected  java.util.Hashtable idMap
           
protected  java.util.Vector leasedItems
           
protected  java.util.Hashtable parentMultimap
           
 
Constructor Summary
MemoryDataStore()
          default constructor.
 
Method Summary
 boolean checkAdd(AddEvent add)
          check if store would like to/be prepared to handle this AddEvent.
 void flush()
          Flush any pending persistent records
 java.util.Enumeration getCandidateItemBindings(ItemData[] itemTemplates)
          get the ItemBinding maintained by this store which should be considered when pattern matching the associated itemTemplates for an add/delete while present pattern.
 java.util.Enumeration getExpiredGUIDs(Time now)
          returns GUIDs of all leased items expiring at or before time 'now'.
 Time getFirstExpireTime()
          returns lowest (soonest, or furthest in past) expire time of any leased item in this store.
 ItemBinding getItemBinding(GUID id)
          get the ItemBinding for the given id iff it is maintained by this store, else null.
 java.util.Enumeration getRemoveResponsibleGUIDs(RemoveResponsible remove)
          get GUIDs of data items in this store which are process bound to the given responsible ID as per the RemoveResponsible event (or not, according to inverse flag).
 boolean handleAdd(AddEvent add)
          request that store handle the Add event, adding to itself accordingly.
 boolean handleDelete(DeleteEvent del)
          request that store handles the given delete, which it must iff it is currently maintaining state for the corresponding data item.
 boolean handleUpdate(UpdateEvent update)
          request that store handles the given update, which it must iff it is currently maintaining state for it.
 boolean holdsGUID(GUID id)
          check if store is maintaining state for the given GUID.
(package private)  void removeParent(ItemBinding binding)
           
 void terminate()
          terminate - tidy up.
 void truncateExpireTimes(GUID responsible, Time expire)
          reduce lease on all leased items with given responsible id to expire at 'expire time'.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

idMap

protected java.util.Hashtable idMap

parentMultimap

protected java.util.Hashtable parentMultimap

leasedItems

protected java.util.Vector leasedItems
Constructor Detail

MemoryDataStore

public MemoryDataStore()
default constructor.

Method Detail

removeParent

void removeParent(ItemBinding binding)

handleAdd

public boolean handleAdd(AddEvent add)
request that store handle the Add event, adding to itself accordingly. Note: also has to handle lease updates.

Specified by:
handleAdd in interface IDataStore
Parameters:
add - The AddEvent to be handled.
Returns:
true iff this store has handled the add event; false if declined. (normally as indicated by a call to IDataStore.checkAdd

checkAdd

public boolean checkAdd(AddEvent add)
check if store would like to/be prepared to handle this AddEvent.

Specified by:
checkAdd in interface IDataStore
Parameters:
add - The AddEvent to be handled.
Returns:
true iff this store would be happy/able to handle it.

holdsGUID

public boolean holdsGUID(GUID id)
check if store is maintaining state for the given GUID.

Specified by:
holdsGUID in interface IDataStore
Parameters:
id - The GUID of the data item in question.
Returns:
true iff the store currently has state for this item.

handleUpdate

public boolean handleUpdate(UpdateEvent update)
request that store handles the given update, which it must iff it is currently maintaining state for it. Note: implies currently no migration of item state between store(s).

Specified by:
handleUpdate in interface IDataStore
Parameters:
update - the UpdateEvent to be handled.
Returns:
true iff the update has been handled (and necessarily the item's state is maintained by this store).

handleDelete

public boolean handleDelete(DeleteEvent del)
request that store handles the given delete, which it must iff it is currently maintaining state for the corresponding data item.

Specified by:
handleDelete in interface IDataStore
Returns:
true iff the delete has been handled (and necessarily the item's state was maintained by this store).

getRemoveResponsibleGUIDs

public java.util.Enumeration getRemoveResponsibleGUIDs(RemoveResponsible remove)
get GUIDs of data items in this store which are process bound to the given responsible ID as per the RemoveResponsible event (or not, according to inverse flag).

Specified by:
getRemoveResponsibleGUIDs in interface IDataStore
Parameters:
remove - the RemoveResponsible event.
Returns:
an Enumeration of the GUIDs of locally maintained data items that should now be deleted.

getItemBinding

public ItemBinding getItemBinding(GUID id)
get the ItemBinding for the given id iff it is maintained by this store, else null.

Specified by:
getItemBinding in interface IDataStore
Parameters:
id - the id of the data item being requested.
Returns:
the ItemBinding for that item, else null iff unknown to this store.

getCandidateItemBindings

public java.util.Enumeration getCandidateItemBindings(ItemData[] itemTemplates)
get the ItemBinding maintained by this store which should be considered when pattern matching the associated itemTemplates for an add/delete while present pattern.

Specified by:
getCandidateItemBindings in interface IDataStore
Parameters:
itemTemplates - array of template data items, else null or zero length list for a wild-card (any item).
Returns:
Enumeration of ItemBindings that should be considered (guaranteed to be a superset of possible matches).

getFirstExpireTime

public Time getFirstExpireTime()
returns lowest (soonest, or furthest in past) expire time of any leased item in this store.

Specified by:
getFirstExpireTime in interface IDataStore
Returns:
lowest (soonest, or furthest in past) expire time, else null.

getExpiredGUIDs

public java.util.Enumeration getExpiredGUIDs(Time now)
returns GUIDs of all leased items expiring at or before time 'now'.

Specified by:
getExpiredGUIDs in interface IDataStore
Parameters:
now - The current time of the expiration clock.
Returns:
Enumeration of GUIDs of now expiring data items which the call might now reasonably issue delete events for).

truncateExpireTimes

public void truncateExpireTimes(GUID responsible,
                                Time expire)
reduce lease on all leased items with given responsible id to expire at 'expire time'.

Specified by:
truncateExpireTimes in interface IDataStore
Parameters:
responsible - required item responsible id
expire - the new expire time for matched items
Returns:
none.

terminate

public void terminate()
terminate - tidy up.

Specified by:
terminate in interface IDataStore

flush

public void flush()
Flush any pending persistent records

Specified by:
flush in interface IDataStore