org.jboss.cache
Class RegionManagerImpl

java.lang.Object
  extended by org.jboss.cache.RegionManagerImpl
All Implemented Interfaces:
RegionManager
Direct Known Subclasses:
LegacyRegionManagerImpl

@ThreadSafe
public class RegionManagerImpl
extends Object
implements RegionManager

The default region manager, used with MVCC locking.

Since:
3.0.0
Author:
Manik Surtani

Field Summary
protected  BuddyFqnTransformer buddyFqnTransformer
           
protected  Configuration configuration
           
static Fqn DEFAULT_REGION
          The default region used in XML configuration files when defining eviction policies.
protected  LockManager lockManager
           
protected static org.apache.commons.logging.Log log
           
protected  RPCManager rpcManager
           
protected static boolean trace
           
 
Constructor Summary
RegionManagerImpl()
           
 
Method Summary
 void activate(Fqn fqn)
          Activates unmarshalling of replication messages for the region rooted in the given Fqn.
 void activateIfEmpty(Fqn fqn)
          Attempts to activate a given region rooted at a given Fqn, similar to RegionManager.activate(org.jboss.cache.Fqn) except that if the fqn is currently already in use (probably already been activated) this method is a no-op.
 void deactivate(Fqn fqn)
          Disables unmarshalling of replication messages for the region rooted in the given Fqn.
protected  void destroy()
           
 String dumpRegions()
          Returns a string containing debug information on every region.
 List<Region> getAllRegions(Region.Type type)
          Returns an ordered list of all regions.
 CacheSPI getCache()
           
 Configuration getConfiguration()
           
 EvictionTimerTask getEvictionTimerTask()
           
 int getNumRegions()
           
 Region getRegion(Fqn fqn, boolean createIfAbsent)
          Returns a region by Fqn, creating it optionally if absent.
 Region getRegion(Fqn fqn, Region.Type type, boolean createIfAbsent)
          An overloaded form of RegionManager.getRegion(org.jboss.cache.Fqn,boolean) that takes an additional Region.Type parameter to force regions of a specific type.
 Region getRegion(String fqn, boolean createIfAbsent)
          Returns a region using Fqn.fromString(fqn), calling RegionManager.getRegion(org.jboss.cache.Fqn,boolean)
 Region getValidMarshallingRegion(Fqn fqn)
          Retrieves a valid marshalling Region after taking into account that this may be a Buddy Backup Fqn.
 boolean hasRegion(Fqn fqn, Region.Type type)
          Returns true if the region exists
protected  void inactivateRegion(Fqn fqn)
          Causes the cache to stop accepting replication events for the subtree rooted at subtreeFqn and evict all nodes in that subtree.
 void injectDependencies(CacheSPI cache, Configuration configuration, RPCManager rpcManager, LockManager lockManager, BuddyFqnTransformer transformer, RegionRegistry regionsRegistry)
           
 boolean isDefaultInactive()
           
 boolean isInactive(Fqn fqn)
          Convenienve method.
protected  boolean isRegionLocked(Fqn fqn)
           
 boolean isUsingEvictions()
           
protected  void lock(Fqn fqn)
           
 boolean removeRegion(Fqn fqn)
          Removes a Region identified by the given fqn.
 void reset()
          Resets the region manager's regions registry
 void setContextClassLoaderAsCurrent(Fqn fqn)
          Helper utility that checks for a ClassLoader registered for the given Fqn, and if found sets it as the TCCL.
 void setDefaultInactive(boolean defaultInactive)
          Sets if replication for new Regions is by default inactive.
 void setEvictionConfig(EvictionConfig evictionConfig)
          Sets the eviction configuration.
 void setUsingEvictions(boolean usingEvictions)
          Sets if evictions are processed.
 void start()
           
 void startEvictionThread()
          Starts the eviction processing thread.
protected  void stop()
           
 void stopEvictionThread()
          Stops the eviction processing thread
 String toString()
          Returns a string containing debug information on every region.
protected  void unlock(Fqn fqn)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

DEFAULT_REGION

public static final Fqn DEFAULT_REGION
The default region used in XML configuration files when defining eviction policies. Any eviction settings bound under this 'default' Fqn is appplied to Fqn.ROOT internally so any region that is not explicitly defined comes under the settings defined for this default.


log

protected static final org.apache.commons.logging.Log log

trace

protected static final boolean trace

configuration

protected Configuration configuration

rpcManager

protected RPCManager rpcManager

lockManager

protected LockManager lockManager

buddyFqnTransformer

protected BuddyFqnTransformer buddyFqnTransformer
Constructor Detail

RegionManagerImpl

public RegionManagerImpl()
Method Detail

isRegionLocked

protected final boolean isRegionLocked(Fqn fqn)

lock

protected final void lock(Fqn fqn)

unlock

protected final void unlock(Fqn fqn)

injectDependencies

public void injectDependencies(CacheSPI cache,
                               Configuration configuration,
                               RPCManager rpcManager,
                               LockManager lockManager,
                               BuddyFqnTransformer transformer,
                               RegionRegistry regionsRegistry)

start

public void start()

stop

protected void stop()

destroy

protected void destroy()

isUsingEvictions

public boolean isUsingEvictions()
Specified by:
isUsingEvictions in interface RegionManager
Returns:
true if evictions are being processed.

isDefaultInactive

public boolean isDefaultInactive()
Specified by:
isDefaultInactive in interface RegionManager
Returns:
true if replication is by default inactive for new Regions.

setDefaultInactive

public void setDefaultInactive(boolean defaultInactive)
Description copied from interface: RegionManager
Sets if replication for new Regions is by default inactive.

Specified by:
setDefaultInactive in interface RegionManager

setContextClassLoaderAsCurrent

public void setContextClassLoaderAsCurrent(Fqn fqn)
Description copied from interface: RegionManager
Helper utility that checks for a ClassLoader registered for the given Fqn, and if found sets it as the TCCL. If the given Fqn is under the _BUDDY_BACKUP_ region, the equivalent region in the main cache is used to find the ClassLoader.

Specified by:
setContextClassLoaderAsCurrent in interface RegionManager
Parameters:
fqn - Fqn pointing to a region for which a special classloader may have been registered.

getRegion

public Region getRegion(Fqn fqn,
                        boolean createIfAbsent)
Description copied from interface: RegionManager
Returns a region by Fqn, creating it optionally if absent. If the region does not exist and createIfAbsent is false, a parent region which may apply to the Fqn is sought.

Note that this takes into account the fact that this may be a Buddy Backup Fqn. If it is, the actual Fqn is calculated and used instead.

Specified by:
getRegion in interface RegionManager

getValidMarshallingRegion

public Region getValidMarshallingRegion(Fqn fqn)
Description copied from interface: RegionManager
Retrieves a valid marshalling Region after taking into account that this may be a Buddy Backup Fqn. If the fqn passed in is null, the region has been deactivated or if a region cannot be found, this method returns a null.

Specified by:
getValidMarshallingRegion in interface RegionManager
Parameters:
fqn - of the region to locate
Returns:
a region

getRegion

public Region getRegion(Fqn fqn,
                        Region.Type type,
                        boolean createIfAbsent)
Description copied from interface: RegionManager
An overloaded form of RegionManager.getRegion(org.jboss.cache.Fqn,boolean) that takes an additional Region.Type parameter to force regions of a specific type.

Note that this takes into account the fact that this may be a Buddy Backup Fqn. If it is, the actual Fqn is calculated and used instead.

Specified by:
getRegion in interface RegionManager
See Also:
Region.Type

getRegion

public Region getRegion(String fqn,
                        boolean createIfAbsent)
Description copied from interface: RegionManager
Returns a region using Fqn.fromString(fqn), calling RegionManager.getRegion(org.jboss.cache.Fqn,boolean)

Specified by:
getRegion in interface RegionManager
See Also:
RegionManager.getRegion(org.jboss.cache.Fqn,boolean)

removeRegion

public boolean removeRegion(Fqn fqn)
Description copied from interface: RegionManager
Removes a Region identified by the given fqn.

Specified by:
removeRegion in interface RegionManager
Parameters:
fqn - fqn of the region to remove
Returns:
true if such a region existed and was removed.

getEvictionTimerTask

public EvictionTimerTask getEvictionTimerTask()
Specified by:
getEvictionTimerTask in interface RegionManager
Returns:
the eviction timer task attached to the region manager

getConfiguration

public Configuration getConfiguration()
Specified by:
getConfiguration in interface RegionManager
Returns:
the configuration

activate

public void activate(Fqn fqn)
              throws RegionNotEmptyException
Description copied from interface: RegionManager
Activates unmarshalling of replication messages for the region rooted in the given Fqn.

NOTE: This method will cause the creation of a node in the local cache at subtreeFqn whether or not that node exists anywhere else in the cluster. If the node does not exist elsewhere, the local node will be empty. The creation of this node will not be replicated.

Specified by:
activate in interface RegionManager
Parameters:
fqn - representing the region to be activated.
Throws:
RegionNotEmptyException - if the node fqn exists and already has either data or children

activateIfEmpty

public void activateIfEmpty(Fqn fqn)
Description copied from interface: RegionManager
Attempts to activate a given region rooted at a given Fqn, similar to RegionManager.activate(org.jboss.cache.Fqn) except that if the fqn is currently already in use (probably already been activated) this method is a no-op.

Specified by:
activateIfEmpty in interface RegionManager
Parameters:
fqn - which represents the region to activate

isInactive

public boolean isInactive(Fqn fqn)
Description copied from interface: RegionManager
Convenienve method. If the region defined by fqn does not exist, RegionManager.isDefaultInactive() is returned, otherwise !Region.isActive() is returned.

Specified by:
isInactive in interface RegionManager
Parameters:
fqn - fqn to test
Returns:
true if inactive

inactivateRegion

protected void inactivateRegion(Fqn fqn)
                         throws CacheException
Causes the cache to stop accepting replication events for the subtree rooted at subtreeFqn and evict all nodes in that subtree.

This is legacy code and should not be called directly. This is a private method for now and will be refactored out. You should be using activate(Fqn) and deactivate(Fqn)

Parameters:
fqn - Fqn string indicating the uppermost node in the portion of the cache that should be activated.
Throws:
CacheException - if there is a problem evicting nodes
IllegalStateException - if Configuration.isUseRegionBasedMarshalling() is false

hasRegion

public boolean hasRegion(Fqn fqn,
                         Region.Type type)
Description copied from interface: RegionManager
Returns true if the region exists

Specified by:
hasRegion in interface RegionManager
Parameters:
fqn - FQN of the region
type - type of region to search for
Returns:
true if the region exists

deactivate

public void deactivate(Fqn fqn)
Description copied from interface: RegionManager
Disables unmarshalling of replication messages for the region rooted in the given Fqn.

Specified by:
deactivate in interface RegionManager

reset

public void reset()
Description copied from interface: RegionManager
Resets the region manager's regions registry

Specified by:
reset in interface RegionManager

getAllRegions

public List<Region> getAllRegions(Region.Type type)
Description copied from interface: RegionManager
Returns an ordered list of all regions. Note that the ordered list returned is sorted according to the natural order defined in the Comparable interface, which Region extends.

Specified by:
getAllRegions in interface RegionManager
Parameters:
type - Type of region to return
Returns:
an ordered list of all regions, based on the type requested.

setUsingEvictions

public void setUsingEvictions(boolean usingEvictions)
Description copied from interface: RegionManager
Sets if evictions are processed.

Specified by:
setUsingEvictions in interface RegionManager

setEvictionConfig

public void setEvictionConfig(EvictionConfig evictionConfig)
Description copied from interface: RegionManager
Sets the eviction configuration.

Specified by:
setEvictionConfig in interface RegionManager

dumpRegions

public String dumpRegions()
Description copied from interface: RegionManager
Returns a string containing debug information on every region.

Specified by:
dumpRegions in interface RegionManager
Returns:
Regions as a string

toString

public String toString()
Returns a string containing debug information on every region.

Overrides:
toString in class Object

getCache

public CacheSPI getCache()
Specified by:
getCache in interface RegionManager

startEvictionThread

public void startEvictionThread()
Starts the eviction processing thread.

Specified by:
startEvictionThread in interface RegionManager

stopEvictionThread

public void stopEvictionThread()
Stops the eviction processing thread

Specified by:
stopEvictionThread in interface RegionManager

getNumRegions

public int getNumRegions()


Copyright © 2008 JBoss, a division of Red Hat. All Rights Reserved.