You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by rm...@apache.org on 2014/05/11 14:43:07 UTC
svn commit: r1593785 - in
/commons/proper/jcs/trunk/commons-jcs-jcache/src/main/java/org/apache/commons/jcs/jcache:
JCSCache.java JCSElement.java spi/ spi/CacheEvictor.java
Author: rmannibucau
Date: Sun May 11 12:43:07 2014
New Revision: 1593785
URL: http://svn.apache.org/r1593785
Log:
adding API CacheEvictor
Added:
commons/proper/jcs/trunk/commons-jcs-jcache/src/main/java/org/apache/commons/jcs/jcache/spi/
commons/proper/jcs/trunk/commons-jcs-jcache/src/main/java/org/apache/commons/jcs/jcache/spi/CacheEvictor.java
Modified:
commons/proper/jcs/trunk/commons-jcs-jcache/src/main/java/org/apache/commons/jcs/jcache/JCSCache.java
commons/proper/jcs/trunk/commons-jcs-jcache/src/main/java/org/apache/commons/jcs/jcache/JCSElement.java
Modified: commons/proper/jcs/trunk/commons-jcs-jcache/src/main/java/org/apache/commons/jcs/jcache/JCSCache.java
URL: http://svn.apache.org/viewvc/commons/proper/jcs/trunk/commons-jcs-jcache/src/main/java/org/apache/commons/jcs/jcache/JCSCache.java?rev=1593785&r1=1593784&r2=1593785&view=diff
==============================================================================
--- commons/proper/jcs/trunk/commons-jcs-jcache/src/main/java/org/apache/commons/jcs/jcache/JCSCache.java (original)
+++ commons/proper/jcs/trunk/commons-jcs-jcache/src/main/java/org/apache/commons/jcs/jcache/JCSCache.java Sun May 11 12:43:07 2014
@@ -23,6 +23,7 @@ import org.apache.commons.jcs.jcache.jmx
import org.apache.commons.jcs.jcache.jmx.JMXs;
import org.apache.commons.jcs.jcache.lang.Subsitutor;
import org.apache.commons.jcs.jcache.proxy.ExceptionWrapperHandler;
+import org.apache.commons.jcs.jcache.spi.CacheEvictor;
import org.apache.commons.jcs.jcache.thread.DaemonThreadFactory;
import javax.cache.Cache;
@@ -110,7 +111,24 @@ public class JCSCache<K, V, C extends Co
final long evictionPause = Long.parseLong(properties.getProperty(cacheName + ".evictionPause", properties.getProperty("evictionPause", "30000")));
if (evictionPause > 0)
{
- pool.submit(new EvictionThread<K>(this, evictionPause));
+ final CacheEvictor<K, V> evictor;
+ final String evictorClass = property(properties, cacheName, "evictor", null);
+ if (evictorClass != null)
+ {
+ try
+ {
+ evictor = CacheEvictor.class.cast(classLoader.loadClass(evictorClass).newInstance());
+ }
+ catch (final Exception e)
+ {
+ throw new IllegalStateException(e);
+ }
+ }
+ else
+ {
+ evictor = null;
+ }
+ pool.submit(new EvictionThread<K, V>(this, evictionPause, evictor));
}
final Factory<CacheLoader<K, V>> cacheLoaderFactory = configuration.getCacheLoaderFactory();
@@ -176,7 +194,12 @@ public class JCSCache<K, V, C extends Co
private static String property(final Properties properties, final String cacheName, final String name, final String defaultValue)
{
- return SUBSTITUTOR.substitute(properties.getProperty(cacheName + "." + name, properties.getProperty(name, defaultValue)));
+ final String property = properties.getProperty(cacheName + "." + name, properties.getProperty(name, defaultValue));
+ if (property == null)
+ {
+ return null;
+ }
+ return SUBSTITUTOR.substitute(property);
}
private void assertNotClosed()
@@ -908,15 +931,17 @@ public class JCSCache<K, V, C extends Co
JMXs.unregister(cacheStatsObjectName);
}
- private static class EvictionThread<K> implements Runnable
+ private static class EvictionThread<K, V> implements Runnable
{
private final long pause;
- private final JCSCache<K, ?, ?> cache;
+ private final JCSCache<K, V, ?> cache;
+ private final CacheEvictor<K, V> evictor;
- public EvictionThread(final JCSCache<K, ?, ?> cache, final long evictionPause)
+ public EvictionThread(final JCSCache<K, V, ?> cache, final long evictionPause, final CacheEvictor<K, V> evictor)
{
this.cache = cache;
this.pause = evictionPause;
+ this.evictor = evictor;
}
@Override
@@ -924,7 +949,14 @@ public class JCSCache<K, V, C extends Co
{
while (!cache.isClosed())
{
- cache.evict();
+ if (evictor != null)
+ {
+ evictor.evict(cache);
+ }
+ else
+ {
+ cache.evict();
+ }
try
{
Thread.sleep(pause);
Modified: commons/proper/jcs/trunk/commons-jcs-jcache/src/main/java/org/apache/commons/jcs/jcache/JCSElement.java
URL: http://svn.apache.org/viewvc/commons/proper/jcs/trunk/commons-jcs-jcache/src/main/java/org/apache/commons/jcs/jcache/JCSElement.java?rev=1593785&r1=1593784&r2=1593785&view=diff
==============================================================================
--- commons/proper/jcs/trunk/commons-jcs-jcache/src/main/java/org/apache/commons/jcs/jcache/JCSElement.java (original)
+++ commons/proper/jcs/trunk/commons-jcs-jcache/src/main/java/org/apache/commons/jcs/jcache/JCSElement.java Sun May 11 12:43:07 2014
@@ -24,7 +24,7 @@ import java.io.Serializable;
public class JCSElement<V> implements Serializable
{
private final V element;
- private volatile long end;
+ private volatile long end = Long.MIN_VALUE;
public JCSElement(final V element, final Duration duration)
{
@@ -44,6 +44,11 @@ public class JCSElement<V> implements Se
public void update(final Duration duration)
{
+ if (end != Long.MIN_VALUE && duration == null)
+ {
+ return;
+ }
+
if (duration == null || duration.isEternal())
{
end = -1;
Added: commons/proper/jcs/trunk/commons-jcs-jcache/src/main/java/org/apache/commons/jcs/jcache/spi/CacheEvictor.java
URL: http://svn.apache.org/viewvc/commons/proper/jcs/trunk/commons-jcs-jcache/src/main/java/org/apache/commons/jcs/jcache/spi/CacheEvictor.java?rev=1593785&view=auto
==============================================================================
--- commons/proper/jcs/trunk/commons-jcs-jcache/src/main/java/org/apache/commons/jcs/jcache/spi/CacheEvictor.java (added)
+++ commons/proper/jcs/trunk/commons-jcs-jcache/src/main/java/org/apache/commons/jcs/jcache/spi/CacheEvictor.java Sun May 11 12:43:07 2014
@@ -0,0 +1,26 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.commons.jcs.jcache.spi;
+
+import org.apache.commons.jcs.jcache.JCSCache;
+
+public interface CacheEvictor<K, V>
+{
+ void evict(JCSCache<K, V, ?> delegate);
+}
Re: svn commit: r1593785 - in /commons/proper/jcs/trunk/commons-jcs-jcache/src/main/java/org/apache/commons/jcs/jcache:
JCSCache.java JCSElement.java spi/ spi/CacheEvictor.java
Posted by Romain Manni-Bucau <rm...@gmail.com>.
Hi Thomas,
I'm not happy of this CacheEvictor at all. Hopefully we'll be able to
remove it when merging JCS and JCache if possible.
Romain Manni-Bucau
Twitter: @rmannibucau
Blog: http://rmannibucau.wordpress.com/
LinkedIn: http://fr.linkedin.com/in/rmannibucau
Github: https://github.com/rmannibucau
2014-05-11 17:36 GMT+02:00 Thomas Vandahl <tv...@apache.org>:
> On 11.05.14 14:43, rmannibucau@apache.org wrote:
>> Author: rmannibucau
>> Date: Sun May 11 12:43:07 2014
>> New Revision: 1593785
>>
>> URL: http://svn.apache.org/r1593785
>> Log:
>> adding API CacheEvictor
>>
>
> Hi Romain,
>
> AFAICS, you are currently creating several JCache replacements for
> already existing JCS features. Are you sure this is the best way to go?
>
> Bye, Thomas.
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
> For additional commands, e-mail: dev-help@commons.apache.org
>
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
For additional commands, e-mail: dev-help@commons.apache.org
Re: svn commit: r1593785 - in /commons/proper/jcs/trunk/commons-jcs-jcache/src/main/java/org/apache/commons/jcs/jcache:
JCSCache.java JCSElement.java spi/ spi/CacheEvictor.java
Posted by Thomas Vandahl <tv...@apache.org>.
On 11.05.14 14:43, rmannibucau@apache.org wrote:
> Author: rmannibucau
> Date: Sun May 11 12:43:07 2014
> New Revision: 1593785
>
> URL: http://svn.apache.org/r1593785
> Log:
> adding API CacheEvictor
>
Hi Romain,
AFAICS, you are currently creating several JCache replacements for
already existing JCS features. Are you sure this is the best way to go?
Bye, Thomas.
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
For additional commands, e-mail: dev-help@commons.apache.org