org.glassfish.ha.store.api
Class BackingStore<K extends Serializable,V extends Serializable>

java.lang.Object
  extended by 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 calling BackingStoreFactory.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
BackingStore()
           
 
Method Summary
 void close()
          Typically called during shutdown of the process.
protected  ObjectInputStream createObjectInputStream(InputStream is)
           
protected  ObjectOutputStream createObjectOutputStream(OutputStream os)
           
 void destroy()
          Called when the store is no longer needed.
protected  BackingStoreConfiguration<K,V> getBackingStoreConfiguration()
           
abstract  BackingStoreFactory getBackingStoreFactory()
           
protected  void initialize(BackingStoreConfiguration<K,V> conf)
           
abstract  V load(K key, String version)
          Load and return the data for the given id.
abstract  void remove(K key)
          Remove the association for the id.
 int removeExpired()
          Remove expired entries
 int removeExpired(long idleForMillis)
           
abstract  String save(K key, V value, boolean isNew)
          Save the value whose key is id.
abstract  int size()
          Get the current size of the store
 void updateTimestamp(K key, long time)
          TODO: BEGIN: REMOVE after shoal integration
 String updateTimestamp(K key, String version, Long accessTime)
          Recomended way is to just do a save(k, v)
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

BackingStore

public BackingStore()
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 the save() 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 null
BackingStoreException - 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 id
value - 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 to load(id) must return null. In addition, any association between id and 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 BackingStoreException
Remove expired entries

Throws:
BackingStoreException

size

public abstract int size()
                  throws BackingStoreException
Get 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 BackingStoreException
Typically called during shutdown of the process. The store must not be used after this call

Throws:
BackingStoreException

destroy

public void destroy()
             throws BackingStoreException
Called 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


Copyright © 2005-2015 Oracle Corporation. All Rights Reserved.