JBoss Cache SVN: r7044 - in core/trunk/src: main/java/org/jboss/cache/eviction and 1 other directories.
by jbosscache-commits@lists.jboss.org
Author: manik.surtani(a)jboss.com
Date: 2008-10-31 08:06:57 -0400 (Fri, 31 Oct 2008)
New Revision: 7044
Modified:
core/trunk/src/main/java/org/jboss/cache/AbstractNode.java
core/trunk/src/main/java/org/jboss/cache/RegionImpl.java
core/trunk/src/main/java/org/jboss/cache/RegionManagerImpl.java
core/trunk/src/main/java/org/jboss/cache/eviction/EvictionTimerTask.java
core/trunk/src/test/java/org/jboss/cache/util/internals/EvictionController.java
Log:
Improved eviction and region interaction
Modified: core/trunk/src/main/java/org/jboss/cache/AbstractNode.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/AbstractNode.java 2008-10-31 11:21:10 UTC (rev 7043)
+++ core/trunk/src/main/java/org/jboss/cache/AbstractNode.java 2008-10-31 12:06:57 UTC (rev 7044)
@@ -21,6 +21,8 @@
*/
package org.jboss.cache;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
import static org.jboss.cache.AbstractNode.NodeFlags.REMOVED;
import static org.jboss.cache.AbstractNode.NodeFlags.RESIDENT;
import org.jboss.cache.lock.IdentityLock;
@@ -41,6 +43,7 @@
protected ConcurrentMap children; // purposefully NOT genericized yet, since UnversionedNode and PessimisticUnversionedNode will both store different types.
protected Fqn fqn;
+ private static final Log log = LogFactory.getLog(AbstractNode.class);
/**
* Flags placed on the node. Replaces older 'boolean' flags.
*/
@@ -159,6 +162,10 @@
public void setResident(boolean resident)
{
+ if (resident)
+ {
+ log.trace("Someone is marking " + fqn + " as resident!", new Throwable());
+ }
setFlag(RESIDENT, resident);
}
Modified: core/trunk/src/main/java/org/jboss/cache/RegionImpl.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/RegionImpl.java 2008-10-31 11:21:10 UTC (rev 7043)
+++ core/trunk/src/main/java/org/jboss/cache/RegionImpl.java 2008-10-31 12:06:57 UTC (rev 7044)
@@ -173,7 +173,6 @@
"; classloader=" + classLoader +
"; status=" + status +
"; eviction=" + (evictionAlgorithm != null) +
- "; timerThreadRegistered=" + (evictionAlgorithm != null && regionManager.getEvictionTimerTask().isRegionRegisteredForProcessing(this)) +
"; evictionQueueSize=" + (evictionAlgorithm == null ? "-1" : evictionEventQueue.size()) +
'}';
}
@@ -211,7 +210,6 @@
{
this.evictionRegionConfig = evictionRegionConfig;
evictionAlgorithm = createEvictionAlgorithm(evictionRegionConfig.getEvictionAlgorithmConfig(), evictionRegionConfig.getEvictionActionPolicyClassName());
- regionManager.getEvictionTimerTask().addRegionToProcess(this);
if (evictionEventQueue == null) createQueue();
evictionAlgorithm.initialize();
}
Modified: core/trunk/src/main/java/org/jboss/cache/RegionManagerImpl.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/RegionManagerImpl.java 2008-10-31 11:21:10 UTC (rev 7043)
+++ core/trunk/src/main/java/org/jboss/cache/RegionManagerImpl.java 2008-10-31 12:06:57 UTC (rev 7044)
@@ -141,7 +141,7 @@
setDefaultInactive(configuration.isInactiveOnStartup());
if (isUsingEvictions())
- evictionTimerTask.init(evictionConfig.getWakeupInterval(), configuration.getRuntimeConfig().getEvictionTimerThreadFactory());
+ evictionTimerTask.init(evictionConfig.getWakeupInterval(), configuration.getRuntimeConfig().getEvictionTimerThreadFactory(), regionsRegistry);
}
@Stop
@@ -293,10 +293,6 @@
Region r = regionsRegistry.remove(fqn);
if (r == null) return false;
- if (isUsingEvictions() && r.getEvictionRegionConfig() != null)
- {
- evictionTimerTask.removeRegionToProcess(r);
- }
return true;
}
@@ -573,7 +569,7 @@
case ANY:
return true;
case EVICTION:
- return r.getEvictionRegionConfig() != null && evictionTimerTask.isRegionRegisteredForProcessing(r);
+ return r.getEvictionRegionConfig() != null;
case MARSHALLING:
return r.isActive() && r.getClassLoader() != null;
}
@@ -644,7 +640,7 @@
// we need to loop thru the regions and only select specific regions to rtn.
for (Region r : regionsRegistry.values())
{
- if ((type == EVICTION && r.getEvictionRegionConfig() != null && evictionTimerTask.isRegionRegisteredForProcessing(r)) ||
+ if ((type == EVICTION && r.getEvictionRegionConfig() != null) ||
(type == MARSHALLING && r.isActive() && r.getClassLoader() != null))
regions.add(r);
}
@@ -739,7 +735,7 @@
*/
public void startEvictionThread()
{
- evictionTimerTask.init(evictionConfig.getWakeupInterval(), configuration.getRuntimeConfig().getEvictionTimerThreadFactory());
+ evictionTimerTask.init(evictionConfig.getWakeupInterval(), configuration.getRuntimeConfig().getEvictionTimerThreadFactory(), regionsRegistry);
}
/**
Modified: core/trunk/src/main/java/org/jboss/cache/eviction/EvictionTimerTask.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/eviction/EvictionTimerTask.java 2008-10-31 11:21:10 UTC (rev 7043)
+++ core/trunk/src/main/java/org/jboss/cache/eviction/EvictionTimerTask.java 2008-10-31 12:06:57 UTC (rev 7044)
@@ -24,9 +24,8 @@
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.jboss.cache.Region;
-import org.jboss.cache.util.concurrent.ConcurrentHashSet;
+import org.jboss.cache.RegionRegistry;
-import java.util.Set;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.ThreadFactory;
@@ -44,7 +43,7 @@
{
private Log log = LogFactory.getLog(EvictionTimerTask.class);
- private final Set<Region> processedRegions;
+ private RegionRegistry regionsRegistry;
private static AtomicInteger tcount = new AtomicInteger();
private long wakeupInterval;
ScheduledExecutorService scheduledExecutor;
@@ -52,50 +51,18 @@
public EvictionTimerTask()
{
- // synchronized set because we need to maintain thread safety
- // for dynamic configuration purposes.
- processedRegions = new ConcurrentHashSet<Region>();
task = new Task();
}
- public void init(long wakeupInterval, ThreadFactory evictionThreadFactory)
+ public void init(long wakeupInterval, ThreadFactory evictionThreadFactory, RegionRegistry rr)
{
if (log.isTraceEnabled())
log.trace("Creating a new eviction listener with wakeupInterval millis set at " + wakeupInterval);
+ this.regionsRegistry = rr;
this.wakeupInterval = wakeupInterval;
start(evictionThreadFactory);
}
- /**
- * Add a MarshRegion to process by the Eviction Thread.
- *
- * @param region MarshRegion to process.
- */
- public void addRegionToProcess(Region region)
- {
- processedRegions.add(region);
- }
-
- /**
- * Remove a MarshRegion to process from the Eviction thread.
- *
- * @param region
- */
- public void removeRegionToProcess(Region region)
- {
- processedRegions.remove(region);
- }
-
- public boolean isRegionRegisteredForProcessing(Region region)
- {
- return processedRegions.contains(region);
- }
-
- public Set<Region> getProcessedRegions()
- {
- return processedRegions;
- }
-
public void stop()
{
if (log.isDebugEnabled()) log.debug("Stopping eviction timer");
@@ -127,38 +94,33 @@
};
scheduledExecutor = Executors.newSingleThreadScheduledExecutor(tf);
- scheduledExecutor.scheduleWithFixedDelay(task, wakeupInterval, wakeupInterval, TimeUnit.MILLISECONDS);
+ scheduledExecutor.scheduleWithFixedDelay(task, wakeupInterval / 2, wakeupInterval, TimeUnit.MILLISECONDS);
}
private void processRegions()
{
- synchronized (processedRegions)
- {
- if (log.isTraceEnabled()) log.trace("Processing eviction regions " + processedRegions);
+ if (log.isTraceEnabled()) log.trace("Processing eviction regions " + regionsRegistry.keySet());
- for (Region region : processedRegions)
- {
+ for (Region region : regionsRegistry.values())
+ {
+ if (region.getEvictionRegionConfig() != null)
handleRegion(region);
- }
}
}
private void handleRegion(Region region)
{
- synchronized (region)
+ try
{
- try
- {
- region.processEvictionQueues();
- }
- catch (EvictionException e)
- {
- log.error("run(): error processing eviction with exception: " + e.toString()
- + " will reset the eviction queue list.");
- region.resetEvictionQueues();
- log.debug("trace", e);
- }
+ region.processEvictionQueues();
}
+ catch (EvictionException e)
+ {
+ log.error("run(): error processing eviction with exception: " + e.toString()
+ + " will reset the eviction queue list.");
+ region.resetEvictionQueues();
+ log.debug("trace", e);
+ }
}
public class Task implements Runnable
Modified: core/trunk/src/test/java/org/jboss/cache/util/internals/EvictionController.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/util/internals/EvictionController.java 2008-10-31 11:21:10 UTC (rev 7043)
+++ core/trunk/src/test/java/org/jboss/cache/util/internals/EvictionController.java 2008-10-31 12:06:57 UTC (rev 7044)
@@ -5,6 +5,7 @@
import org.jboss.cache.Fqn;
import org.jboss.cache.Region;
import org.jboss.cache.RegionManager;
+import org.jboss.cache.RegionRegistry;
import org.jboss.cache.config.EvictionConfig;
import org.jboss.cache.config.EvictionRegionConfig;
import org.jboss.cache.eviction.EvictionTimerTask;
@@ -31,6 +32,7 @@
RegionManager regionManager;
EvictionTimerTask timerTask;
long originalWakeupInterval;
+ RegionRegistry rr;
public EvictionController(Cache cache)
{
@@ -45,6 +47,7 @@
{
throw new IllegalStateException("No timer task!!!");
}
+ rr = this.cache.getComponentRegistry().getComponent(RegionRegistry.class);
stopEvictionThread();
originalWakeupInterval = cache.getConfiguration().getEvictionConfig().getWakeupInterval();
}
@@ -75,7 +78,7 @@
if (restartEvictionTimerTask)
{
- timerTask.init(originalWakeupInterval, null);
+ timerTask.init(originalWakeupInterval, null, rr);
}
}
@@ -109,9 +112,9 @@
*/
public void evictRegion(String regionStr) throws Exception
{
- for (Region region : timerTask.getProcessedRegions())
+ for (Region region : rr.values())
{
- if (region.getFqn().equals(Fqn.fromString(regionStr)))
+ if (region.getEvictionRegionConfig() != null && region.getFqn().equals(Fqn.fromString(regionStr)))
{
Method method = EvictionTimerTask.class.getDeclaredMethod("handleRegion", Region.class);
method.setAccessible(true);
@@ -150,7 +153,7 @@
{
throw new RuntimeException(e);
}
- timerTask.init(originalWakeupInterval, null);
+ timerTask.init(originalWakeupInterval, null, rr);
return s;
}