Package org.glassfish.ha.store.api
Class BackingStore<K extends Serializable,V extends Serializable>
- java.lang.Object
-
- org.glassfish.ha.store.api.BackingStore<K,V>
-
- Direct Known Subclasses:
NoOpBackingStore
public abstract class BackingStore<K extends Serializable,V extends Serializable> extends Object
An object that stores a given value against an id. This class defines the set of operations that a container could perform on a store. An instance of BackingStore is created by callingBackingStoreFactory.createBackingStore()method. The BackingStore instance is created and used for storing data that belongs to a single application or container. The store implementation must be thread safe.- Author:
- Mahesh.Kannan@Sun.Com, Larry.White@Sun.Com
-
-
Constructor Summary
Constructors Constructor Description BackingStore()
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description voidclose()Typically called during shutdown of the process.protected ObjectInputStreamcreateObjectInputStream(InputStream is)protected ObjectOutputStreamcreateObjectOutputStream(OutputStream os)voiddestroy()Called when the store is no longer needed.protected BackingStoreConfiguration<K,V>getBackingStoreConfiguration()abstract BackingStoreFactorygetBackingStoreFactory()protected voidinitialize(BackingStoreConfiguration<K,V> conf)abstract Vload(K key, String version)Load and return the data for the given id.abstract voidremove(K key)Remove the association for the id.intremoveExpired()Remove expired entriesintremoveExpired(long idleForMillis)abstract Stringsave(K key, V value, boolean isNew)Save the value whose key is id.abstract intsize()Get the current size of the storevoidupdateTimestamp(K key, long time)TODO: BEGIN: REMOVE after shoal integrationStringupdateTimestamp(K key, String version, Long accessTime)Recomended way is to just do a save(k, v)
-
-
-
Method Detail
-
initialize
protected void initialize(BackingStoreConfiguration<K,V> conf) throws BackingStoreException
- Throws:
BackingStoreException
-
getBackingStoreConfiguration
protected BackingStoreConfiguration<K,V> getBackingStoreConfiguration()
-
getBackingStoreFactory
public abstract BackingStoreFactory getBackingStoreFactory()
-
load
public abstract V load(K key, String version) throws BackingStoreException
Load and return the data for the given id. The store is expected to return the largest ever version that was saved in the stored using thesave()method.- Parameters:
key- the key whose value must be returned- Returns:
- the value if this store contains it or null. The implementation must return the exact same type as that was passed to it in the save method.
- Throws:
NullPointerException- if the id is nullBackingStoreException- if the underlying store implementation encounters any exception
-
save
public abstract String save(K key, V value, boolean isNew) throws BackingStoreException
Save the value whose key is id. The store is NOT expected to throw an exception if isNew is false but the entry doesn't exist in the store. (This is possible in some implementations (like in-memory) where packets could be lost.)- Parameters:
key- the idvalue- The Metadata to be stored- Returns:
- A (possibly null) String indicating the instance name where the data was saved.
- Throws:
BackingStoreException- if the underlying store implementation encounters any exception
-
remove
public abstract void remove(K key) throws BackingStoreException
Remove the association for the id. After this call, any call toload(id)must return null. In addition, any association betweenidand container extra params must also be removed.- Parameters:
key- the id of the Metadata- Throws:
BackingStoreException- if the underlying store implementation encounters any exception
-
updateTimestamp
public void updateTimestamp(K key, long time) throws BackingStoreException
TODO: BEGIN: REMOVE after shoal integration- Throws:
BackingStoreException
-
removeExpired
public int removeExpired(long idleForMillis) throws BackingStoreException- Throws:
BackingStoreException
-
updateTimestamp
public String updateTimestamp(K key, String version, Long accessTime) throws BackingStoreException
Recomended way is to just do a save(k, v)- Parameters:
key-version-accessTime-- Throws:
BackingStoreException
-
removeExpired
public int removeExpired() throws BackingStoreExceptionRemove expired entries- Throws:
BackingStoreException
-
size
public abstract int size() throws BackingStoreExceptionGet the current size of the store- Returns:
- the (approximate) number of entries in the store
- Throws:
BackingStoreException- if the underlying store implementation encounters any exception
-
close
public void close() throws BackingStoreExceptionTypically called during shutdown of the process. The store must not be used after this call- Throws:
BackingStoreException
-
destroy
public void destroy() throws BackingStoreExceptionCalled when the store is no longer needed. Must clean up and close any opened resources. The store must not be used after this call.- Throws:
BackingStoreException
-
createObjectOutputStream
protected ObjectOutputStream createObjectOutputStream(OutputStream os) throws IOException
- Throws:
IOException
-
createObjectInputStream
protected ObjectInputStream createObjectInputStream(InputStream is) throws IOException
- Throws:
IOException
-
-