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 C974010DCC for ; Mon, 21 Dec 2015 13:19:21 +0000 (UTC) Received: (qmail 48039 invoked by uid 500); 21 Dec 2015 13:19:21 -0000 Delivered-To: apmail-commons-commits-archive@commons.apache.org Received: (qmail 47964 invoked by uid 500); 21 Dec 2015 13:19:21 -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 47955 invoked by uid 99); 21 Dec 2015 13:19:21 -0000 Received: from Unknown (HELO spamd3-us-west.apache.org) (209.188.14.142) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 21 Dec 2015 13:19:21 +0000 Received: from localhost (localhost [127.0.0.1]) by spamd3-us-west.apache.org (ASF Mail Server at spamd3-us-west.apache.org) with ESMTP id 25E0B180441 for ; Mon, 21 Dec 2015 13:19:21 +0000 (UTC) X-Virus-Scanned: Debian amavisd-new at spamd3-us-west.apache.org X-Spam-Flag: NO X-Spam-Score: 1.247 X-Spam-Level: * X-Spam-Status: No, score=1.247 tagged_above=-999 required=6.31 tests=[KAM_ASCII_DIVIDERS=0.8, KAM_LAZY_DOMAIN_SECURITY=1, RP_MATCHES_RCVD=-0.554, URIBL_BLOCKED=0.001] autolearn=disabled Received: from mx1-eu-west.apache.org ([10.40.0.8]) by localhost (spamd3-us-west.apache.org [10.40.0.10]) (amavisd-new, port 10024) with ESMTP id 5w6yMw2nd-2F for ; Mon, 21 Dec 2015 13:19:13 +0000 (UTC) Received: from mailrelay1-us-west.apache.org (mailrelay1-us-west.apache.org [209.188.14.139]) by mx1-eu-west.apache.org (ASF Mail Server at mx1-eu-west.apache.org) with ESMTP id D4F4520273 for ; Mon, 21 Dec 2015 13:19:12 +0000 (UTC) Received: from svn01-us-west.apache.org (svn.apache.org [10.41.0.6]) by mailrelay1-us-west.apache.org (ASF Mail Server at mailrelay1-us-west.apache.org) with ESMTP id 01718E0428 for ; Mon, 21 Dec 2015 13:19:11 +0000 (UTC) Received: from svn01-us-west.apache.org (localhost [127.0.0.1]) by svn01-us-west.apache.org (ASF Mail Server at svn01-us-west.apache.org) with ESMTP id A414C3A0051 for ; Mon, 21 Dec 2015 13:19:11 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r1721147 - in /commons/proper/jcs/trunk/commons-jcs-sandbox/filecache/src/main/java/org/apache/commons/jcs/auxiliary/disk/file: FileDiskCache.java FileDiskCacheAttributes.java FileDiskCacheFactory.java FileDiskCacheManager.java Date: Mon, 21 Dec 2015 13:19:11 -0000 To: commits@commons.apache.org From: tv@apache.org X-Mailer: svnmailer-1.0.9 Message-Id: <20151221131911.A414C3A0051@svn01-us-west.apache.org> Author: tv Date: Mon Dec 21 13:19:11 2015 New Revision: 1721147 URL: http://svn.apache.org/viewvc?rev=1721147&view=rev Log: Make code compile again Modified: commons/proper/jcs/trunk/commons-jcs-sandbox/filecache/src/main/java/org/apache/commons/jcs/auxiliary/disk/file/FileDiskCache.java commons/proper/jcs/trunk/commons-jcs-sandbox/filecache/src/main/java/org/apache/commons/jcs/auxiliary/disk/file/FileDiskCacheAttributes.java commons/proper/jcs/trunk/commons-jcs-sandbox/filecache/src/main/java/org/apache/commons/jcs/auxiliary/disk/file/FileDiskCacheFactory.java commons/proper/jcs/trunk/commons-jcs-sandbox/filecache/src/main/java/org/apache/commons/jcs/auxiliary/disk/file/FileDiskCacheManager.java Modified: commons/proper/jcs/trunk/commons-jcs-sandbox/filecache/src/main/java/org/apache/commons/jcs/auxiliary/disk/file/FileDiskCache.java URL: http://svn.apache.org/viewvc/commons/proper/jcs/trunk/commons-jcs-sandbox/filecache/src/main/java/org/apache/commons/jcs/auxiliary/disk/file/FileDiskCache.java?rev=1721147&r1=1721146&r2=1721147&view=diff ============================================================================== --- commons/proper/jcs/trunk/commons-jcs-sandbox/filecache/src/main/java/org/apache/commons/jcs/auxiliary/disk/file/FileDiskCache.java (original) +++ commons/proper/jcs/trunk/commons-jcs-sandbox/filecache/src/main/java/org/apache/commons/jcs/auxiliary/disk/file/FileDiskCache.java Mon Dec 21 13:19:11 2015 @@ -19,16 +19,6 @@ package org.apache.commons.jcs.auxiliary * under the License. */ -import org.apache.commons.jcs.auxiliary.AuxiliaryCacheAttributes; -import org.apache.commons.jcs.auxiliary.disk.AbstractDiskCache; -import org.apache.commons.jcs.engine.behavior.ICacheElement; -import org.apache.commons.jcs.engine.behavior.IElementSerializer; -import org.apache.commons.jcs.engine.logging.behavior.ICacheEvent; -import org.apache.commons.jcs.engine.logging.behavior.ICacheEventLogger; -import org.apache.commons.jcs.utils.timing.SleepUtil; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; - import java.io.BufferedOutputStream; import java.io.File; import java.io.FileInputStream; @@ -36,10 +26,19 @@ import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; -import java.io.Serializable; import java.util.Map; import java.util.Set; +import org.apache.commons.jcs.auxiliary.AuxiliaryCacheAttributes; +import org.apache.commons.jcs.auxiliary.disk.AbstractDiskCache; +import org.apache.commons.jcs.engine.behavior.ICacheElement; +import org.apache.commons.jcs.engine.behavior.IElementSerializer; +import org.apache.commons.jcs.engine.logging.behavior.ICacheEvent; +import org.apache.commons.jcs.engine.logging.behavior.ICacheEventLogger; +import org.apache.commons.jcs.utils.timing.SleepUtil; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; + /** * This disk cache writes each item to a separate file. This is for regions with very few items, * perhaps big ones. @@ -47,12 +46,9 @@ import java.util.Set; * This is a fairly simple implementation. All the disk writing is handled right here. It's not * clear that anything more complicated is needed. */ -public class FileDiskCache +public class FileDiskCache extends AbstractDiskCache { - /** Don't change */ - private static final long serialVersionUID = 1L; - /** The logger. */ private static final Log log = LogFactory.getLog( FileDiskCache.class ); @@ -88,7 +84,7 @@ public class FileDiskCache File file( KK key ) + protected File file( KK key ) { StringBuilder fileNameBuffer = new StringBuilder(); @@ -203,17 +199,17 @@ public class FileDiskCache cacheEvent = createICacheEvent( cacheName, "none", ICacheEventLogger.DISPOSE_EVENT ); + ICacheEvent cacheEvent = createICacheEvent( getCacheName(), "none", ICacheEventLogger.DISPOSE_EVENT ); try { - if ( !alive ) + if ( !isAlive() ) { log.error( logCacheName + "Not alive and dispose was called, directgory: " + getDirectory() ); return; } // Prevents any interaction with the cache while we're shutting down. - alive = false; + setAlive(false); // TODO consider giving up the handle on the directory. if ( log.isInfoEnabled() ) @@ -273,7 +269,7 @@ public class FileDiskCache boolean _processRemove( T key ) + private boolean _processRemove( T key ) throws IOException { File file = file( key ); Modified: commons/proper/jcs/trunk/commons-jcs-sandbox/filecache/src/main/java/org/apache/commons/jcs/auxiliary/disk/file/FileDiskCacheAttributes.java URL: http://svn.apache.org/viewvc/commons/proper/jcs/trunk/commons-jcs-sandbox/filecache/src/main/java/org/apache/commons/jcs/auxiliary/disk/file/FileDiskCacheAttributes.java?rev=1721147&r1=1721146&r2=1721147&view=diff ============================================================================== --- commons/proper/jcs/trunk/commons-jcs-sandbox/filecache/src/main/java/org/apache/commons/jcs/auxiliary/disk/file/FileDiskCacheAttributes.java (original) +++ commons/proper/jcs/trunk/commons-jcs-sandbox/filecache/src/main/java/org/apache/commons/jcs/auxiliary/disk/file/FileDiskCacheAttributes.java Mon Dec 21 13:19:11 2015 @@ -19,7 +19,6 @@ package org.apache.commons.jcs.auxiliary * under the License. */ -import org.apache.commons.jcs.auxiliary.AuxiliaryCacheAttributes; import org.apache.commons.jcs.auxiliary.disk.AbstractDiskCacheAttributes; /** @@ -60,25 +59,6 @@ public class FileDiskCacheAttributes private boolean touchOnGet = DEFAULT_TOUCH_ON_GET; /** - * Returns a copy of the attributes. - *

- * @return AuxiliaryCacheAttributes - */ - @Override - public AuxiliaryCacheAttributes copy() - { - try - { - return (AuxiliaryCacheAttributes) this.clone(); - } - catch ( Exception e ) - { - // swallow - } - return this; - } - - /** * @param maxNumberOfFiles the maxNumberOfFiles to set */ public void setMaxNumberOfFiles( int maxNumberOfFiles ) Modified: commons/proper/jcs/trunk/commons-jcs-sandbox/filecache/src/main/java/org/apache/commons/jcs/auxiliary/disk/file/FileDiskCacheFactory.java URL: http://svn.apache.org/viewvc/commons/proper/jcs/trunk/commons-jcs-sandbox/filecache/src/main/java/org/apache/commons/jcs/auxiliary/disk/file/FileDiskCacheFactory.java?rev=1721147&r1=1721146&r2=1721147&view=diff ============================================================================== --- commons/proper/jcs/trunk/commons-jcs-sandbox/filecache/src/main/java/org/apache/commons/jcs/auxiliary/disk/file/FileDiskCacheFactory.java (original) +++ commons/proper/jcs/trunk/commons-jcs-sandbox/filecache/src/main/java/org/apache/commons/jcs/auxiliary/disk/file/FileDiskCacheFactory.java Mon Dec 21 13:19:11 2015 @@ -27,8 +27,6 @@ import org.apache.commons.jcs.engine.log import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; -import java.io.Serializable; - /** Create Disk File Caches */ public class FileDiskCacheFactory implements AuxiliaryCacheFactory @@ -54,7 +52,7 @@ public class FileDiskCacheFactory * @return AuxiliaryCache */ @Override - public FileDiskCache createCache( + public FileDiskCache createCache( AuxiliaryCacheAttributes attr, ICompositeCacheManager cacheMgr, ICacheEventLogger cacheEventLogger, IElementSerializer elementSerializer ) { @@ -98,4 +96,24 @@ public class FileDiskCacheFactory { this.name = name; } + + /** + * @see org.apache.commons.jcs.auxiliary.AuxiliaryCacheFactory#initialize() + */ + @Override + public void initialize() + { + // TODO Auto-generated method stub + + } + + /** + * @see org.apache.commons.jcs.auxiliary.AuxiliaryCacheFactory#dispose() + */ + @Override + public void dispose() + { + // TODO Auto-generated method stub + + } } Modified: commons/proper/jcs/trunk/commons-jcs-sandbox/filecache/src/main/java/org/apache/commons/jcs/auxiliary/disk/file/FileDiskCacheManager.java URL: http://svn.apache.org/viewvc/commons/proper/jcs/trunk/commons-jcs-sandbox/filecache/src/main/java/org/apache/commons/jcs/auxiliary/disk/file/FileDiskCacheManager.java?rev=1721147&r1=1721146&r2=1721147&view=diff ============================================================================== --- commons/proper/jcs/trunk/commons-jcs-sandbox/filecache/src/main/java/org/apache/commons/jcs/auxiliary/disk/file/FileDiskCacheManager.java (original) +++ commons/proper/jcs/trunk/commons-jcs-sandbox/filecache/src/main/java/org/apache/commons/jcs/auxiliary/disk/file/FileDiskCacheManager.java Mon Dec 21 13:19:11 2015 @@ -19,35 +19,40 @@ package org.apache.commons.jcs.auxiliary * under the License. */ -import org.apache.commons.jcs.auxiliary.disk.AbstractDiskCacheManager; +import java.util.concurrent.ConcurrentHashMap; +import java.util.concurrent.ConcurrentMap; +import java.util.concurrent.locks.Lock; +import java.util.concurrent.locks.ReentrantLock; + import org.apache.commons.jcs.engine.behavior.IElementSerializer; import org.apache.commons.jcs.engine.logging.behavior.ICacheEventLogger; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; -import java.io.Serializable; -import java.util.Map; -import java.util.concurrent.ConcurrentHashMap; - /** * This is a non singleton. It creates caches on a per region basis. */ public class FileDiskCacheManager - extends AbstractDiskCacheManager { - /** Don't change */ - private static final long serialVersionUID = -4153287154512264626L; - /** The logger */ private static final Log log = LogFactory.getLog( FileDiskCacheManager.class ); /** Each region has an entry here. */ - private final Map> caches = - new ConcurrentHashMap>(); + private final ConcurrentMap> caches = + new ConcurrentHashMap>(); + + /** Lock cache initialization */ + private final Lock lock = new ReentrantLock(); /** User configurable attributes */ private final FileDiskCacheAttributes defaultCacheAttributes; + /** Event logger */ + private final ICacheEventLogger eventLogger; + + /** Custom serializer */ + private final IElementSerializer elementSerializer; + /** * Constructor for the DiskFileCacheManager object *

@@ -59,8 +64,8 @@ public class FileDiskCacheManager IElementSerializer elementSerializer ) { this.defaultCacheAttributes = defaultCacheAttributes; - setElementSerializer( elementSerializer ); - setCacheEventLogger( cacheEventLogger ); + this.elementSerializer = elementSerializer; + this.eventLogger = cacheEventLogger; } /** @@ -69,10 +74,9 @@ public class FileDiskCacheManager * @param cacheName Name that will be used when creating attributes. * @return A cache. */ - @Override - public FileDiskCache getCache( String cacheName ) + public FileDiskCache getCache( String cacheName ) { - FileDiskCacheAttributes cacheAttributes = (FileDiskCacheAttributes) defaultCacheAttributes.copy(); + FileDiskCacheAttributes cacheAttributes = (FileDiskCacheAttributes) defaultCacheAttributes.clone(); cacheAttributes.setCacheName( cacheName ); @@ -86,7 +90,8 @@ public class FileDiskCacheManager * @param cacheAttributes Attributes the cache should have. * @return A cache, either from the existing set or newly created. */ - public FileDiskCache getCache( FileDiskCacheAttributes cacheAttributes ) + @SuppressWarnings("unchecked") // Need to cast because of common map for all caches + public FileDiskCache getCache( FileDiskCacheAttributes cacheAttributes ) { FileDiskCache cache = null; @@ -94,23 +99,30 @@ public class FileDiskCacheManager log.debug( "Getting cache named: " + cacheName ); - synchronized ( caches ) - { - // Try to load the cache from the set that have already been - // created. This only looks at the name attribute. + // Try to load the cache from the set that have already been + // created. This only looks at the name attribute. + cache = (FileDiskCache) caches.get( cacheName ); - @SuppressWarnings("unchecked") // Need to cast because of common map for all caches - FileDiskCache fileDiskCache = (FileDiskCache) caches.get( cacheName ); - cache = fileDiskCache; + if (cache == null) + { + lock.lock(); - // If it was not found, create a new one using the supplied - // attributes + try + { + cache = (FileDiskCache) caches.get( cacheName ); - if ( cache == null ) + // If it was not found, create a new one using the supplied + // attributes + if ( cache == null ) + { + cache = new FileDiskCache( cacheAttributes, elementSerializer ); + cache.setCacheEventLogger( eventLogger ); + caches.put( cacheName, cache ); + } + } + finally { - cache = new FileDiskCache( cacheAttributes, getElementSerializer() ); - cache.setCacheEventLogger( getCacheEventLogger() ); - caches.put( cacheName, cache ); + lock.unlock(); } }