com.cloudtran.coherence.llapi
Class CTCacheFactory

java.lang.Object
  extended by com.cloudtran.coherence.llapi.CTCacheFactory

public class CTCacheFactory
extends Object

This is the cache factory for the low-level API; it manages the lifecycle of transactional caches.

This class only implements the CloudTran-specific getCache() methods from CacheFactory. It does not override CacheFactory because all the methods are static: if you want to call methods other than those supported by CloudTran, use the standard CacheFactory.

A transactional cache is only valid for the lifetime of the transaction. You should not use it on transactional methods (put, remove, invoke) after the transaction has completed (committed/rolled back). If you are using Spring transactions, this is easy: use a method local variable, and it is guaranteed to go away as the transaction completes. If you are not using Spring transactions, the same approach works, except you have to do the commit/roll back yourself: store the transactional cache in a local variable of a method and do the commit/rollback as the last thing in the method.

The CTCacheFactory class also provides add/removeMapListener methods to make MapListeners participate in transactions. You only need to do this if the MapListener is a MapTriggerListener - these can make changes before an entry is committed and so can be incorporated into a transaction. Non-MapTrigger MapListeners are call after the cache update is completed so cannot be made transactional; CloudTran does not change the action of non-MapTrigger MapListeners.

What happens when the MapTrigger is transactional is that the cache operation - put, remove and invoke - can make transactional changes to an entry and the MapTrigger is then called before the changes are committed. The map listener is passed an Entry wrapper that has the values representing the transactional change that has occurred. The previous value passed is the previous transactional value if there is one, or the committed value is not. The new value passed is the new value as set by the cache operation. As usual, the MapTrigger can change the values to quietly affect the operation, or it can throw an exception, which will be propagated back to the user with out any changes being made.

The MapListener methods are available as static methods, and also on transactional caches created by the getCache() methods. The reasons for providing static methods are

Note that you must create transactional MapTriggerListeners programmatically. It is not possible to create make them transactional via cache-config.xml.

In the current version, CloudTran transactions work on Distributed scheme caches only.


Method Summary
static void addMapListener(NamedCache cache, MapListener listener)
           
static void addMapListener(NamedCache cache, MapListener listener, Filter filter, boolean fLite)
           
static void addMapListener(NamedCache cache, MapListener listener, Object oKey, boolean fLite)
           
static CTNamedCache getCache(NamedCache cohCache)
           
static CTNamedCache getCache(String sName)
          Gets a transactional implementation of NamedCache cache.
static CTNamedCache getCache(String cacheName, ClassLoader loader)
          Gets a cache based on getCache.
static void removeMapListener(NamedCache cache, MapListener listener)
           
static void removeMapListener(NamedCache cache, MapListener listener, Filter filter)
           
static void removeMapListener(NamedCache cache, MapListener listener, Object oKey)
           
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

getCache

public static CTNamedCache getCache(String sName)
                             throws CannotCreateTransactionException
Gets a transactional implementation of NamedCache cache. This method throws an exception if there is no current transaction based on getCache which will be transactional if there is an ongoing CloudTran transaction (in the current thread) or a normal Coherence NamedCache if there is no ongoing CloudTran transaction.

Returns:
a cache linked to the ongoing transaction.
Throws:
CannotCreateTransactionException

getCache

public static CTNamedCache getCache(String cacheName,
                                    ClassLoader loader)
Gets a cache based on getCache.

Parameters:
cacheName -
-
Returns:
a cache linked to the ongoing transaction.

getCache

public static CTNamedCache getCache(NamedCache cohCache)

addMapListener

public static void addMapListener(NamedCache cache,
                                  MapListener listener,
                                  Filter filter,
                                  boolean fLite)

addMapListener

public static void addMapListener(NamedCache cache,
                                  MapListener listener,
                                  Object oKey,
                                  boolean fLite)

addMapListener

public static void addMapListener(NamedCache cache,
                                  MapListener listener)

removeMapListener

public static void removeMapListener(NamedCache cache,
                                     MapListener listener,
                                     Filter filter)

removeMapListener

public static void removeMapListener(NamedCache cache,
                                     MapListener listener,
                                     Object oKey)

removeMapListener

public static void removeMapListener(NamedCache cache,
                                     MapListener listener)