org.jboss.cache.aop
Class MarshalledTreeCache

java.lang.Object
  extended by org.jboss.mx.util.JBossNotificationBroadcasterSupport
      extended by org.jboss.system.ServiceMBeanSupport
          extended by org.jboss.cache.TreeCache
              extended by org.jboss.cache.aop.MarshalledTreeCache
All Implemented Interfaces:
java.lang.Cloneable, javax.management.MBeanRegistration, javax.management.NotificationBroadcaster, javax.management.NotificationEmitter, TreeCacheListener, TreeCacheMBean, org.jboss.system.Service, org.jboss.system.ServiceMBean, org.jgroups.MembershipListener

public class MarshalledTreeCache
extends TreeCache
implements TreeCacheListener

Version of TreeCache that added call to handle marshalling values. You will need marshalling when your application is running under different class loader scope, for example, under JBoss AS where your application has a scoped class loader.

Note that: Currently, we also have a in-memory cache copy to minimize the call to unmarshalling. And we also have an invalidation mechanism in place to synchronize the external updates.

In the future, it'd be best if JBossCache can provides 1) notification excluding myself, 2) notification granulairty with specific modified key, 3) we will also move this to different package.

Finally, since the use of in-memory copy, the memory usage is almost doubled since we have one in-memory copy and the marshalled value in the cache store.

Author:
Ben Wang

Field Summary
protected  TreeCache localCopy_
           
protected  boolean marshalling_
           
protected  java.lang.String nodeId_
           
protected static java.lang.String NODEID_KEY
           
protected  java.lang.ClassLoader tcl_
           
protected  boolean useLocalOptimization_
           
 
Fields inherited from class org.jboss.cache.TreeCache
activationChangeNodes, buddyManager, buddyReplicationConfig, cache_mode, cacheLoaderConfig, cacheLoaderManager, channel, cloaderConfig, cluster_name, cluster_props, coordinator, DEFAULT_REPLICATION_VERSION, disp, evictConfig_, eviction_policy_class, eviction_policy_provider, evictionInterceptorClass, evictionRegionManager_, fetchInMemoryState, hasListeners, inactiveOnStartup, interceptor_chain, internalFqns, INVALIDATION_ASYNC, INVALIDATION_SYNC, isolationLevel, isStandalone, isStateSet, LOCAL, lock_acquisition_timeout, log, marshaller_, members, ml, mux_serviceName, mux_stackName, nodeLockingOptimistic, regionManager_, REPL_ASYNC, repl_queue, repl_queue_interval, repl_queue_max_elements, REPL_SYNC, root, SEPARATOR, setStateException, state_fetch_timeout, sync_commit_phase, sync_repl_timeout, sync_rollback_phase, tm, tm_lookup, tm_lookup_class, UNINITIALIZED, use_interceptor_mbeans, use_repl_queue, useCreateService, useRegionBasedMarshalling, usingEviction
 
Fields inherited from class org.jboss.system.ServiceMBeanSupport
server, SERVICE_CONTROLLER_SIG, serviceName
 
Fields inherited from interface org.jboss.system.ServiceMBean
CREATE_EVENT, CREATED, DESTROY_EVENT, DESTROYED, FAILED, REGISTERED, START_EVENT, STARTED, STARTING, states, STOP_EVENT, STOPPED, STOPPING, UNREGISTERED
 
Constructor Summary
MarshalledTreeCache()
           
MarshalledTreeCache(org.jgroups.JChannel channel)
           
MarshalledTreeCache(java.lang.String cluster_name, java.lang.String props, long state_fetch_timeout)
           
 
Method Summary
 void cacheStarted(TreeCache cache)
          Called when the cache is started.
 void cacheStopped(TreeCache cache)
          Called when the cache is stopped.
protected  void checkValue(java.lang.Object value)
           
 java.lang.String getNodeId()
          DataNode id is a communication id that denotes the cluster node.
protected  void invalidate(Fqn fqn)
          Invalidate the local copy cache.
 java.lang.Object marshalledGet_(Fqn fqn, java.lang.Object key)
           
 java.lang.Object marshalledGet(Fqn fqn, java.lang.Object key)
          Obtain the value from the marshalled cache.
 java.lang.Object marshalledGet(java.lang.String fqn, java.lang.Object key)
           
 void marshalledPut_(Fqn fqn, java.lang.Object key, java.lang.Object value)
           
 void marshalledPut(Fqn fqn, java.lang.Object key, java.lang.Object value)
          Marshalled put.
 void marshalledPut(java.lang.String fqn, java.lang.Object key, java.lang.Object value)
           
 java.lang.Object marshalledRemove_(Fqn fqn, java.lang.Object key)
           
 java.lang.Object marshalledRemove(Fqn fqn, java.lang.Object key)
          Remove a marshalled node.
 java.lang.Object marshalledRemove(java.lang.String fqn, java.lang.Object key)
           
 void nodeCreated(Fqn fqn)
          Called when a node is created
 void nodeEvicted(Fqn fqn)
          Called when a node is evicted (not the same as remove()).
 void nodeLoaded(Fqn fqn)
          Called when a node is loaded into memory via the CacheLoader.
 void nodeModified(Fqn fqn)
          Called when a node is modified, e.g., one (key, value) pair in the internal map storage has been modified.
 void nodeRemoved(Fqn fqn)
          Called when a node is removed.
 void nodeVisited(Fqn fqn)
          Called when a node is visisted, i.e., get().
protected  void obtainNodeId()
          Get a node id based on jgroups properties.
 void setClassLoader(java.lang.ClassLoader tcl)
          The context class loader to perform marshalling/unmarshalling
 void setLocalOptimization(boolean optimization)
          Indicate whether to have a in-memory copy of the unmarshalling object such that there is no need to unmarshal.
 void setMarshalling(boolean marshalling)
          Turn marshalling layer on or off.
 void startService()
          Lifecyle method.
 void stopService()
          Lifecycle method.
 void viewChange(org.jgroups.View new_view)
           
 
Methods inherited from class org.jboss.cache.TreeCache
_addChild, _clusteredGet, _createService, _dataGravitationCleanup, _enqueueMethodCall, _evict, _evict, _evictSubtree, _get, _get, _getAssociatedState, _getChildrenNames, _getData, _getKeys, _getState, _getState, _gravitateData, _loadState, _loadState, _lock, _print, _put, _put, _put, _put, _put, _put, _releaseAllLocks, _remoteAnnounceBuddyPoolName, _remoteAssignToBuddyGroup, _remoteRemoveFromBuddyGroup, _remove, _remove, _remove, _remove, _remove, _remove, _remove, _removeData, _removeData, _removeData, _removeData, _removeData, _replicate, _replicate, _setState, acquireLocksForStateTransfer, activateRegion, addTreeCacheListener, addUndoOperation, block, callRemoteMethods, callRemoteMethods, callRemoteMethods, callRemoteMethods, callRemoteMethods, commit, createEvictionPolicy, createService, createSubtreeRootNode, destroyService, determineCoordinator, dumpTransactionTable, evict, exists, exists, exists, exists, fetchState, fetchStateOnStartup, forceAcquireLock, get, get, get, get, get, get, get, get, getBuddyManager, getBuddyReplicationConfig, getCacheLoader, getCacheLoaderAsynchronous, getCacheLoaderClass, getCacheLoaderConfig, getCacheLoaderConfiguration, getCacheLoaderFetchPersistentState, getCacheLoaderFetchTransientState, getCacheLoaderManager, getCacheLoaderPassivation, getCacheLoaderPreload, getCacheLoaderShared, getCacheMode, getCacheModeInternal, getChildrenNames, getChildrenNames, getChildrenNames, getClusterName, getClusterProperties, getCoordinator, getCurrentTransaction, getCurrentTransaction, getCurrentTransaction, getCurrentTransaction, getDeadlockDetection, getDefaultProperties, getEvictionInterceptorClass, getEvictionPolicyClass, getEvictionPolicyConfig, getEvictionRegionManager, getEvictionThreadWakeupIntervalSeconds, getFetchInMemoryState, getFetchPersistentState, getFetchStateOnStartup, getInitialStateRetrievalTimeout, getInstance, getInterceptorChain, getInterceptors, getInternalFqns, getInvocationContext, getIsolationLevel, getIsolationLevelClass, getKeys, getKeys, getLocalAddress, getLocalTransaction, getLockAcquisitionTimeout, getLockTable, getMarshaller, getMembers, getMessageListener, getMultiplexerService, getMultiplexerStack, getNodeLockingScheme, getNumberOfAttributes, getNumberOfAttributes, getNumberOfLocksHeld, getNumberOfNodes, getOwnerForLock, getPojoCacheConfig, getRegionManager, getReplicationVersion, getReplicationVersionShort, getReplQueue, getReplQueueInterval, getReplQueueMaxElements, getRoot, getStateBytes, getStateTransferVersion, getSyncCommitPhase, getSyncReplTimeout, getSyncRollbackPhase, getTransactionManager, getTransactionManagerLookupClass, getTransactionTable, getTreeCacheListeners, getUseInterceptorMbeans, getUseMarshalling, getUseRegionBasedMarshalling, getUseReplQueue, getVersion, hasChild, inactivateRegion, invokeMethod, isCoordinator, isInactiveOnStartup, isNodeLockingOptimistic, isUsingEviction, load, loadClass, notifyAllNodesCreated, notifyCacheStarted, notifyCacheStopped, notifyCallForInactiveSubtree, notifyNodeActivate, notifyNodeCreated, notifyNodeEvict, notifyNodeEvicted, notifyNodeLoaded, notifyNodeModified, notifyNodeModify, notifyNodePassivate, notifyNodeRemove, notifyNodeRemoved, notifyNodeVisited, notifyViewChange, optimisticPrepare, peek, peek, prepare, print, print, printDetails, printLockInfo, purgeCacheLoaders, put, put, put, put, put, put, putFailFast, putFailFast, registerClassLoader, releaseAllLocks, releaseAllLocks, releaseStateTransferLocks, remove, remove, remove, remove, remove, remove, removeData, removeData, removeTreeCacheListener, rollback, setBuddyReplicationConfig, setCacheLoader, setCacheLoaderAsynchronous, setCacheLoaderClass, setCacheLoaderConfig, setCacheLoaderConfiguration, setCacheLoaderFetchPersistentState, setCacheLoaderFetchTransientState, setCacheLoaderManager, setCacheLoaderPassivation, setCacheLoaderPreload, setCacheLoaderShared, setCacheMode, setCacheMode, setClusterConfig, setClusterName, setClusterProperties, setDeadlockDetection, setEvictionListener, setEvictionPolicyClass, setEvictionPolicyConfig, setEvictionPolicyProvider, setFetchInMemoryState, setFetchStateOnStartup, setInactiveOnStartup, setInitialStateRetrievalTimeout, setInterceptorChain, setInvocationContext, setIsolationLevel, setIsolationLevel, setIsUsingEviction, setLockAcquisitionTimeout, setMultiplexerService, setMultiplexerStack, setNodeLockingOptimistic, setNodeLockingScheme, setPojoCacheConfig, setReplicationVersion, setReplQueueInterval, setReplQueueMaxElements, setStateBytes, setStateTransferVersion, setSyncCommitPhase, setSyncReplTimeout, setSyncRollbackPhase, setTransactionManagerLookup, setTransactionManagerLookupClass, setUseInterceptorMbeans, setUseMarshalling, setUseRegionBasedMarshalling, setUseReplQueue, string2Mode, suspect, toString, toString, unregisterClassLoader, viewAccepted
 
Methods inherited from class org.jboss.system.ServiceMBeanSupport
create, destroy, getDeploymentInfo, 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
addNotificationListener, getNotificationInfo, handleNotification, nextNotificationSequenceNumber, removeNotificationListener, removeNotificationListener, sendNotification
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface org.jboss.system.ServiceMBean
getName, getState, getStateString, jbossInternalLifecycle
 
Methods inherited from interface org.jboss.system.Service
create, destroy, start, stop
 

Field Detail

localCopy_

protected TreeCache localCopy_

nodeId_

protected java.lang.String nodeId_

NODEID_KEY

protected static final java.lang.String NODEID_KEY
See Also:
Constant Field Values

tcl_

protected java.lang.ClassLoader tcl_

useLocalOptimization_

protected boolean useLocalOptimization_

marshalling_

protected boolean marshalling_
Constructor Detail

MarshalledTreeCache

public MarshalledTreeCache(java.lang.String cluster_name,
                           java.lang.String props,
                           long state_fetch_timeout)
                    throws java.lang.Exception
Throws:
java.lang.Exception

MarshalledTreeCache

public MarshalledTreeCache()
                    throws java.lang.Exception
Throws:
java.lang.Exception

MarshalledTreeCache

public MarshalledTreeCache(org.jgroups.JChannel channel)
                    throws java.lang.Exception
Throws:
java.lang.Exception
Method Detail

startService

public void startService()
                  throws java.lang.Exception
Description copied from class: TreeCache
Lifecyle method. This is the same thing as calling start

Specified by:
startService in interface TreeCacheMBean
Overrides:
startService in class TreeCache
Throws:
java.lang.Exception

stopService

public void stopService()
Description copied from class: TreeCache
Lifecycle method. Same thing as calling stop.

Specified by:
stopService in interface TreeCacheMBean
Overrides:
stopService in class TreeCache

obtainNodeId

protected void obtainNodeId()
Get a node id based on jgroups properties.


getNodeId

public java.lang.String getNodeId()
DataNode id is a communication id that denotes the cluster node.


setMarshalling

public void setMarshalling(boolean marshalling)
Turn marshalling layer on or off. If off, no marshalling. Default is on.


setLocalOptimization

public void setLocalOptimization(boolean optimization)
Indicate whether to have a in-memory copy of the unmarshalling object such that there is no need to unmarshal. If it is on, invlidation will be handled where another active node has update this fqn.


setClassLoader

public void setClassLoader(java.lang.ClassLoader tcl)
The context class loader to perform marshalling/unmarshalling


marshalledPut

public void marshalledPut(java.lang.String fqn,
                          java.lang.Object key,
                          java.lang.Object value)
                   throws CacheException
Throws:
CacheException

marshalledPut

public void marshalledPut(Fqn fqn,
                          java.lang.Object key,
                          java.lang.Object value)
                   throws CacheException
Marshalled put. That is, the value that is put into cache is marshalled first. Note that we still require that key to be primitive type.

Throws:
CacheException

marshalledPut_

public void marshalledPut_(Fqn fqn,
                           java.lang.Object key,
                           java.lang.Object value)
                    throws CacheException
Throws:
CacheException

marshalledGet

public java.lang.Object marshalledGet(java.lang.String fqn,
                                      java.lang.Object key)
                               throws CacheException
Throws:
CacheException

marshalledGet

public java.lang.Object marshalledGet(Fqn fqn,
                                      java.lang.Object key)
                               throws CacheException
Obtain the value from the marshalled cache. Note that the return value is un-marshalled either from the local copy or from the distributed store.

Throws:
CacheException

marshalledGet_

public java.lang.Object marshalledGet_(Fqn fqn,
                                       java.lang.Object key)
                                throws CacheException
Throws:
CacheException

marshalledRemove

public java.lang.Object marshalledRemove(java.lang.String fqn,
                                         java.lang.Object key)
                                  throws CacheException
Throws:
CacheException

marshalledRemove

public java.lang.Object marshalledRemove(Fqn fqn,
                                         java.lang.Object key)
                                  throws CacheException
Remove a marshalled node. This is required if you have performed a marshalledPut since we will need to do clean up.

Throws:
CacheException

marshalledRemove_

public java.lang.Object marshalledRemove_(Fqn fqn,
                                          java.lang.Object key)
                                   throws CacheException
Throws:
CacheException

nodeCreated

public void nodeCreated(Fqn fqn)
Description copied from interface: TreeCacheListener
Called when a node is created

Specified by:
nodeCreated in interface TreeCacheListener

nodeRemoved

public void nodeRemoved(Fqn fqn)
Description copied from interface: TreeCacheListener
Called when a node is removed.

Specified by:
nodeRemoved in interface TreeCacheListener

nodeLoaded

public void nodeLoaded(Fqn fqn)
Description copied from interface: TreeCacheListener
Called when a node is loaded into memory via the CacheLoader. This is not the same as TreeCacheListener.nodeCreated(Fqn).

Specified by:
nodeLoaded in interface TreeCacheListener

nodeEvicted

public void nodeEvicted(Fqn fqn)
Description copied from interface: TreeCacheListener
Called when a node is evicted (not the same as remove()).

Specified by:
nodeEvicted in interface TreeCacheListener

nodeModified

public void nodeModified(Fqn fqn)
Description copied from interface: TreeCacheListener
Called when a node is modified, e.g., one (key, value) pair in the internal map storage has been modified.

Specified by:
nodeModified in interface TreeCacheListener

nodeVisited

public void nodeVisited(Fqn fqn)
Description copied from interface: TreeCacheListener
Called when a node is visisted, i.e., get().

Specified by:
nodeVisited in interface TreeCacheListener

cacheStarted

public void cacheStarted(TreeCache cache)
Description copied from interface: TreeCacheListener
Called when the cache is started.

Specified by:
cacheStarted in interface TreeCacheListener

cacheStopped

public void cacheStopped(TreeCache cache)
Description copied from interface: TreeCacheListener
Called when the cache is stopped.

Specified by:
cacheStopped in interface TreeCacheListener

viewChange

public void viewChange(org.jgroups.View new_view)
Specified by:
viewChange in interface TreeCacheListener

checkValue

protected void checkValue(java.lang.Object value)

invalidate

protected void invalidate(Fqn fqn)
Invalidate the local copy cache. Assumption is invlidation should not happen that often anyway. In addition, we will invalidate the whole thing under the fqn.

Parameters:
fqn -


Copyright 1998-2005 JBoss Inc . All Rights Reserved.