org.apache.tuscany.sca.core.store
Class MemoryStore

java.lang.Object
  extended by org.apache.tuscany.sca.core.event.BaseEventPublisher
      extended by org.apache.tuscany.sca.core.store.MemoryStore
All Implemented Interfaces:
EventPublisher, Store

public class MemoryStore
extends BaseEventPublisher
implements Store

Implements a non-durable, non-transactional store using a simple in-memory map


Field Summary
 
Fields inherited from class org.apache.tuscany.sca.core.event.BaseEventPublisher
listeners, TRUE_FILTER
 
Fields inherited from interface org.apache.tuscany.sca.store.Store
DEFAULT_EXPIRATION_OFFSET, NEVER
 
Constructor Summary
MemoryStore(StoreMonitor monitor)
           
 
Method Summary
 void destroy()
           
 long getDefaultExpirationOffset()
          Returns the maximum default expiration offset for records in the store
 long getReaperInterval()
           
 void init()
           
 void insertRecord(RuntimeComponent owner, java.lang.String id, java.lang.Object object, long expiration)
          Adds the given record to the store.
 java.lang.Object readRecord(RuntimeComponent owner, java.lang.String id)
          Returns the deserialized object in the store corresponding to the given id
 void recover(RecoveryListener listener)
          Initiates a recovery operation, for example during restart after a crash
 void removeRecord(RuntimeComponent owner, java.lang.String id)
          Removes a record from the store
 void removeRecords()
          Removes all records from the store
 void setDefaultExpirationOffset(long defaultExpirationOffset)
          Sets the maximum default expiration offset for records in the store
 void setReaperInterval(long reaperInterval)
          Sets the interval for expired entry scanning to be performed
 void updateRecord(RuntimeComponent owner, java.lang.String id, java.lang.Object object, long expiration)
          Updates a given record in the store, overwriting previous information.
 
Methods inherited from class org.apache.tuscany.sca.core.event.BaseEventPublisher
addListener, addListener, getListeners, publish, removeListener
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.apache.tuscany.sca.event.EventPublisher
addListener, addListener, publish, removeListener
 

Constructor Detail

MemoryStore

public MemoryStore(StoreMonitor monitor)
Method Detail

getDefaultExpirationOffset

public long getDefaultExpirationOffset()
Returns the maximum default expiration offset for records in the store

Returns:
the maximum default expiration offset for records in the store

setDefaultExpirationOffset

public void setDefaultExpirationOffset(long defaultExpirationOffset)
Sets the maximum default expiration offset for records in the store


setReaperInterval

public void setReaperInterval(long reaperInterval)
Sets the interval for expired entry scanning to be performed


getReaperInterval

public long getReaperInterval()

init

public void init()

destroy

public void destroy()

insertRecord

public void insertRecord(RuntimeComponent owner,
                         java.lang.String id,
                         java.lang.Object object,
                         long expiration)
                  throws StoreWriteException
Description copied from interface: Store
Adds the given record to the store. Implementations may choose different strategies for writing data such as write-through or write-behind.

Specified by:
insertRecord in interface Store
Parameters:
owner - the instance owner
id - the unique id of the record
object - the object representing the data to write
expiration - the time in milliseconds when the entry expires
Throws:
StoreWriteException - if an error occurs during the write operation

updateRecord

public void updateRecord(RuntimeComponent owner,
                         java.lang.String id,
                         java.lang.Object object,
                         long expiration)
                  throws StoreWriteException
Description copied from interface: Store
Updates a given record in the store, overwriting previous information.

Specified by:
updateRecord in interface Store
Parameters:
owner - the instance owner
id - the unique id of the record
object - the object representing the data to write
expiration - the time in milliseconds when the entry expires
Throws:
StoreWriteException

readRecord

public java.lang.Object readRecord(RuntimeComponent owner,
                                   java.lang.String id)
Description copied from interface: Store
Returns the deserialized object in the store corresponding to the given id

Specified by:
readRecord in interface Store
Parameters:
owner - the instance owner
id - the unique id of the record
Returns:
the deserialized object or null if one is not found

removeRecords

public void removeRecords()
Description copied from interface: Store
Removes all records from the store

Specified by:
removeRecords in interface Store

removeRecord

public void removeRecord(RuntimeComponent owner,
                         java.lang.String id)
                  throws StoreWriteException
Description copied from interface: Store
Removes a record from the store

Specified by:
removeRecord in interface Store
Parameters:
owner - the instance owner
id - the unique id of the record
Throws:
StoreWriteException

recover

public void recover(RecoveryListener listener)
Description copied from interface: Store
Initiates a recovery operation, for example during restart after a crash

Specified by:
recover in interface Store
Parameters:
listener - the listener to receive recovery callback events