Author: nfilotto
Date: 2010-02-16 11:53:30 -0500 (Tue, 16 Feb 2010)
New Revision: 1841
Modified:
kernel/trunk/exo.kernel.component.cache/src/main/java/org/exoplatform/services/cache/ExoCacheConfig.java
kernel/trunk/exo.kernel.component.ext.cache.impl.jboss.v3/src/main/java/org/exoplatform/services/cache/impl/jboss/AbstractExoCache.java
kernel/trunk/exo.kernel.component.ext.cache.impl.jboss.v3/src/test/java/org/exoplatform/services/cache/impl/jboss/TestAbstractExoCache.java
Log:
EXOJCR-520: JBC implementation of ExoCache: Avoid to go through the interceptor chain when
it is possible
ExoCacheConfig: The live time field is always expressed in seconds
AbstractExoCache: We know go though the interceptor chain when it is needed
TestAbstractExoCache: Test on evict even has been added
Modified:
kernel/trunk/exo.kernel.component.cache/src/main/java/org/exoplatform/services/cache/ExoCacheConfig.java
===================================================================
---
kernel/trunk/exo.kernel.component.cache/src/main/java/org/exoplatform/services/cache/ExoCacheConfig.java 2010-02-16
16:00:38 UTC (rev 1840)
+++
kernel/trunk/exo.kernel.component.cache/src/main/java/org/exoplatform/services/cache/ExoCacheConfig.java 2010-02-16
16:53:30 UTC (rev 1841)
@@ -43,7 +43,7 @@
private int maxSize;
/**
- * The amount of time (in milliseconds) an element is not written or
+ * The amount of time (in seconds) an element is not written or
* read before it is evicted.
*/
private long liveTime;
@@ -105,7 +105,7 @@
public void setLiveTime(long period)
{
- liveTime = period * 1000;
+ liveTime = period;
}
public boolean isDistributed()
Modified:
kernel/trunk/exo.kernel.component.ext.cache.impl.jboss.v3/src/main/java/org/exoplatform/services/cache/impl/jboss/AbstractExoCache.java
===================================================================
---
kernel/trunk/exo.kernel.component.ext.cache.impl.jboss.v3/src/main/java/org/exoplatform/services/cache/impl/jboss/AbstractExoCache.java 2010-02-16
16:00:38 UTC (rev 1840)
+++
kernel/trunk/exo.kernel.component.ext.cache.impl.jboss.v3/src/main/java/org/exoplatform/services/cache/impl/jboss/AbstractExoCache.java 2010-02-16
16:53:30 UTC (rev 1841)
@@ -35,8 +35,9 @@
import org.jboss.cache.notifications.annotation.NodeEvicted;
import org.jboss.cache.notifications.annotation.NodeModified;
import org.jboss.cache.notifications.annotation.NodeRemoved;
-import org.jboss.cache.notifications.event.EventImpl;
-import org.jboss.cache.notifications.event.NodeEvent;
+import org.jboss.cache.notifications.event.NodeEvictedEvent;
+import org.jboss.cache.notifications.event.NodeModifiedEvent;
+import org.jboss.cache.notifications.event.NodeRemovedEvent;
import java.io.Serializable;
import java.util.LinkedList;
@@ -303,7 +304,9 @@
throw new NullPointerException("No null cache key accepted");
}
final Fqn<Serializable> fqn = getFqn(name);
- final NodeSPI<K, V> node = cache.getNode(fqn);
+ // We use the methods peek and getDirect to avoid going through the interceptor
chain
+ // in order to avoid to visit nodes that were about to be evicted
+ final NodeSPI<K, V> node = cache.peek(fqn, false);
V result = null;
if (node != null)
{
@@ -342,7 +345,9 @@
continue;
}
final K key = getKey(node);
- final V value = node.get(key);
+ // We use the method getDirect to avoid going through the interceptor chain
+ // in order to avoid to visit nodes that were about to be evicted
+ final V value = ((NodeSPI<K, V>)node).getDirect(key);
ObjectCacheInfo<V> info = new ObjectCacheInfo<V>()
{
public V get()
@@ -527,47 +532,37 @@
{
@NodeEvicted
- public void nodeEvicted(NodeEvent ne)
+ public void nodeEvicted(NodeEvictedEvent ne)
{
if (ne.isPre())
{
- // Cannot give the value since
- // since it disturbs the eviction
- // algorithms
- onExpire(getKey(ne.getFqn()), null);
+ final NodeSPI<K, V> node = cache.peek(ne.getFqn(), true);
+ final K key = getKey(ne.getFqn());
+ onExpire(key, node == null ? null : node.getDirect(key));
}
}
+ @SuppressWarnings("unchecked")
@NodeRemoved
- public void nodeRemoved(NodeEvent ne)
+ public void nodeRemoved(NodeRemovedEvent ne)
{
if (ne.isPre() && !ne.isOriginLocal())
{
- final Node<K, V> node = cache.getNode(ne.getFqn());
final K key = getKey(ne.getFqn());
- onRemove(key, node.get(key));
+ final Map<K, V> data = ne.getData();
+ onRemove(key, data == null ? null : data.get(key));
}
}
@SuppressWarnings("unchecked")
@NodeModified
- public void nodeModified(NodeEvent ne)
+ public void nodeModified(NodeModifiedEvent ne)
{
if (!ne.isOriginLocal() && !ne.isPre())
{
final K key = getKey(ne.getFqn());
- if (ne instanceof EventImpl)
- {
- EventImpl evt = (EventImpl)ne;
- Map<K, V> data = evt.getData();
- if (data != null)
- {
- onPut(key, data.get(key));
- return;
- }
- }
- final Node<K, V> node = cache.getNode(ne.getFqn());
- onPut(key, node.get(key));
+ final Map<K, V> data = ne.getData();
+ onPut(key, data == null ? null : data.get(key));
}
}
}
Modified:
kernel/trunk/exo.kernel.component.ext.cache.impl.jboss.v3/src/test/java/org/exoplatform/services/cache/impl/jboss/TestAbstractExoCache.java
===================================================================
---
kernel/trunk/exo.kernel.component.ext.cache.impl.jboss.v3/src/test/java/org/exoplatform/services/cache/impl/jboss/TestAbstractExoCache.java 2010-02-16
16:00:38 UTC (rev 1840)
+++
kernel/trunk/exo.kernel.component.ext.cache.impl.jboss.v3/src/test/java/org/exoplatform/services/cache/impl/jboss/TestAbstractExoCache.java 2010-02-16
16:53:30 UTC (rev 1841)
@@ -236,12 +236,14 @@
ExoCacheConfig config = new ExoCacheConfig();
config.setName("MyCacheDistributed");
config.setMaxSize(5);
- config.setLiveTime(1000);
+ config.setLiveTime(1);
+ config.setImplementation("LRU");
config.setDistributed(true);
ExoCacheConfig config2 = new ExoCacheConfig();
config2.setName("MyCacheDistributed2");
config2.setMaxSize(5);
- config2.setLiveTime(1000);
+ config2.setLiveTime(1);
+ config2.setImplementation("LRU");
config2.setDistributed(true);
AbstractExoCache<Serializable, Object> cache1 =
(AbstractExoCache<Serializable, Object>)factory.createCache(config);
MyCacheListener listener1 = new MyCacheListener();
@@ -379,6 +381,7 @@
cache1.putMap(values);
assertEquals(2, cache1.getCacheSize());
assertEquals(2, cache2.getCacheSize());
+ assertEquals(1, cache3.getCacheSize());
assertEquals(5, listener1.put);
assertEquals(5, listener2.put);
assertEquals(1, listener3.put);
@@ -391,6 +394,28 @@
assertEquals(1, listener1.clearCache);
assertEquals(0, listener2.clearCache);
assertEquals(0, listener3.clearCache);
+ assertEquals(0, listener1.expire);
+ assertEquals(0, listener2.expire);
+ assertEquals(0, listener3.expire);
+ Thread.sleep(1600);
+ assertEquals(0, cache1.getCacheSize());
+ assertEquals(0, cache2.getCacheSize());
+ assertEquals(0, cache3.getCacheSize());
+ assertEquals(5, listener1.put);
+ assertEquals(5, listener2.put);
+ assertEquals(1, listener3.put);
+ assertEquals(2, listener1.get);
+ assertEquals(4, listener2.get);
+ assertEquals(1, listener3.get);
+ assertEquals(2, listener1.remove);
+ assertEquals(2, listener2.remove);
+ assertEquals(0, listener3.remove);
+ assertEquals(1, listener1.clearCache);
+ assertEquals(0, listener2.clearCache);
+ assertEquals(0, listener3.clearCache);
+ assertEquals(2, listener1.expire);
+ assertEquals(2, listener2.expire);
+ assertEquals(1, listener3.expire);
}
finally
{