You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by tv...@apache.org on 2016/02/07 19:23:33 UTC
svn commit: r1729001 - in /commons/proper/jcs/trunk/commons-jcs-core/src:
main/java/org/apache/commons/jcs/engine/
main/java/org/apache/commons/jcs/utils/struct/
test/java/org/apache/commons/jcs/utils/struct/
Author: tv
Date: Sun Feb 7 18:23:33 2016
New Revision: 1729001
URL: http://svn.apache.org/viewvc?rev=1729001&view=rev
Log:
Replace BoundedQueue with JDK implementation
Removed:
commons/proper/jcs/trunk/commons-jcs-core/src/main/java/org/apache/commons/jcs/utils/struct/BoundedQueue.java
commons/proper/jcs/trunk/commons-jcs-core/src/test/java/org/apache/commons/jcs/utils/struct/BoundedQueueUnitTest.java
Modified:
commons/proper/jcs/trunk/commons-jcs-core/src/main/java/org/apache/commons/jcs/engine/ZombieCacheServiceNonLocal.java
Modified: commons/proper/jcs/trunk/commons-jcs-core/src/main/java/org/apache/commons/jcs/engine/ZombieCacheServiceNonLocal.java
URL: http://svn.apache.org/viewvc/commons/proper/jcs/trunk/commons-jcs-core/src/main/java/org/apache/commons/jcs/engine/ZombieCacheServiceNonLocal.java?rev=1729001&r1=1729000&r2=1729001&view=diff
==============================================================================
--- commons/proper/jcs/trunk/commons-jcs-core/src/main/java/org/apache/commons/jcs/engine/ZombieCacheServiceNonLocal.java (original)
+++ commons/proper/jcs/trunk/commons-jcs-core/src/main/java/org/apache/commons/jcs/engine/ZombieCacheServiceNonLocal.java Sun Feb 7 18:23:33 2016
@@ -19,18 +19,18 @@ package org.apache.commons.jcs.engine;
* under the License.
*/
-import org.apache.commons.jcs.engine.behavior.ICacheElement;
-import org.apache.commons.jcs.engine.behavior.ICacheServiceNonLocal;
-import org.apache.commons.jcs.utils.struct.BoundedQueue;
-import org.apache.commons.jcs.utils.timing.ElapsedTimer;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-
import java.io.IOException;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;
+import java.util.concurrent.ConcurrentLinkedQueue;
+
+import org.apache.commons.jcs.engine.behavior.ICacheElement;
+import org.apache.commons.jcs.engine.behavior.ICacheServiceNonLocal;
+import org.apache.commons.jcs.utils.timing.ElapsedTimer;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
/**
* Zombie adapter for the non local cache services. It just balks if there is no queue configured.
@@ -52,14 +52,14 @@ public class ZombieCacheServiceNonLocal<
private int maxQueueSize = 0;
/** The queue */
- private final BoundedQueue<ZombieEvent> queue;
+ private final ConcurrentLinkedQueue<ZombieEvent> queue;
/**
* Default.
*/
public ZombieCacheServiceNonLocal()
{
- queue = new BoundedQueue<ZombieEvent>( 0 );
+ queue = new ConcurrentLinkedQueue<ZombieEvent>();
}
/**
@@ -70,7 +70,7 @@ public class ZombieCacheServiceNonLocal<
public ZombieCacheServiceNonLocal( int maxQueueSize )
{
this.maxQueueSize = maxQueueSize;
- queue = new BoundedQueue<ZombieEvent>( maxQueueSize );
+ queue = new ConcurrentLinkedQueue<ZombieEvent>();
}
/**
@@ -83,6 +83,15 @@ public class ZombieCacheServiceNonLocal<
return queue.size();
}
+ private void addQueue(ZombieEvent event)
+ {
+ queue.add(event);
+ if (queue.size() > maxQueueSize)
+ {
+ queue.poll(); // drop oldest entry
+ }
+ }
+
/**
* Adds an update event to the queue if the maxSize is greater than 0;
* <p>
@@ -95,7 +104,7 @@ public class ZombieCacheServiceNonLocal<
if ( maxQueueSize > 0 )
{
PutEvent<K, V> event = new PutEvent<K, V>( item, listenerId );
- queue.add( event );
+ addQueue( event );
}
// Zombies have no inner life
}
@@ -113,7 +122,7 @@ public class ZombieCacheServiceNonLocal<
if ( maxQueueSize > 0 )
{
RemoveEvent<K> event = new RemoveEvent<K>( cacheName, key, listenerId );
- queue.add( event );
+ addQueue( event );
}
// Zombies have no inner life
}
@@ -130,7 +139,7 @@ public class ZombieCacheServiceNonLocal<
if ( maxQueueSize > 0 )
{
RemoveAllEvent event = new RemoveAllEvent( cacheName, listenerId );
- queue.add( event );
+ addQueue( event );
}
// Zombies have no inner life
}
@@ -212,7 +221,7 @@ public class ZombieCacheServiceNonLocal<
cnt++;
// for each item, call the appropriate service method
- ZombieEvent event = queue.take();
+ ZombieEvent event = queue.poll();
if ( event instanceof PutEvent )
{