[jboss-cvs] JBossCache/src/org/jboss/cache ...
Manik Surtani
msurtani at jboss.com
Tue Nov 14 09:17:11 EST 2006
User: msurtani
Date: 06/11/14 09:17:11
Modified: src/org/jboss/cache Region.java CacheSPI.java
RegionImpl.java TreeCacheProxyImpl.java
TreeCache.java RegionManager.java
Log:
Merged eviction.Region and Region, eviction.RegionManager and RegionManager (lots of changes, now needs v. thorough testing)
Revision Changes Path
1.6 +16 -2 JBossCache/src/org/jboss/cache/Region.java
(In the diff below, changes in quantity of whitespace are not shown.)
Index: Region.java
===================================================================
RCS file: /cvsroot/jboss/JBossCache/src/org/jboss/cache/Region.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -b -r1.5 -r1.6
--- Region.java 8 Nov 2006 21:48:33 -0000 1.5
+++ Region.java 14 Nov 2006 14:17:11 -0000 1.6
@@ -9,6 +9,8 @@
import org.jboss.cache.eviction.EvictionPolicyConfig;
import org.jboss.cache.eviction.EvictionPolicy;
import org.jboss.cache.eviction.LRUPolicy;
+import org.jboss.cache.eviction.EvictedEventNode;
+import org.jboss.cache.config.EvictionRegionConfig;
/**
* Represents a section of the cache, and characteristics such as class loading and activaton can be applied to regions.
@@ -60,6 +62,18 @@
EvictionPolicyConfig getEvictionPolicyConfig();
+ EvictionPolicy getEvictionPolicy();
+
+ EvictionRegionConfig getEvictionRegionConfig();
+
+ void resetEvictionQueues();
+
+ int nodeEventQueueSize();
+
+ EvictedEventNode takeLastEventNode();
+
+ void putNodeEvent(EvictedEventNode event);
+
/**
* Add an event to the eviction queue marking a node as currently in use.
* If there is an {@link EvictionPolicy} associated with this region, and
@@ -74,7 +88,7 @@
*
* @see #unmarkNodeCurrentlyInUse(Fqn)
*/
- void markNodeCurrentlyInUse(Fqn fqn, long timeout);
+ void markNodeCurrentlyInUse(long timeout);
/**
* Add an event to the eviction queue indicating that a node is no longer in use.
@@ -83,7 +97,7 @@
*
* @see #markNodeCurrentlyInUse(Fqn, long)
*/
- void unmarkNodeCurrentlyInUse(Fqn fqn);
+ void unmarkNodeCurrentlyInUse();
Fqn getFqn();
}
1.20 +0 -2 JBossCache/src/org/jboss/cache/CacheSPI.java
(In the diff below, changes in quantity of whitespace are not shown.)
Index: CacheSPI.java
===================================================================
RCS file: /cvsroot/jboss/JBossCache/src/org/jboss/cache/CacheSPI.java,v
retrieving revision 1.19
retrieving revision 1.20
diff -u -b -r1.19 -r1.20
--- CacheSPI.java 13 Nov 2006 14:47:52 -0000 1.19
+++ CacheSPI.java 14 Nov 2006 14:17:11 -0000 1.20
@@ -109,8 +109,6 @@
void addUndoOperation(GlobalTransaction tx, MethodCall undoOperation);
- org.jboss.cache.eviction.RegionManager getEvictionRegionManager();
-
Map getLockTable();
RegionManager getRegionManager();
1.7 +158 -21 JBossCache/src/org/jboss/cache/RegionImpl.java
(In the diff below, changes in quantity of whitespace are not shown.)
Index: RegionImpl.java
===================================================================
RCS file: /cvsroot/jboss/JBossCache/src/org/jboss/cache/RegionImpl.java,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -b -r1.6 -r1.7
--- RegionImpl.java 8 Nov 2006 21:48:33 -0000 1.6
+++ RegionImpl.java 14 Nov 2006 14:17:11 -0000 1.7
@@ -6,11 +6,13 @@
*/
package org.jboss.cache;
+import EDU.oswego.cs.dl.util.concurrent.BoundedLinkedQueue;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
+import org.jboss.cache.config.EvictionRegionConfig;
import org.jboss.cache.eviction.EvictedEventNode;
+import org.jboss.cache.eviction.EvictionPolicy;
import org.jboss.cache.eviction.EvictionPolicyConfig;
-import org.jboss.cache.eviction.LRUPolicy;
import org.jboss.cache.eviction.NodeEventType;
/**
@@ -26,6 +28,11 @@
Fqn fqn;
boolean active;
ClassLoader classLoader;
+ BoundedLinkedQueue nodeEventQueue_;
+ int checkCapacityCount = 0;
+ int capacityWarnThreshold = 0;
+ EvictionRegionConfig configuration;
+ EvictionPolicy policy;
/**
* Creates a MarshRegion from an fqn and registers the region in the region registry.
@@ -39,6 +46,20 @@
this.active = !regionManager.isDefaultInactive();
}
+ /**
+ * Constructor that creates an eviction region
+ * @param policy
+ * @param config
+ */
+ public RegionImpl(EvictionPolicy policy, EvictionRegionConfig config, Fqn fqn, RegionManager regionManager)
+ {
+ this(fqn, regionManager);
+ this.configuration = config;
+ this.policy = policy;
+
+ createQueue();
+ }
+
public void registerContextClassLoader(ClassLoader classLoader)
{
this.classLoader = classLoader;
@@ -69,35 +90,25 @@
return classLoader;
}
- public void setEvictionPolicy(EvictionPolicyConfig evictionPolicyConfig)
- {
- // TODO: MANIK: HABANERO: Eviction policy config
- }
-
- public EvictionPolicyConfig getEvictionPolicyConfig()
- {
- // TODO: MANIK: HABANERO: Eviction policy config
- return null;
- }
-
public Fqn getFqn()
{
return fqn;
}
- public void markNodeCurrentlyInUse(Fqn fqn, long timeout)
+
+ // -------- eviction stuff -----
+
+ public void markNodeCurrentlyInUse(long timeout)
{
-// EvictedEventNode markUse = new EvictedEventNode(fqn, NodeEventType.MARK_IN_USE_EVENT);
-// markUse.setInUseTimeout(timeout);
-// putNodeEvent(markUse);
- log.error("markNodeCurrentlyInUse not yet implemented");
+ EvictedEventNode markUse = new EvictedEventNode(fqn, NodeEventType.MARK_IN_USE_EVENT);
+ markUse.setInUseTimeout(timeout);
+ putNodeEvent(markUse);
}
- public void unmarkNodeCurrentlyInUse(Fqn fqn)
+ public void unmarkNodeCurrentlyInUse()
{
-// EvictedEventNode markNoUse = new EvictedEventNode(fqn, NodeEventType.UNMARK_USE_EVENT);
-// putNodeEvent(markNoUse);
- log.error("markNodeCurrentlyInUse not yet implemented");
+ EvictedEventNode markNoUse = new EvictedEventNode(fqn, NodeEventType.UNMARK_USE_EVENT);
+ putNodeEvent(markNoUse);
}
public String toString()
@@ -117,4 +128,130 @@
}
return 1;
}
+
+
+ /*
+
+ from eviction region
+
+ public void setAddedNode(Fqn fqn)
+ {
+ putNodeEvent(fqn, NodeEventType.ADD_NODE_EVENT);
+ }
+
+ public void setRemovedNode(Fqn fqn)
+ {
+ putNodeEvent(fqn, NodeEventType.REMOVE_NODE_EVENT);
+ }
+
+ public void setVisitedNode(Fqn fqn)
+ {
+ putNodeEvent(fqn, NodeEventType.VISIT_NODE_EVENT);
+ }
+
+ public void putNodeEvent(Fqn fqn, NodeEventType type)
+ {
+ this.putNodeEvent(new EvictedEventNode(fqn, type));
+ }
+ */
+
+ public void putNodeEvent(EvictedEventNode event)
+ {
+ try
+ {
+ // Don't check capacity every time as this is an expensive operation for
+ // bounded buffer type objects in this situation
+ if (++checkCapacityCount > 100)
+ {
+ checkCapacityCount = 0;
+ if (nodeEventQueue_.size() > capacityWarnThreshold)
+ {
+ log.warn("putNodeEvent(): eviction node event queue size is at 98% threshold value of capacity: " + configuration.getEventQueueSize() + " You will need to reduce the wakeUpIntervalSeconds parameter.");
+ }
+ }
+ nodeEventQueue_.put(event);
+ }
+ catch (InterruptedException e)
+ {
+ log.debug("give up put", e);
+ }
+ }
+
+ /**
+ * Take the last node from node queue. It will also
+ * remove it from the queue.
+ *
+ * @return The EvictedEventNode
+ */
+ public EvictedEventNode takeLastEventNode()
+ {
+ try
+ {
+ return (EvictedEventNode) nodeEventQueue_.poll(0);
+ }
+ catch (InterruptedException e)
+ {
+ log.debug("trace", e);
+ }
+ return null;
+ }
+
+ public int nodeEventQueueSize()
+ {
+ return nodeEventQueue_.size();
+ }
+
+ public void resetEvictionQueues()
+ {
+ BoundedLinkedQueue q1 = nodeEventQueue_;
+ log.info("reseteEvictionQueues(): node queue size: " + q1.size() +
+ " region name: " + getFqn());
+ createQueue();
+ // Help to recycle
+ for (int i = 0; i < q1.size(); i++)
+ {
+ try
+ {
+ q1.take();
+ }
+ catch (InterruptedException e)
+ {
+ e.printStackTrace();
+ }
+ }
+ }
+
+ private void createQueue()
+ {
+ capacityWarnThreshold = (98 * configuration.getEventQueueSize()) / 100 - 100;
+ if (capacityWarnThreshold <= 0)
+ {
+ throw new RuntimeException("Capacity warn threshold used in eviction is smaller than 1.");
+ }
+ nodeEventQueue_ = new BoundedLinkedQueue(configuration.getEventQueueSize());
+ }
+
+ public EvictionRegionConfig getEvictionRegionConfig()
+ {
+ return this.configuration;
+ }
+
+ public EvictionPolicyConfig getEvictionPolicyConfig()
+ {
+ return configuration == null ? null : configuration.getEvictionPolicyConfig();
+ }
+
+ public EvictionPolicy getEvictionPolicy()
+ {
+ return policy;
+ }
+
+ public void setEvictionPolicy(EvictionPolicyConfig evictionPolicyConfig)
+ {
+ //To change body of implemented methods use File | Settings | File Templates.
+ }
+
+
+
+
}
1.47 +0 -5 JBossCache/src/org/jboss/cache/TreeCacheProxyImpl.java
(In the diff below, changes in quantity of whitespace are not shown.)
Index: TreeCacheProxyImpl.java
===================================================================
RCS file: /cvsroot/jboss/JBossCache/src/org/jboss/cache/TreeCacheProxyImpl.java,v
retrieving revision 1.46
retrieving revision 1.47
diff -u -b -r1.46 -r1.47
--- TreeCacheProxyImpl.java 2 Nov 2006 12:35:23 -0000 1.46
+++ TreeCacheProxyImpl.java 14 Nov 2006 14:17:11 -0000 1.47
@@ -169,11 +169,6 @@
treeCache.addUndoOperation(tx, undo_op);
}
- public org.jboss.cache.eviction.RegionManager getEvictionRegionManager()
- {
- return treeCache.getEvictionRegionManager();
- }
-
public Map getLockTable()
{
return treeCache.getLockTable();
1.267 +3 -26 JBossCache/src/org/jboss/cache/TreeCache.java
(In the diff below, changes in quantity of whitespace are not shown.)
Index: TreeCache.java
===================================================================
RCS file: /cvsroot/jboss/JBossCache/src/org/jboss/cache/TreeCache.java,v
retrieving revision 1.266
retrieving revision 1.267
diff -u -b -r1.266 -r1.267
--- TreeCache.java 11 Nov 2006 19:55:19 -0000 1.266
+++ TreeCache.java 14 Nov 2006 14:17:11 -0000 1.267
@@ -92,7 +92,7 @@
* @author <a href="mailto:manik at jboss.org">Manik Surtani (manik at jboss.org)</a>
* @author Brian Stansberry
* @author Daniel Huang (dhuang at jboss.org)
- * @version $Id: TreeCache.java,v 1.266 2006/11/11 19:55:19 msurtani Exp $
+ * @version $Id: TreeCache.java,v 1.267 2006/11/14 14:17:11 msurtani Exp $
* <p/>
* @see <a href="http://labs.jboss.com/portal/jbosscache/docs">JBossCache doc</a>
*/
@@ -181,11 +181,6 @@
protected VersionAwareMarshaller marshaller_ = null;
/**
- * MarshRegionManager used by cache eviction
- */
- protected org.jboss.cache.eviction.RegionManager evictionRegionManager_ = null;
-
- /**
* {@link #invokeMethod(MethodCall)} will dispatch to this chain of interceptors.
* In the future, this will be replaced with JBossAop. This is a first step towards refactoring JBossCache.
*/
@@ -523,15 +518,6 @@
}
/**
- * Obtain eviction thread (if any) wake up interval in seconds
- */
- public int getEvictionThreadWakeupIntervalSeconds()
- {
- return evictionRegionManager_.getEvictionThreadWakeupIntervalSeconds();
- }
-
-
- /**
* Sets the TransactionManagerLookup object
*
* @param l
@@ -881,12 +867,11 @@
protected void createEvictionPolicy()
{
-
- evictionRegionManager_ = new org.jboss.cache.eviction.RegionManager();
if (configuration.getEvictionConfig() != null
&& configuration.getEvictionConfig().isValidConfig())
{
- evictionRegionManager_.configure(this);
+ //evictionRegionManager_.configure(this);
+ if (true) throw new RuntimeException("Fixme: configure the region manager for evictions");
this.usingEviction = true;
}
else
@@ -4017,14 +4002,6 @@
}
- /**
- * Returns the eviction region manager for this TreeCache.
- */
- public org.jboss.cache.eviction.RegionManager getEvictionRegionManager()
- {
- return evictionRegionManager_;
- }
-
public VersionAwareMarshaller getMarshaller()
{
if (marshaller_ == null)
1.4 +454 -1 JBossCache/src/org/jboss/cache/RegionManager.java
(In the diff below, changes in quantity of whitespace are not shown.)
Index: RegionManager.java
===================================================================
RCS file: /cvsroot/jboss/JBossCache/src/org/jboss/cache/RegionManager.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -b -r1.3 -r1.4
--- RegionManager.java 18 Oct 2006 11:07:54 -0000 1.3
+++ RegionManager.java 14 Nov 2006 14:17:11 -0000 1.4
@@ -3,6 +3,7 @@
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.jboss.cache.buddyreplication.BuddyManager;
+import org.jboss.cache.eviction.RegionNameConflictException;
import java.util.ArrayList;
import java.util.Collections;
@@ -303,6 +304,458 @@
return regions;
}
+}
-}
+/*
+
+FROM THE ERegionManager:
+*/
+
+/**
+ * Factory to create region from configuration, to track region,
+ * and to resolve naming conflict for regions. Note that in addition to
+ * user-specified regions, there is also a global cache <code>_default_</code>
+ * region that covers everything else.
+ *
+ * @author Ben Wang 02-2004
+ * @author Daniel Huang (dhuang at jboss.org)
+ * @author Brian Stansberry
+ * @version $Id: RegionManager.java,v 1.4 2006/11/14 14:17:11 msurtani Exp $
+ */
+/*public class ERegionManager
+{
+
+ // There is global cache wide default values if no region is found.
+ final static Fqn DEFAULT_REGION = new Fqn("_default_");
+ private static final Log log_ = LogFactory.getLog(ERegionManager.class);
+
+ private final Map regionMap_ = new ConcurrentReaderHashMap();
+ private int longestFqn = 0;
+
+ private Timer evictionThread_;
+ private EvictionTimerTask evictionTimerTask_;
+ private EvictionConfig config_;
+ private TreeCache cache_;
+
+ *//**
+ * @deprecated This is provided for JBCache 1.2 backwards API compatibility.
+ *//*
+ private EvictionPolicy policy_;
+
+ public ERegionManager()
+ {
+ evictionTimerTask_ = new EvictionTimerTask();
+ }
+
+ public int getEvictionThreadWakeupIntervalSeconds()
+ {
+ return (config_ == null ? 0 : config_.getWakeupIntervalSeconds());
+ }
+
+ *//**
+ * @deprecated DO NOT USE THIS METHOD. IT IS PROVIDED FOR EJB3 INTEGRATION BACKWARDS COMPATIBILITY
+ *//*
+ public ERegion createRegion(String fqn, EvictionAlgorithm algorithm) throws RegionNameConflictException
+ {
+ return createRegion(Fqn.fromString(fqn), algorithm);
+ }
+
+ *//**
+ * @deprecated DO NOT USE THIS METHOD. IT IS PROVIDED FOR EJB3 INTEGRATION BACKWARDS COMPATIBILITY
+ *//*
+ public ERegion createRegion(Fqn fqn, EvictionAlgorithm algorithm) throws RegionNameConflictException
+ {
+ if (policy_ == null)
+ {
+ throw new RuntimeException("Deprecated API not properly setup for use. The MarshRegionManager must be constructed with a single Policy");
+ }
+
+ EvictionPolicyConfig epc = null;
+ try
+ {
+ epc = (EvictionPolicyConfig) policy_.getEvictionConfigurationClass().newInstance();
+ }
+ catch (Exception e)
+ {
+ throw new RuntimeException("Could not instantiate EvictionPolicyConfig class", e);
+ }
+
+ return createRegion(fqn, policy_, epc);
+ }
+
+ private void addRegion(ERegion region) throws RegionNameConflictException
+ {
+ // Even with ConcurrentReaderHashMap we want to synchronize
+ // so the following is atomic
+ synchronized (regionMap_)
+ {
+ Fqn fqn = region.getFqnObject();
+ checkConflict(fqn);
+ regionMap_.put(fqn, region);
+ longestFqn = Math.max(longestFqn, fqn.size());
+ }
+
+ // If the region was added programmatically, we need to update
+ // our config to include it
+ if (config_ != null)
+ {
+ synchronized (config_)
+ {
+ List regionConfigs = config_.getEvictionRegionConfigs();
+ if (regionConfigs == null)
+ regionConfigs = new ArrayList();
+
+ if (!regionConfigs.contains(region.getEvictionRegionConfig()))
+ {
+ regionConfigs.add(region.getEvictionRegionConfig());
+ config_.setEvictionRegionConfigs(regionConfigs);
+ }
+ }
+ }
+
+ evictionTimerTask_.addRegionToProcess(region);
+ }
+
+ public ERegion createRegion(EvictionRegionConfig erc) throws RegionNameConflictException
+ {
+ // Ensure we have defaults
+ erc.setDefaultEventQueueSize(config_ == null ? EvictionConfig.EVENT_QUEUE_SIZE_DEFAULT : config_.getDefaultEventQueueSize());
+
+ EvictionPolicy policy = instantiatePolicy(erc.getEvictionPolicyConfig());
+ policy.configure(cache_);
+
+ ERegion region = new ERegion(policy, erc);
+ addRegion(region);
+
+ return region;
+ }*/
+
+ /**
+ * Supports programatic instantiation of a region from an Fqn and a policy config.
+ *
+ * @param fqn
+ * @param epc
+ * @return
+ * @throws RegionNameConflictException
+ */
+ /* public ERegion createRegion(Fqn fqn, EvictionPolicyConfig epc) throws RegionNameConflictException
+ {
+ EvictionRegionConfig erc = new EvictionRegionConfig();
+ erc.setRegionFqn(fqn);
+ erc.setEvictionPolicyConfig(epc);
+ erc.setDefaultEventQueueSize(config_ == null ? EvictionConfig.EVENT_QUEUE_SIZE_DEFAULT : config_.getDefaultEventQueueSize());
+
+ return createRegion(erc);
+ }*/
+
+ /**
+ * Supports programatic instantiation of a region from an Fqn and a policy config.
+ *
+ * @param fqn
+ * @param epc
+ * @return
+ * @throws RegionNameConflictException
+ */
+ /* public ERegion createRegion(String fqn, EvictionPolicyConfig epc) throws RegionNameConflictException
+ {
+ return createRegion(Fqn.fromString(fqn), epc);
+ }*/
+
+ /**
+ * Supports programatic instantiation of a region from an Fqn, EvictionPolicy
+ * and a policy config. Should only be used in a case where the caller needs
+ * to manipulate the EvictionPolicy; otherwise use the other overloaded versions
+ * of this method.
+ *
+ * @param fqn
+ * @param epc
+ * @return
+ * @throws RegionNameConflictException
+ */
+/* public ERegion createRegion(Fqn fqn, EvictionPolicy policy, EvictionPolicyConfig epc) throws RegionNameConflictException
+ {
+ EvictionRegionConfig erc = new EvictionRegionConfig();
+ erc.setRegionFqn(fqn);
+ erc.setEvictionPolicyConfig(epc);
+ erc.setDefaultEventQueueSize(config_ == null ? EvictionConfig.EVENT_QUEUE_SIZE_DEFAULT : config_.getDefaultEventQueueSize());
+
+ policy.configure(cache_);
+
+ ERegion region = new ERegion(policy, erc);
+ addRegion(region);
+ return region;
+ }*/
+
+ /**
+ * Supports programatic instantiation of a region from an Fqn, EvictionPolicy
+ * and a policy config. Should only be used in a case where the caller needs
+ * to manipulate the EvictionPolicy; otherwise use the other overloaded versions
+ * of this method.
+ *
+ * @param fqn
+ * @param policy
+ * @param config
+ * @return
+ * @throws RegionNameConflictException
+ */
+/* public ERegion createRegion(String fqn, EvictionPolicy policy, EvictionPolicyConfig config) throws RegionNameConflictException
+ {
+ return createRegion(Fqn.fromString(fqn), policy, config);
+ }
+
+ public void configure(TreeCache cache)
+ {
+ if (log_.isTraceEnabled())
+ {
+ log_.trace("Configuring the eviction region manager");
+ }
+ cache_ = cache;
+
+ config_ = cache_.getConfiguration().getEvictionConfig();
+
+ // done for API 1.2 backwards compatibility for EJB3 integration.
+ String evictionClass = config_.getDefaultEvictionPolicyClass();
+ if (evictionClass != null && evictionClass.length() != 0)
+ {
+ try
+ {
+ policy_ = (EvictionPolicy) Util.loadClass(evictionClass).newInstance();
+ policy_.configure(cache_);
+ //cache_.setEvictionPolicyProvider(policy_);
+ }
+ catch (Exception e)
+ {
+ log_.warn("Default Policy with class name " + evictionClass + " could not be loaded by the classloader");
+ }
+ }
+
+ EvictionTreeCacheListener listener = new EvictionTreeCacheListener();
+ cache_.getNotifier().setEvictionPolicyListener(listener);
+
+ List regions = config_.getEvictionRegionConfigs();
+ if (regions != null)
+ {
+ for (Iterator iter = regions.iterator(); iter.hasNext();)
+ {
+ EvictionRegionConfig erc = (EvictionRegionConfig) iter.next();
+ try
+ {
+ createRegion(erc);
+ }
+ catch (RegionNameConflictException e)
+ {
+ throw new RuntimeException(
+ "Illegal region name specified for eviction policy " + erc.getRegionName()
+ + " exception: " + e);
+ }
+ }
+ }
+ }
+
+ public EvictionConfig getEvictionConfig()
+ {
+ return config_;
+ }*/
+
+ /**
+ * Removes a region by string.
+ */
+/* public void removeRegion(String fqn)
+ {
+ removeRegion(Fqn.fromString(fqn));
+ }*/
+
+ /**
+ * Removes a region by Fqn, returns true if the region was found.
+ */
+ /* public boolean removeRegion(Fqn fqn)
+ {
+ ERegion region = (ERegion) regionMap_.remove(fqn);
+ evictionTimerTask_.removeRegionToProcess(region);
+
+ if (region != null && config_ != null)
+ {
+ // Update the config to reflect the region's removal
+ synchronized (config_)
+ {
+ List regionConfigs = config_.getEvictionRegionConfigs();
+ for (Iterator it = regionConfigs.iterator(); it.hasNext();)
+ {
+ EvictionRegionConfig erc = (EvictionRegionConfig) it.next();
+ if (region.getFqnObject().equals(erc.getRegionFqn()))
+ {
+ regionConfigs.remove(erc);
+ config_.setEvictionRegionConfigs(regionConfigs);
+ break;
+ }
+ }
+ }
+ }
+
+ return region != null;
+ }*/
+
+ /**
+ * Returns true if the region exists.
+ */
+ /* public boolean hasRegion(String myFqn)
+ {
+ return hasRegion(Fqn.fromString(myFqn));
+ }*/
+
+ /**
+ * Returns true if the region exists.
+ */
+ /* public boolean hasRegion(Fqn fqn)
+ {
+ return regionMap_.containsKey(fqn);
+ }*/
+
+ /**
+ * Returns the MarshRegion belonging to a String FQN.
+ */
+/* public ERegion getRegion(String myFqn)
+ {
+ return getRegion(Fqn.fromString(myFqn));
+ }*/
+
+ /**
+ * Returns the MarshRegion corresponding to this Fqn.
+ */
+ /* public ERegion getRegion(Fqn fqn)
+ {
+ // Truncate Fqn as an optimization
+ if (fqn.size() > longestFqn)
+ fqn = fqn.getFqnChild(0, longestFqn);
+
+ ERegion region;
+ while (!fqn.isRoot())
+ {
+ region = (ERegion) regionMap_.get(fqn);
+ if (region != null)
+ return region;
+ fqn = fqn.getParent();
+ }
+
+ if (log_.isTraceEnabled())
+ {
+ log_.trace("getRegion(): user-specified region not found: " + fqn
+ + " will use the global default region");
+ }
+ region = (ERegion) regionMap_.get(DEFAULT_REGION);
+ if (region == null)
+ {
+ throw new RuntimeException(
+ "MarshRegionManager.getRegion(): Default region (" + DEFAULT_REGION + ") is not configured!" +
+ " You will need to define it in your EvictionPolicyConfig.");
+ }
+ return region;
+ }*/
+
+ /**
+ * Returns an ordered list of regions.
+ * Orders (by reverse) Fqn.
+ */
+ /* public ERegion[] getRegions()
+ {
+ Collection c = regionMap_.values();
+ ERegion r[] = new ERegion[c.size()];
+ r = (ERegion[]) regionMap_.values().toArray(r);
+ Arrays.sort(r, new RegionComparator());
+ return r;
+ }*/
+
+ /**
+ * Check for conflict in the current regions. There is a conflict
+ * if fqn is any parent fqn of the current regions.
+ *
+ * @param myFqn Current fqn for potential new region.
+ * @throws RegionNameConflictException to indicate a region name conflict has ocurred.
+ */
+ /* public void checkConflict(String myFqn) throws RegionNameConflictException
+ {
+ checkConflict(Fqn.fromString(myFqn));
+ }*/
+
+ /**
+ * Check for conflict in the current regions. There is a conflict
+ * if fqn is any parent fqn of the current regions.
+ */
+ /* public void checkConflict(Fqn fqn) throws RegionNameConflictException
+ {
+ for (int i = 0; i < fqn.size(); i++)
+ {
+ Fqn child = fqn.getFqnChild(i);
+ if (regionMap_.containsKey(child))
+ {
+ throw new RegionNameConflictException("MarshRegionManager.checkConflict(): new region fqn "
+ + fqn + " is in conflict with existing region fqn " + child);
+ }
+ }
+ // We are clear then.
+ }*/
+
+ /**
+ * This method is here to aid unit testing.
+ */
+ /* final void setTreeCache(TreeCache cache)
+ {
+ this.cache_ = cache;
+ }
+
+ public String toString()
+ {
+ return super.toString() + " regions=" + regionMap_;
+ }
+
+ class EvictionTreeCacheListener extends AbstractCacheListener
+ {
+ public void cacheStarted(CacheSPI cache)
+ {
+ log_.debug("Starting eviction timer");
+ evictionThread_ = new Timer();
+ evictionThread_.schedule(evictionTimerTask_, ERegionManager.this.getEvictionThreadWakeupIntervalSeconds() * 1000,
+ ERegionManager.this.getEvictionThreadWakeupIntervalSeconds() * 1000);
+ }
+
+ public void cacheStopped(CacheSPI cache)
+ {
+ log_.debug("Stopping eviction timer ... ");
+ if (evictionThread_ != null)
+ evictionThread_.cancel();
+ evictionThread_ = null;
+ }
+ }
+
+ static class RegionComparator implements Comparator
+ {
+ public int compare(Object o1, Object o2)
+ {
+ ERegion r1 = (ERegion) o1;
+ ERegion r2 = (ERegion) o2;
+ Fqn f1 = r1.getFqnObject();
+ Fqn f2 = r2.getFqnObject();
+ if (f1.equals(DEFAULT_REGION)) return -1;
+ if (f2.equals(DEFAULT_REGION)) return 1;
+ return -FqnComparator.INSTANCE.compare(f1, f2);
+ }
+ }
+
+ private static EvictionPolicy instantiatePolicy(EvictionPolicyConfig config)
+ {
+ try
+ {
+ return (EvictionPolicy) Util.loadClass(config.getEvictionPolicyClass()).newInstance();
+ }
+ catch (RuntimeException e)
+ {
+ throw e;
+ }
+ catch (Exception e)
+ {
+ throw new RuntimeException("Failed to create EvictionPolicy " +
+ config.getEvictionPolicyClass(), e);
+ }
+ }
+}*/
More information about the jboss-cvs-commits
mailing list