org.jboss.remoting
Class CallbackStore

java.lang.Object
  extended byorg.jboss.remoting.CallbackStore
All Implemented Interfaces:
CallbackStoreMBean, SerializableStore

public class CallbackStore
extends Object
implements CallbackStoreMBean

Acts as a persistent list which writes Serializable objects to disk and will retrieve them in same order in which they were added (FIFO). Each file will be named according to the current time (using System.currentTimeMillis() with the file suffix specified (see below). When the object is read and returned by calling the getNext() method, the file on disk for that object will be deleted. If for some reason the store VM crashes, the objects will still be available upon next startup.

The attributes to make sure to configure are:

file path - this determins which directory to write the objects. The default value is the property value of 'jboss.server.data.dir' and if this is not set, then will be 'data'. For example, might be /jboss/server/default/data.

file suffix - the file suffix to use for the file written for each object stored.

This is also a service mbean, so can be run as a service within JBoss AS or stand alone.

Author:
Tom Elrod

Nested Class Summary
 class CallbackStore.StoreFileFilter
           
 
Field Summary
static String FILE_PATH_KEY
           
static String FILE_SUFFIX_KEY
           
 
Constructor Summary
CallbackStore()
          Default store constructor.
CallbackStore(boolean purgeOnDestroy)
          Store constructor.
 
Method Summary
 void add(Serializable object)
          Persists the serializable object passed to the directory specified.
 void create()
          This is a no op method, but needed in order to be used as a service within JBoss AS.
 void destroy()
          If purgeOnDestroy is true, will remove files upon shutdown.
 Object getNext()
          Will look through the files in the store directory for the oldest object serialized to disk, load it, delete the file, and return the deserialized object.
 boolean getPurgeOnShutdown()
          Returns if store will clean up persisted files when shutdown (destroy()).
 String getStoreFilePath()
          Gets the file path for the directory where the objects will be stored.
 String getStoreFileSuffix()
          Gets the file suffix for each of the files that objects will be persisted to.
 void purgeFiles()
           
 void setConfig(Map config)
          Will use the values in the map to set configuration.
 void setPurgeOnShutdown(boolean purgeOnShutdown)
          Sets if store should clean up persisted files when shutdown (destroy()).
 void setStoreFilePath(String filePath)
          Sets teh file path for the directory where the objects will be stored.
 void setStoreFileSuffix(String fileSuffix)
          Sets the file suffix for each of the files that objects will be persisted to.
 int size()
          Getst the number of objects stored and available.
 void start()
          Will get the file path value (if not already set will just use the default setting) and will create the directory specified by the file path if it does not already exist.
 void stop()
          This will allow for change of file suffix and file path and then may start again using these new values.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

FILE_PATH_KEY

public static final String FILE_PATH_KEY
See Also:
Constant Field Values

FILE_SUFFIX_KEY

public static final String FILE_SUFFIX_KEY
See Also:
Constant Field Values
Constructor Detail

CallbackStore

public CallbackStore()
Default store constructor.


CallbackStore

public CallbackStore(boolean purgeOnDestroy)
Store constructor.

Parameters:
purgeOnDestroy - if true, will remove all persisted objects from disk on when destroy() is called, else will leave the files (which is the default behaviour).
Method Detail

start

public void start()
           throws Exception
Will get the file path value (if not already set will just use the default setting) and will create the directory specified by the file path if it does not already exist.

Specified by:
start in interface SerializableStore
Throws:
Exception

setPurgeOnShutdown

public void setPurgeOnShutdown(boolean purgeOnShutdown)
Sets if store should clean up persisted files when shutdown (destroy()).

Specified by:
setPurgeOnShutdown in interface SerializableStore
Parameters:
purgeOnShutdown -

getPurgeOnShutdown

public boolean getPurgeOnShutdown()
Returns if store will clean up persisted files when shutdown (destroy()).

Specified by:
getPurgeOnShutdown in interface SerializableStore
Returns:

create

public void create()
            throws Exception
This is a no op method, but needed in order to be used as a service within JBoss AS.

Specified by:
create in interface SerializableStore
Throws:
Exception

stop

public void stop()
This will allow for change of file suffix and file path and then may start again using these new values. However, any object already written out using the old values will be lost as will not longer be accessible if these attributes are changed while stopped.

Specified by:
stop in interface SerializableStore

destroy

public void destroy()
If purgeOnDestroy is true, will remove files upon shutdown.

Specified by:
destroy in interface SerializableStore

purgeFiles

public void purgeFiles()
Specified by:
purgeFiles in interface SerializableStore

setConfig

public void setConfig(Map config)
Will use the values in the map to set configuration. This will not change behaviour of store until has been stopped and then started (if has not been started, will take effect upon start). The keys for the map are FILE_PATH_KEY and FILE_SUFFIX_KEY.

Specified by:
setConfig in interface SerializableStore
Parameters:
config -

getStoreFilePath

public String getStoreFilePath()
Gets the file path for the directory where the objects will be stored.

Specified by:
getStoreFilePath in interface CallbackStoreMBean
Returns:

setStoreFilePath

public void setStoreFilePath(String filePath)
Sets teh file path for the directory where the objects will be stored.

Specified by:
setStoreFilePath in interface CallbackStoreMBean
Parameters:
filePath -

getStoreFileSuffix

public String getStoreFileSuffix()
Gets the file suffix for each of the files that objects will be persisted to.

Specified by:
getStoreFileSuffix in interface CallbackStoreMBean
Returns:

setStoreFileSuffix

public void setStoreFileSuffix(String fileSuffix)
Sets the file suffix for each of the files that objects will be persisted to.

Specified by:
setStoreFileSuffix in interface CallbackStoreMBean
Parameters:
fileSuffix -

size

public int size()
Getst the number of objects stored and available.

Specified by:
size in interface SerializableStore
Returns:

getNext

public Object getNext()
               throws IOException
Will look through the files in the store directory for the oldest object serialized to disk, load it, delete the file, and return the deserialized object. Important to note that once this object is returned from this method, it is gone forever from this store and will not be able to retrieve it again without adding it back.

Specified by:
getNext in interface SerializableStore
Returns:
Throws:
IOException

add

public void add(Serializable object)
         throws IOException
Persists the serializable object passed to the directory specified. The file name will be the current time in milliseconds (vis System.currentTimeMillis()) with the specified suffix. This object can later be retrieved using the getNext() method, but objects will be returned in the order that they were added (FIFO).

Specified by:
add in interface SerializableStore
Parameters:
object -
Throws:
IOException


Copyright © 2004 JBoss Inc. All Rights Reserved.