org.jboss.cache.aop
Class TreeCacheAop

java.lang.Object
  extended byorg.jboss.mx.util.JBossNotificationBroadcasterSupport (src) 
      extended byorg.jboss.system.ServiceMBeanSupport (src) 
          extended byorg.jboss.cache.TreeCache (src) 
              extended byorg.jboss.cache.aop.TreeCacheAop
All Implemented Interfaces:
java.lang.Cloneable, MBeanRegistration (src) , NotificationBroadcaster (src) , NotificationEmitter (src) , Service (src) , ServiceMBean (src)

public class TreeCacheAop
extends TreeCache (src)

Implementation of the cache using dyanmic aop interceptors. The basic idea is that the caller only uses the putObject(String,Object), getObject(String) and removeObject(String) methods.
When putting an object into the cache, the cache essentially takes care of how the object will be replicated. It 'breaks' the object apart to map it onto the tree, and adds an interceptor recursively for each object reachable from the root object. Those interceptor 'know' to which part of the tree they are mapped. Whenever there is state change ("set*" interceptors), the tree is modified using the superclass. All "get*" operations to the object are intercepted and redirected to the tree.
Bottom line is that a user simply puts any object into the cache, and the object will be replicated to all caches in the cluster. The only requirement on cachable objects is that they access all state through getters and setters.


Field Summary
protected  java.util.Map cachedTypes
           
static java.lang.String CLASS_INTERNAL
           
static java.lang.String DUMMY
           
static Fqn (src) JBOSS_INTERNAL
           
 
Fields inherited from class org.jboss.cache.TreeCache (src)
addChildMethodLocal, cache_loader, cache_loader_class, cache_loader_config, cache_loader_fetch_persistent_state, cache_loader_fetch_transient_state, cache_loader_preload, cache_loader_shared, cache_mode, channel, cluster_name, cluster_props, commitMethod, coordinator, deadlockDetection, disp, evictConfig_, eviction_policy_class, eviction_policy_provider, evictNodeMethodLocal, fetch_state_on_startup, getChildrenNamesMethodLocal, getKeysMethodLocal, getKeyValueMethodLocal, getNodeMethodLocal, interceptor_chain, isolationLevel, isStateSet, listeners, LOCAL, lock_acquisition_timeout, lockMethodLocal, members, ml, prepareMethod, printMethodLocal, putDataEraseMethodLocal, putDataMethodLocal, putFailFastKeyValueMethodLocal, putKeyValMethodLocal, releaseAllLocksMethodLocal, removeDataMethodLocal, removeKeyMethodLocal, removeNodeMethodLocal, REPL_ASYNC, repl_queue, repl_queue_interval, repl_queue_max_elements, REPL_SYNC, replicateAllMethod, replicateMethod, replication_handler, rollbackMethod, root, SEPARATOR, state_fetch_timeout, sync_commit_phase, sync_repl_timeout, sync_rollback_phase, tm, tm_lookup, tm_lookup_class, UNINITIALIZED, use_repl_queue
 
Fields inherited from class org.jboss.system.ServiceMBeanSupport (src)
log, server, SERVICE_CONTROLLER_SIG, serviceName
 
Fields inherited from interface org.jboss.system.ServiceMBean (src)
CREATE_EVENT, CREATED, DESTROY_EVENT, DESTROYED, FAILED, REGISTERED, START_EVENT, STARTED, STARTING, states, STOP_EVENT, STOPPED, STOPPING, UNREGISTERED
 
Constructor Summary
TreeCacheAop()
           
TreeCacheAop(JChannel channel)
           
TreeCacheAop(java.lang.String cluster_name, java.lang.String props, long state_fetch_timeout)
           
 
Method Summary
 java.lang.Object _put(GlobalTransaction (src)  tx, Fqn (src)  fqn, java.lang.Object key, java.lang.Object value, boolean create_undo_ops)
          Override the base class to provide some aop specific behaviors.
 java.lang.Object _putObject(Fqn (src)  fqn, java.lang.Object obj)
           
protected  java.lang.Object _removeObject(Fqn (src)  fqn, boolean removeCacheInterceptor)
           
protected  Fqn (src) checkCircularReference(Fqn (src)  fqn, InstanceAdvisor advisor, java.lang.Object obj)
           
protected  void checkObjectType(java.lang.Object obj)
          Check whether the object type is valid.
protected  Fqn (src) createInternalNode(Fqn (src)  storedFqn)
           
protected  void endTransaction()
           
 void evict(Fqn (src)  fqn)
          Override to provide aop specific eviction.
protected  Interceptor findCacheInterceptor(InstanceAdvisor advisor)
          Find existing cache interceptor.
protected  Interceptor findCacheInterceptor(InstanceAdvisor advisor, Fqn (src)  fqn)
          Find cache interceptor with exact fqn.
 CachedType (src) getCachedType(java.lang.Class clazz)
          Obtain a cache aop type for user to traverse the defined "primitive" types in aop.
 java.lang.Object getObject(Fqn (src)  fqn)
          Retrieve the aop-enabled object from the cache.
 java.lang.Object getObject(java.lang.String fqn)
          Retrieve the aop-enabled object from the cache.
protected  Fqn (src) handleObjectGraph(Fqn (src)  fqn, InstanceAdvisor advisor, CachedType (src)  type, java.lang.Object obj)
          Handle cases where there is circular, e.g., parent refers to child and child to parent, or multiple references, e.g., two objects reference the same sub-object.
protected  boolean hasCurrentTransaction()
           
 java.lang.Object putObject(Fqn (src)  fqn, java.lang.Object obj)
          Insert an aop-enabled object into the cache.
 java.lang.Object putObject(java.lang.String fqn, java.lang.Object obj)
          Insert an aop-enabled object into the cache.
 java.lang.Object removeObject(Fqn (src)  fqn)
          Remove aop-enabled object from the cache.
 java.lang.Object removeObject(java.lang.String fqn)
          Remove aop-enabled object from the cache.
 void setEvictionPolicyClass(java.lang.String eviction_policy_class)
          Over-ride to make sure we are using an eviction policy specific to aop.
 
Methods inherited from class org.jboss.cache.TreeCache (src)
_addChild, _evict, _get, _get, _getChildrenNames, _getKeys, _lock, _print, _put, _put, _put, _put, _put, _releaseAllLocks, _remove, _remove, _remove, _remove, _remove, _remove, _remove, _removeData, _removeData, _removeData, _removeData, _replicate, addNode, addTreeCacheListener, block, cacheLoaderPreload, callRemoteMethods, callRemoteMethods, callRemoteMethods, commit, createCacheLoader, createInterceptorChain, createService, destroyService, determineCoordinator, dumpTransactionTable, exists, exists, exists, exists, fetchState, fetchStateOnStartup, get, get, get, get, get, getCacheLoader, getCacheLoaderClass, getCacheLoaderConfig, getCacheLoaderFetchPersistentState, getCacheLoaderFetchTransientState, getCacheLoaderPreload, getCacheLoaderShared, getCacheMode, getCacheModeInternal, getChildrenNames, getChildrenNames, getClusterName, getClusterProperties, getCoordinator, getCurrentTransaction, getCurrentTransaction, getDeadlockDetection, getDefaultProperties, getEvictionPolicyClass, getEvictionPolicyConfig, getEvictionThreadWakeupIntervalSeconds, getFetchStateOnStartup, getInitialStateRetrievalTimeout, getInstance, getInterceptorChain, getInterceptors, getIsolationLevel, getIsolationLevelClass, getKeys, getKeys, getLocalAddress, getLocalTransaction, getLockAcquisitionTimeout, getLockTable, getMembers, getMessageListener, getNumberOfAttributes, getNumberOfLocksHeld, getNumberOfNodes, getReplicationHandler, getReplQueue, getReplQueueInterval, getReplQueueMaxElements, getRoot, getStateBytes, getSyncCommitPhase, getSyncReplTimeout, getSyncRollbackPhase, getTransactionManager, getTransactionManagerLookupClass, getTransactionTable, getUseReplQueue, hasChild, invokeMethod, isCoordinator, isCrudMethod, load, notifyAllNodesCreated, notifyCacheStarted, notifyCacheStopped, notifyNodeCreated, notifyNodeEvicted, notifyNodeLoaded, notifyNodeModified, notifyNodeRemoved, notifyNodeVisisted, notifyViewChange, peek, prepare, print, print, printDetails, printLockInfo, put, put, put, put, putFailFast, putFailFast, releaseAllLocks, releaseAllLocks, remove, remove, remove, remove, removeData, removeData, removeTreeCacheListener, rollback, setCacheLoader, setCacheLoaderClass, setCacheLoaderConfig, setCacheLoaderFetchPersistentState, setCacheLoaderFetchTransientState, setCacheLoaderPreload, setCacheLoaderShared, setCacheMode, setCacheMode, setClusterConfig, setClusterName, setClusterProperties, setDeadlockDetection, setEvictionPolicyConfig, setFetchStateOnStartup, setInitialStateRetrievalTimeout, setIsolationLevel, setIsolationLevel, setLockAcquisitionTimeout, setReplicationHandler, setReplQueueInterval, setReplQueueMaxElements, setStateBytes, setSyncCommitPhase, setSyncReplTimeout, setSyncRollbackPhase, setTransactionManagerLookup, setTransactionManagerLookupClass, setUseReplQueue, startService, stopService, string2Mode, suspect, toString, toString, viewAccepted
 
Methods inherited from class org.jboss.system.ServiceMBeanSupport (src)
create, destroy, getLog, getName, getNextNotificationSequenceNumber, getObjectName, getServer, getServiceName, getState, getStateString, jbossInternalCreate, jbossInternalDescription, jbossInternalDestroy, jbossInternalLifecycle, jbossInternalStart, jbossInternalStop, postDeregister, postRegister, preDeregister, preRegister, start, stop
 
Methods inherited from class org.jboss.mx.util.JBossNotificationBroadcasterSupport (src)
addNotificationListener, getNotificationInfo, handleNotification, removeNotificationListener, removeNotificationListener, sendNotification
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

cachedTypes

protected java.util.Map cachedTypes

CLASS_INTERNAL

public static final java.lang.String CLASS_INTERNAL
See Also:
Constant Field Values (src)

JBOSS_INTERNAL

public static final Fqn (src)  JBOSS_INTERNAL

DUMMY

public static final java.lang.String DUMMY
See Also:
Constant Field Values (src)
Constructor Detail

TreeCacheAop

public TreeCacheAop(java.lang.String cluster_name,
                    java.lang.String props,
                    long state_fetch_timeout)
             throws java.lang.Exception

TreeCacheAop

public TreeCacheAop()
             throws java.lang.Exception

TreeCacheAop

public TreeCacheAop(JChannel channel)
             throws java.lang.Exception
Method Detail

setEvictionPolicyClass

public void setEvictionPolicyClass(java.lang.String eviction_policy_class)
Over-ride to make sure we are using an eviction policy specific to aop.

Overrides:
setEvictionPolicyClass in class TreeCache (src)

putObject

public java.lang.Object putObject(java.lang.String fqn,
                                  java.lang.Object obj)
                           throws CacheException (src) 
Insert an aop-enabled object into the cache. It will also recursively put the any sub-object that is declared as aop-capable (i.e., in jboss-aop.xml). Note that List, Map, Set attributes are aop-enabled, by default, as well.

Parameters:
fqn - The fqn string name to associate with the object in the cache.
obj - aop-enabled object to be inerted into the cache. If null, it will nullify the fqn node.
Throws:
CacheException (src)

putObject

public java.lang.Object putObject(Fqn (src)  fqn,
                                  java.lang.Object obj)
                           throws CacheException (src) 
Insert an aop-enabled object into the cache. It will also recursively put the any sub-object that is declared as aop-capable (i.e., in jboss-aop.xml). Note that List, Map, Set attributes are aop-enabled, by default, as well.

Parameters:
fqn - The fqn instance to associate with the object in the cache.
obj - aop-enabled object to be inerted into the cache. If null, it will nullify the fqn node.
Throws:
CacheException (src)

endTransaction

protected void endTransaction()

_putObject

public java.lang.Object _putObject(Fqn (src)  fqn,
                                   java.lang.Object obj)
                            throws CacheException (src) 
Parameters:
fqn -
obj -
Returns:
Throws:
CacheException (src)

checkObjectType

protected void checkObjectType(java.lang.Object obj)
Check whether the object type is valid. An object type is valid if it is either: aspectized, Serializable, or primitive type. Otherwise a runtime exception is thrown.

Parameters:
obj -

checkCircularReference

protected Fqn (src)  checkCircularReference(Fqn (src)  fqn,
                                     InstanceAdvisor advisor,
                                     java.lang.Object obj)

handleObjectGraph

protected Fqn (src)  handleObjectGraph(Fqn (src)  fqn,
                                InstanceAdvisor advisor,
                                CachedType (src)  type,
                                java.lang.Object obj)
                         throws CacheException (src) 
Handle cases where there is circular, e.g., parent refers to child and child to parent, or multiple references, e.g., two objects reference the same sub-object. In this case, we will remove the current sub-object and substitue with a ref. The reference will point to an Jboss internal node where the sub-object is re-created and stored. It will also have reference counting to keep track of garbage collection.

Parameters:
fqn - Current fqn to store this sub-object
advisor - The associated Advisor instance
Returns:
The fqn that refers to the sub-object stored in JBoss internal node.
Throws:
CacheException (src)

findCacheInterceptor

protected Interceptor findCacheInterceptor(InstanceAdvisor advisor,
                                           Fqn (src)  fqn)
Find cache interceptor with exact fqn.

Parameters:
advisor -
fqn -
Returns:

findCacheInterceptor

protected Interceptor findCacheInterceptor(InstanceAdvisor advisor)
Find existing cache interceptor. Since there is supposedly only one cache interceptor per pojo, this call should suffice. In addition, in cases of cross or circular reference, fqn can be different anyway.

Parameters:
advisor -
Returns:

createInternalNode

protected Fqn (src)  createInternalNode(Fqn (src)  storedFqn)

getObject

public java.lang.Object getObject(java.lang.String fqn)
                           throws CacheException (src) 
Retrieve the aop-enabled object from the cache.

Parameters:
fqn - String name that associates with this node.
Returns:
Current content value. Null if does not exist.
Throws:
CacheException (src)

hasCurrentTransaction

protected boolean hasCurrentTransaction()

getObject

public java.lang.Object getObject(Fqn (src)  fqn)
                           throws CacheException (src) 
Retrieve the aop-enabled object from the cache. Return null if object does not exist in the cache.

Parameters:
fqn - Instance that associates with this node.
Returns:
Current content value. Null if does not exist.
Throws:
CacheException (src)

removeObject

public java.lang.Object removeObject(java.lang.String fqn)
                              throws CacheException (src) 
Remove aop-enabled object from the cache.

Parameters:
fqn - String name that associates with this node.
Returns:
Value object from this node.
Throws:
CacheException (src)

removeObject

public java.lang.Object removeObject(Fqn (src)  fqn)
                              throws CacheException (src) 
Remove aop-enabled object from the cache.

Parameters:
fqn - Instance that associates with this node.
Returns:
Original value object from this node.
Throws:
CacheException (src)

_removeObject

protected java.lang.Object _removeObject(Fqn (src)  fqn,
                                         boolean removeCacheInterceptor)
                                  throws CacheException (src) 
Throws:
CacheException (src)

getCachedType

public CachedType (src)  getCachedType(java.lang.Class clazz)
Obtain a cache aop type for user to traverse the defined "primitive" types in aop.

Parameters:
clazz - The original pojo class
Returns:
CachedType

_put

public java.lang.Object _put(GlobalTransaction (src)  tx,
                             Fqn (src)  fqn,
                             java.lang.Object key,
                             java.lang.Object value,
                             boolean create_undo_ops)
                      throws CacheException (src) 
Override the base class to provide some aop specific behaviors.

Overrides:
_put in class TreeCache (src)
Parameters:
fqn -
key -
value -
Returns:
Previous value (if any)
Throws:
CacheException (src)

evict

public void evict(Fqn (src)  fqn)
           throws CacheException (src) 
Override to provide aop specific eviction.

Called by eviction policy provider. Note that eviction is done only in local mode, that is, it doesn't replicate the node removal. This is will cause the replcation nodes not synchronizing, but it is ok since user is supposed to add the node again when get is null. After that, the contents will be in sync.

Overrides:
evict in class TreeCache (src)
Parameters:
fqn - Will remove everythign assoicated with this fqn.
Throws:
CacheException (src)