org.mule.util.store
Class MonitoredObjectStoreWrapper<T extends Serializable>

java.lang.Object
  extended by org.mule.util.store.MonitoredObjectStoreWrapper<T>
All Implemented Interfaces:
Runnable, MuleContextAware, Disposable, Initialisable, ListableObjectStore<T>, ObjectStore<T>

public class MonitoredObjectStoreWrapper<T extends Serializable>
extends Object
implements ListableObjectStore<T>, Runnable, MuleContextAware, Initialisable, Disposable

The MonitoredObjectStoreWrapper wraps an ObjectStore which does not support direct expiry and adds this behavior


Nested Class Summary
protected static class MonitoredObjectStoreWrapper.StoredObject<T>
           
 
Field Summary
protected  MuleContext context
           
protected  int entryTTL
          The time-to-live for each message ID, specified in milliseconds, or -1 for entries that should never expire.
protected  int expirationInterval
          The interval for periodic bounded size enforcement and entry expiration, specified in milliseconds.
protected  int maxEntries
          the maximum number of entries that this store keeps around.
protected  String name
          A name for this store, can be used for logging and identification purposes.
protected  ScheduledThreadPoolExecutor scheduler
           
 
Fields inherited from interface org.mule.api.lifecycle.Initialisable
PHASE_NAME
 
Fields inherited from interface org.mule.api.lifecycle.Disposable
PHASE_NAME
 
Constructor Summary
MonitoredObjectStoreWrapper(ListableObjectStore<MonitoredObjectStoreWrapper.StoredObject<T>> baseStore)
           
MonitoredObjectStoreWrapper(ListableObjectStore<MonitoredObjectStoreWrapper.StoredObject<T>> baseStore, int maxEntries, int entryTTL, int expirationInterval)
           
 
Method Summary
 List<Serializable> allKeys()
           
 void clear()
          Removes all items of this store without disposing it, meaning that after performing a clear(), you should still be able perform other operations.
 void close()
          Close the underlying store.
 boolean contains(Serializable key)
          Check whether the given Object is already registered with this store.
 void dispose()
          A lifecycle method where implementor should free up any resources.
 void expire()
           
 void initialise()
          Method used to perform any initialisation work.
 boolean isPersistent()
          Is this store persistent?
 void open()
          Open the underlying store.
 T remove(Serializable key)
          Remove the object with key.
 T retrieve(Serializable key)
          Retrieve the given Object.
 void run()
           
 void setMuleContext(MuleContext context)
           
 void store(Serializable key, T value)
          Store the given Object.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

context

protected MuleContext context

scheduler

protected ScheduledThreadPoolExecutor scheduler

maxEntries

protected int maxEntries
the maximum number of entries that this store keeps around. Specify -1 if the store is supposed to be "unbounded".


entryTTL

protected int entryTTL
The time-to-live for each message ID, specified in milliseconds, or -1 for entries that should never expire. DO NOT combine this with an unbounded store!


expirationInterval

protected int expirationInterval
The interval for periodic bounded size enforcement and entry expiration, specified in milliseconds. Arbitrary positive values between 1 millisecond and several hours or days are possible, but should be chosen carefully according to the expected message rate to prevent out of memory conditions.


name

protected String name
A name for this store, can be used for logging and identification purposes.

Constructor Detail

MonitoredObjectStoreWrapper

public MonitoredObjectStoreWrapper(ListableObjectStore<MonitoredObjectStoreWrapper.StoredObject<T>> baseStore)

MonitoredObjectStoreWrapper

public MonitoredObjectStoreWrapper(ListableObjectStore<MonitoredObjectStoreWrapper.StoredObject<T>> baseStore,
                                   int maxEntries,
                                   int entryTTL,
                                   int expirationInterval)
Method Detail

contains

public boolean contains(Serializable key)
                 throws ObjectStoreException
Description copied from interface: ObjectStore
Check whether the given Object is already registered with this store.

Specified by:
contains in interface ObjectStore<T extends Serializable>
Parameters:
key - the identifier of the object to check
Returns:
true if the key is stored or false no value was stored for the key.
Throws:
ObjectStoreException - if the given key is null.
ObjectStoreNotAvaliableException - if any implementation-specific error occured, e.g. when the store is not available

store

public void store(Serializable key,
                  T value)
           throws ObjectStoreException
Description copied from interface: ObjectStore
Store the given Object.

Specified by:
store in interface ObjectStore<T extends Serializable>
Parameters:
key - the identifier for value
value - the Object to store with key
Throws:
ObjectStoreException - if the given key cannot be stored or is null.
ObjectStoreNotAvaliableException - if the store is not available or any other implementation-specific error occured.
ObjectAlreadyExistsException - if an attempt is made to store an object for a key that already has an object associated.

retrieve

public T retrieve(Serializable key)
                                throws ObjectStoreException
Description copied from interface: ObjectStore
Retrieve the given Object.

Specified by:
retrieve in interface ObjectStore<T extends Serializable>
Parameters:
key - the identifier of the object to retrieve.
Returns:
the object associated with the given key. If no object for the given key was found this method throws an ObjectDoesNotExistException.
Throws:
ObjectStoreException - if the given key is null.
ObjectStoreNotAvaliableException - if the store is not available or any other implementation-specific error occured.
ObjectDoesNotExistException - if no value for the given key was previously stored.

clear

public void clear()
           throws ObjectStoreException
Description copied from interface: ObjectStore
Removes all items of this store without disposing it, meaning that after performing a clear(), you should still be able perform other operations. Implementations of this method have to remove all items in the fastest way possible. No assumptions should be made regarding thread safeness. If the store implementation is thread-safe, then this method should also be. If the implementation does not guarantee thread-safeness, then you shouldn't expect that from this method either.

Specified by:
clear in interface ObjectStore<T extends Serializable>
Throws:
ObjectStoreException - if the operation fails

remove

public T remove(Serializable key)
                              throws ObjectStoreException
Description copied from interface: ObjectStore
Remove the object with key.

Specified by:
remove in interface ObjectStore<T extends Serializable>
Parameters:
key - the identifier of the object to remove.
Returns:
the object that was previously stored for the given key
Throws:
ObjectStoreException - if the given key is null or if the store is not available or any other implementation-specific error occured
ObjectDoesNotExistException - if no value for the given key was previously stored.

isPersistent

public boolean isPersistent()
Description copied from interface: ObjectStore
Is this store persistent?

Specified by:
isPersistent in interface ObjectStore<T extends Serializable>
Returns:
true if this store is persistent

open

public void open()
          throws ObjectStoreException
Description copied from interface: ListableObjectStore
Open the underlying store.

Specified by:
open in interface ListableObjectStore<T extends Serializable>
Throws:
ObjectStoreException - if an exception occurred while opening the underlying store.

close

public void close()
           throws ObjectStoreException
Description copied from interface: ListableObjectStore
Close the underlying store.

Specified by:
close in interface ListableObjectStore<T extends Serializable>
Throws:
ObjectStoreException - if an exception occurred while closing the underlying store.

allKeys

public List<Serializable> allKeys()
                           throws ObjectStoreException
Specified by:
allKeys in interface ListableObjectStore<T extends Serializable>
Returns:
list containing all keys that this object store currently holds values for.
Throws:
ObjectStoreException - if an exception occurred while collecting the list of all keys.

setMuleContext

public void setMuleContext(MuleContext context)
Specified by:
setMuleContext in interface MuleContextAware

run

public void run()
Specified by:
run in interface Runnable

expire

public void expire()

dispose

public void dispose()
Description copied from interface: Disposable
A lifecycle method where implementor should free up any resources. If an exception is thrown it should just be logged and processing should continue. This method should not throw Runtime exceptions.

Specified by:
dispose in interface Disposable

initialise

public void initialise()
                throws InitialisationException
Description copied from interface: Initialisable
Method used to perform any initialisation work. If a fatal error occurs during initialisation an InitialisationException should be thrown, causing the Mule instance to shutdown. If the error is recoverable, say by retrying to connect, a RecoverableException should be thrown. There is no guarantee that by throwing a Recoverable exception that the Mule instance will not shut down.

Specified by:
initialise in interface Initialisable
Throws:
InitialisationException - if a fatal error occurs causing the Mule instance to shutdown
RecoverableException - if an error occurs that can be recovered from


Copyright © 2003-2014 MuleSoft, Inc.. All Rights Reserved.