Return-Path: X-Original-To: apmail-commons-commits-archive@minotaur.apache.org Delivered-To: apmail-commons-commits-archive@minotaur.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id D418B11B8F for ; Sun, 11 May 2014 14:32:15 +0000 (UTC) Received: (qmail 50548 invoked by uid 500); 11 May 2014 12:43:32 -0000 Delivered-To: apmail-commons-commits-archive@commons.apache.org Received: (qmail 50364 invoked by uid 500); 11 May 2014 12:43:32 -0000 Mailing-List: contact commits-help@commons.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@commons.apache.org Delivered-To: mailing list commits@commons.apache.org Received: (qmail 50219 invoked by uid 99); 11 May 2014 12:43:32 -0000 Received: from Unknown (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Sun, 11 May 2014 12:43:32 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=5.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Sun, 11 May 2014 12:43:31 +0000 Received: from eris.apache.org (localhost [127.0.0.1]) by eris.apache.org (Postfix) with ESMTP id C7782238889B; Sun, 11 May 2014 12:43:07 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: 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 Date: Sun, 11 May 2014 12:43:07 -0000 To: commits@commons.apache.org From: rmannibucau@apache.org X-Mailer: svnmailer-1.0.9 Message-Id: <20140511124307.C7782238889B@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org 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 0) { - pool.submit(new EvictionThread(this, evictionPause)); + final CacheEvictor 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(this, evictionPause, evictor)); } final Factory> cacheLoaderFactory = configuration.getCacheLoaderFactory(); @@ -176,7 +194,12 @@ public class JCSCache implements Runnable + private static class EvictionThread implements Runnable { private final long pause; - private final JCSCache cache; + private final JCSCache cache; + private final CacheEvictor evictor; - public EvictionThread(final JCSCache cache, final long evictionPause) + public EvictionThread(final JCSCache cache, final long evictionPause, final CacheEvictor evictor) { this.cache = cache; this.pause = evictionPause; + this.evictor = evictor; } @Override @@ -924,7 +949,14 @@ public class JCSCache 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 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 +{ + void evict(JCSCache delegate); +}