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 2026/02/17 17:57:23 UTC
(commons-jcs) 06/12: Remove duplicate code
This is an automated email from the ASF dual-hosted git repository.
tv pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-jcs.git
commit 15df71a9c813b9c74096290f7b5395cd6f211cf6
Author: Thomas Vandahl <tv...@apache.org>
AuthorDate: Tue Feb 17 14:51:52 2026 +0100
Remove duplicate code
---
.../apache/commons/jcs4/access/CacheAccess.java | 12 +--
.../jcs4/auxiliary/AbstractAuxiliaryCache.java | 35 +++++++++
.../AbstractAuxiliaryCacheEventLogging.java | 2 +-
.../auxiliary/AbstractCacheEventLogSupport.java | 8 +-
.../commons/jcs4/auxiliary/AuxiliaryCache.java | 10 ++-
.../jcs4/auxiliary/disk/AbstractDiskCache.java | 59 +++++----------
.../jcs4/auxiliary/disk/PurgatoryElement.java | 16 ++--
.../jcs4/auxiliary/disk/block/BlockDiskCache.java | 40 +++++-----
.../disk/block/BlockDiskCacheFactory.java | 5 +-
.../auxiliary/disk/indexed/IndexedDiskCache.java | 49 ++++++-------
.../jcs4/auxiliary/disk/jdbc/JDBCDiskCache.java | 20 ++---
.../lateral/socket/tcp/LateralTCPCache.java | 60 ++++++---------
.../socket/tcp/LateralTCPCacheNoWaitFacade.java | 33 +--------
.../remote/AbstractRemoteAuxiliaryCache.java | 85 +++++++---------------
.../remote/AbstractRemoteCacheNoWaitFacade.java | 22 +-----
.../commons/jcs4/auxiliary/remote/RemoteCache.java | 14 ++--
.../jcs4/auxiliary/remote/RemoteCacheNoWait.java | 10 ---
.../remote/http/client/RemoteHttpCache.java | 17 +----
.../remote/http/client/RemoteHttpCacheMonitor.java | 3 +-
.../http/server/AbstractRemoteCacheService.java | 57 ++++-----------
.../remote/http/server/RemoteHttpCacheService.java | 11 +--
.../remote/value/RemoteCacheResponse.java | 2 +-
.../jcs4/engine/behavior/ICacheService.java | 12 +--
.../jcs4/engine/control/CompositeCache.java | 3 +-
.../memory/soft/SoftReferenceMemoryCache.java | 2 +-
.../commons/jcs4/access/CacheAccessUnitTest.java | 3 +-
.../commons/jcs4/auxiliary/MockAuxiliaryCache.java | 9 ---
.../auxiliary/disk/AbstractDiskCacheUnitTest.java | 12 +--
.../auxiliary/remote/RemoteCacheClientTester.java | 3 +-
.../control/CompositeCacheDiskUsageUnitTest.java | 10 ---
30 files changed, 215 insertions(+), 409 deletions(-)
diff --git a/commons-jcs4-core/src/main/java/org/apache/commons/jcs4/access/CacheAccess.java b/commons-jcs4-core/src/main/java/org/apache/commons/jcs4/access/CacheAccess.java
index e8965c61..bb641b03 100644
--- a/commons-jcs4-core/src/main/java/org/apache/commons/jcs4/access/CacheAccess.java
+++ b/commons-jcs4-core/src/main/java/org/apache/commons/jcs4/access/CacheAccess.java
@@ -30,8 +30,6 @@ import java.util.stream.Collectors;
import org.apache.commons.jcs4.access.behavior.ICacheAccess;
import org.apache.commons.jcs4.access.exception.CacheException;
import org.apache.commons.jcs4.access.exception.InvalidArgumentException;
-import org.apache.commons.jcs4.access.exception.InvalidHandleException;
-import org.apache.commons.jcs4.access.exception.ObjectExistsException;
import org.apache.commons.jcs4.engine.CacheElement;
import org.apache.commons.jcs4.engine.behavior.ICacheElement;
import org.apache.commons.jcs4.engine.behavior.IElementAttributes;
@@ -278,15 +276,14 @@ public class CacheAccess<K, V>
*
* @param key Key object will be stored with
* @param value Object to store
- * @throws CacheException and ObjectExistsException is thrown if the item is already in the
- * cache.
+ * @throws CacheException is thrown if the item is already in the cache.
*/
@Override
public void putSafe( final K key, final V value )
{
if ( getCacheControl().get( key ) != null )
{
- throw new ObjectExistsException( "putSafe failed. Object exists in the cache for key [" + key
+ throw new CacheException( "putSafe failed. Object exists in the cache for key [" + key
+ "]. Remove first or use a non-safe put to override the value." );
}
put( key, value );
@@ -309,7 +306,7 @@ public class CacheAccess<K, V>
*
* @param name Key of object to reset attributes for
* @param attr New attributes for the object
- * @throws InvalidHandleException if the item does not exist.
+ * @throws CacheException if the item does not exist.
*/
@Override
public void resetElementAttributes( final K name, final IElementAttributes attr )
@@ -318,14 +315,13 @@ public class CacheAccess<K, V>
if ( element == null )
{
- throw new InvalidHandleException( "Object for name [" + name + "] is not in the cache" );
+ throw new CacheException( "Object for name [" + name + "] is not in the cache" );
}
// Although it will work currently, don't assume pass by reference here,
// i.e. don't do this:
// element.setElementAttributes( attr );
// Another reason to call put is to force the changes to be distributed.
-
put( element.key(), element.value(), attr );
}
}
diff --git a/commons-jcs4-core/src/main/java/org/apache/commons/jcs4/auxiliary/AbstractAuxiliaryCache.java b/commons-jcs4-core/src/main/java/org/apache/commons/jcs4/auxiliary/AbstractAuxiliaryCache.java
index 71234d4e..46c4b97a 100644
--- a/commons-jcs4-core/src/main/java/org/apache/commons/jcs4/auxiliary/AbstractAuxiliaryCache.java
+++ b/commons-jcs4-core/src/main/java/org/apache/commons/jcs4/auxiliary/AbstractAuxiliaryCache.java
@@ -43,6 +43,9 @@ public abstract class AbstractAuxiliaryCache<K, V>
/** Key matcher used by the getMatching API */
private IKeyMatcher<K> keyMatcher = new KeyMatcherPatternImpl<>();
+ /** Cache configuration */
+ private AuxiliaryCacheAttributes auxiliaryCacheAttributes;
+
/**
* Gets the item from the cache.
*
@@ -73,6 +76,28 @@ public abstract class AbstractAuxiliaryCache<K, V>
return this.keyMatcher;
}
+ /**
+ * Returns the cache configuration.
+ *
+ * @return cache configuration
+ */
+ @Override
+ public AuxiliaryCacheAttributes getAuxiliaryCacheAttributes()
+ {
+ return auxiliaryCacheAttributes;
+ }
+
+ /**
+ * Gets the extra info for the event log.
+ *
+ * @return the eventLogSourceName
+ */
+ @Override
+ protected String getEventLogSourceName()
+ {
+ return getAuxiliaryCacheAttributes().getName();
+ }
+
/**
* Gets multiple items from the cache based on the given set of keys.
*
@@ -133,4 +158,14 @@ public abstract class AbstractAuxiliaryCache<K, V>
this.keyMatcher = keyMatcher;
}
}
+
+ /**
+ * Set the cache configuration
+ *
+ * @param auxiliaryCacheAttributes the auxiliaryCacheAttributes to set
+ */
+ public void setAuxiliaryCacheAttributes(AuxiliaryCacheAttributes auxiliaryCacheAttributes)
+ {
+ this.auxiliaryCacheAttributes = auxiliaryCacheAttributes;
+ }
}
diff --git a/commons-jcs4-core/src/main/java/org/apache/commons/jcs4/auxiliary/AbstractAuxiliaryCacheEventLogging.java b/commons-jcs4-core/src/main/java/org/apache/commons/jcs4/auxiliary/AbstractAuxiliaryCacheEventLogging.java
index a0c2203e..096833d4 100644
--- a/commons-jcs4-core/src/main/java/org/apache/commons/jcs4/auxiliary/AbstractAuxiliaryCacheEventLogging.java
+++ b/commons-jcs4-core/src/main/java/org/apache/commons/jcs4/auxiliary/AbstractAuxiliaryCacheEventLogging.java
@@ -351,5 +351,5 @@ public abstract class AbstractAuxiliaryCacheEventLogging<K, V>
*
* @return disk location
*/
- public abstract String getEventLoggingExtraInfo();
+ protected abstract String getEventLoggingExtraInfo();
}
diff --git a/commons-jcs4-core/src/main/java/org/apache/commons/jcs4/auxiliary/AbstractCacheEventLogSupport.java b/commons-jcs4-core/src/main/java/org/apache/commons/jcs4/auxiliary/AbstractCacheEventLogSupport.java
index c803c973..1f7666a6 100644
--- a/commons-jcs4-core/src/main/java/org/apache/commons/jcs4/auxiliary/AbstractCacheEventLogSupport.java
+++ b/commons-jcs4-core/src/main/java/org/apache/commons/jcs4/auxiliary/AbstractCacheEventLogSupport.java
@@ -73,7 +73,7 @@ public abstract class AbstractCacheEventLogSupport<K, V>
String regionName = item == null ? null : item.cacheName();
K key = item == null ? null : item.key();
- return createICacheEvent(getAuxiliaryCacheAttributes().getName(), regionName,
+ return createICacheEvent(getEventLogSourceName(), regionName,
eventType, eventLoggingExtraInfo.get(), key);
}
@@ -94,7 +94,7 @@ public abstract class AbstractCacheEventLogSupport<K, V>
return new CacheEvent<>();
}
- return createICacheEvent(getAuxiliaryCacheAttributes().getName(), regionName,
+ return createICacheEvent(getEventLogSourceName(), regionName,
eventType, eventLoggingExtraInfo.get(), key);
}
@@ -111,9 +111,9 @@ public abstract class AbstractCacheEventLogSupport<K, V>
/**
* Gets the extra info for the event log.
*
- * @return IP, or disk location, etc.
+ * @return the eventLogSourceName
*/
- public abstract AuxiliaryCacheAttributes getAuxiliaryCacheAttributes();
+ protected abstract String getEventLogSourceName();
/**
* Logs an event if an event logger is configured.
diff --git a/commons-jcs4-core/src/main/java/org/apache/commons/jcs4/auxiliary/AuxiliaryCache.java b/commons-jcs4-core/src/main/java/org/apache/commons/jcs4/auxiliary/AuxiliaryCache.java
index 02362eae..e6f730ae 100644
--- a/commons-jcs4-core/src/main/java/org/apache/commons/jcs4/auxiliary/AuxiliaryCache.java
+++ b/commons-jcs4-core/src/main/java/org/apache/commons/jcs4/auxiliary/AuxiliaryCache.java
@@ -23,7 +23,6 @@ import java.io.IOException;
import java.util.Set;
import org.apache.commons.jcs4.engine.behavior.ICache;
-import org.apache.commons.jcs4.engine.stats.behavior.IStats;
/**
* Tag interface for auxiliary caches. Currently this provides no additional methods over what is in
@@ -54,8 +53,13 @@ public interface AuxiliaryCache<K, V>
Set<K> getKeySet() throws IOException;
/**
- * @return the historical and statistical data for a region's auxiliary cache.
+ * Returns the cache name.
+ *
+ * @return usually the region name.
*/
@Override
- IStats getStatistics();
+ default String getCacheName()
+ {
+ return getAuxiliaryCacheAttributes().getCacheName();
+ }
}
diff --git a/commons-jcs4-core/src/main/java/org/apache/commons/jcs4/auxiliary/disk/AbstractDiskCache.java b/commons-jcs4-core/src/main/java/org/apache/commons/jcs4/auxiliary/disk/AbstractDiskCache.java
index 3a88e335..ed760c6f 100644
--- a/commons-jcs4-core/src/main/java/org/apache/commons/jcs4/auxiliary/disk/AbstractDiskCache.java
+++ b/commons-jcs4-core/src/main/java/org/apache/commons/jcs4/auxiliary/disk/AbstractDiskCache.java
@@ -31,6 +31,7 @@ import java.util.concurrent.locks.ReentrantReadWriteLock;
import org.apache.commons.jcs4.auxiliary.AbstractAuxiliaryCacheEventLogging;
import org.apache.commons.jcs4.auxiliary.AuxiliaryCache;
+import org.apache.commons.jcs4.auxiliary.AuxiliaryCacheAttributes;
import org.apache.commons.jcs4.auxiliary.disk.behavior.IDiskCacheAttributes;
import org.apache.commons.jcs4.engine.CacheEventQueueFactory;
import org.apache.commons.jcs4.engine.CacheInfo;
@@ -214,9 +215,6 @@ public abstract class AbstractDiskCache<K, V>
/** The logger */
private static final Log log = Log.getLog( AbstractDiskCache.class );
- /** Generic disk cache attributes */
- private final IDiskCacheAttributes diskCacheAttributes;
-
/**
* Map where elements are stored between being added to this cache and actually spooled to disk.
* This allows puts to the disk cache to return quickly, and the more expensive operation of
@@ -239,9 +237,6 @@ public abstract class AbstractDiskCache<K, V>
*/
private final AtomicBoolean alive = new AtomicBoolean();
- /** Every cache will have a name, subclasses must set this when they are initialized. */
- private final String cacheName;
-
/** DEBUG: Keeps a count of the number of purgatory hits for debug messages */
private final AtomicInteger purgHits = new AtomicInteger();
@@ -257,17 +252,16 @@ public abstract class AbstractDiskCache<K, V>
*
* @param attr
*/
- protected AbstractDiskCache( final IDiskCacheAttributes attr )
+ protected AbstractDiskCache(final AuxiliaryCacheAttributes attr)
{
- this.diskCacheAttributes = attr;
- this.cacheName = attr.getCacheName();
+ setAuxiliaryCacheAttributes(attr);
// create queue
final CacheEventQueueFactory<K, V> fact = new CacheEventQueueFactory<>();
this.cacheEventQueue = fact.createCacheEventQueue(
- new MyCacheListener(), CacheInfo.INSTANCE.listenerId(), cacheName,
- diskCacheAttributes.getEventQueuePoolName(),
- diskCacheAttributes.getEventQueueType() );
+ new MyCacheListener(), CacheInfo.INSTANCE.listenerId(), getCacheName(),
+ attr.getEventQueuePoolName(),
+ attr.getEventQueueType() );
// create purgatory
initPurgatory();
@@ -293,7 +287,8 @@ public abstract class AbstractDiskCache<K, V>
log.info( "In dispose, destroying event queue." );
// wait for dispose and then quit if not done.
- cacheEventQueue.destroy(this.diskCacheAttributes.getShutdownSpoolTimeLimit());
+ int spoolTimeLimit = getAuxiliaryCacheAttributes().getShutdownSpoolTimeLimit();
+ cacheEventQueue.destroy(spoolTimeLimit);
// Invoke any implementation specific disposal code
// need to handle the disposal first.
@@ -346,7 +341,7 @@ public abstract class AbstractDiskCache<K, V>
// will allow the memory size = 0 setting to work well.
log.debug( "Found element in purgatory, cacheName: {0}, key: {1}",
- cacheName, key );
+ getCacheName(), key );
return pe.cacheElement();
}
@@ -366,16 +361,6 @@ public abstract class AbstractDiskCache<K, V>
return null;
}
- /**
- * @return the region name.
- * @see ICache#getCacheName
- */
- @Override
- public String getCacheName()
- {
- return cacheName;
- }
-
/**
* @see org.apache.commons.jcs4.engine.behavior.ICacheType#getCacheType
* @return Always returns DISK_CACHE since subclasses should all be of that type.
@@ -387,21 +372,14 @@ public abstract class AbstractDiskCache<K, V>
}
/**
- * This is used by the event logging.
- *
- * @return the location of the disk, either path or ip.
- */
- protected abstract String getDiskLocation();
-
- /**
- * Gets the extra info for the event log.
+ * Returns the cache configuration.
*
- * @return disk location
+ * @return cache configuration
*/
@Override
- public String getEventLoggingExtraInfo()
+ public IDiskCacheAttributes getAuxiliaryCacheAttributes()
{
- return getDiskLocation();
+ return (IDiskCacheAttributes) super.getAuxiliaryCacheAttributes();
}
/**
@@ -502,10 +480,10 @@ public abstract class AbstractDiskCache<K, V>
{
synchronized (this)
{
- if ( diskCacheAttributes.getMaxPurgatorySize() >= 0 )
+ int maxPurgatorySize = getAuxiliaryCacheAttributes().getMaxPurgatorySize();
+ if (maxPurgatorySize >= 0)
{
- purgatory = Collections.synchronizedMap(
- new LRUMap<>( diskCacheAttributes.getMaxPurgatorySize()));
+ purgatory = Collections.synchronizedMap(new LRUMap<>(maxPurgatorySize));
}
else
{
@@ -575,7 +553,8 @@ public abstract class AbstractDiskCache<K, V>
public final void removeAll()
throws IOException
{
- if ( this.diskCacheAttributes.isAllowRemoveAll() )
+ boolean allowRemoveAll = getAuxiliaryCacheAttributes().isAllowRemoveAll();
+ if (allowRemoveAll)
{
// Replace purgatory with a new empty hashtable
initPurgatory();
@@ -614,7 +593,7 @@ public abstract class AbstractDiskCache<K, V>
throws IOException
{
log.debug( "Putting element in purgatory, cacheName: {0}, key: {1}",
- () -> cacheName, cacheElement::key);
+ this::getCacheName, cacheElement::key);
try
{
diff --git a/commons-jcs4-core/src/main/java/org/apache/commons/jcs4/auxiliary/disk/PurgatoryElement.java b/commons-jcs4-core/src/main/java/org/apache/commons/jcs4/auxiliary/disk/PurgatoryElement.java
index 7cd67cd7..378eff36 100644
--- a/commons-jcs4-core/src/main/java/org/apache/commons/jcs4/auxiliary/disk/PurgatoryElement.java
+++ b/commons-jcs4-core/src/main/java/org/apache/commons/jcs4/auxiliary/disk/PurgatoryElement.java
@@ -52,8 +52,8 @@ public record PurgatoryElement<K, V>(
}
/**
- * @return cacheElement.getCacheName();
- * @see ICacheElement#getCacheName
+ * @return cacheElement.cacheName();
+ * @see ICacheElement#cacheName
*/
@Override
public String cacheName()
@@ -62,8 +62,8 @@ public record PurgatoryElement<K, V>(
}
/**
- * @return cacheElement.getElementAttributes();
- * @see ICacheElement#getElementAttributes
+ * @return cacheElement.elementAttributes();
+ * @see ICacheElement#elementAttributes
*/
@Override
public IElementAttributes elementAttributes()
@@ -72,8 +72,8 @@ public record PurgatoryElement<K, V>(
}
/**
- * @return cacheElement.getKey();
- * @see ICacheElement#getKey
+ * @return cacheElement.key();
+ * @see ICacheElement#key
*/
@Override
public K key()
@@ -82,8 +82,8 @@ public record PurgatoryElement<K, V>(
}
/**
- * @return cacheElement.getVal();
- * @see ICacheElement#getVal
+ * @return cacheElement.value();
+ * @see ICacheElement#value
*/
@Override
public V value()
diff --git a/commons-jcs4-core/src/main/java/org/apache/commons/jcs4/auxiliary/disk/block/BlockDiskCache.java b/commons-jcs4-core/src/main/java/org/apache/commons/jcs4/auxiliary/disk/block/BlockDiskCache.java
index 08f1107d..a776cea4 100644
--- a/commons-jcs4-core/src/main/java/org/apache/commons/jcs4/auxiliary/disk/block/BlockDiskCache.java
+++ b/commons-jcs4-core/src/main/java/org/apache/commons/jcs4/auxiliary/disk/block/BlockDiskCache.java
@@ -33,7 +33,6 @@ import java.util.concurrent.TimeUnit;
import java.util.concurrent.locks.ReentrantReadWriteLock;
import java.util.stream.Collectors;
-import org.apache.commons.jcs4.auxiliary.AuxiliaryCacheAttributes;
import org.apache.commons.jcs4.auxiliary.disk.AbstractDiskCache;
import org.apache.commons.jcs4.engine.behavior.ICacheElement;
import org.apache.commons.jcs4.engine.behavior.IElementSerializer;
@@ -64,9 +63,6 @@ public class BlockDiskCache<K, V>
/** The data access object */
private BlockDisk dataFile;
- /** Attributes governing the behavior of the block disk cache. */
- private final BlockDiskCacheAttributes blockDiskCacheAttributes;
-
/** The root directory for keys and data. */
private final File rootDirectory;
@@ -101,8 +97,6 @@ public class BlockDiskCache<K, V>
{
super( cacheAttributes );
setElementSerializer( elementSerializer );
-
- this.blockDiskCacheAttributes = cacheAttributes;
this.logCacheName = "Region [" + getCacheName() + "] ";
log.info("{0}: Constructing BlockDiskCache with attributes {1}", logCacheName, cacheAttributes );
@@ -115,10 +109,10 @@ public class BlockDiskCache<K, V>
try
{
- if ( this.blockDiskCacheAttributes.getBlockSizeBytes() > 0 )
+ if ( cacheAttributes.getBlockSizeBytes() > 0 )
{
this.dataFile = new BlockDisk( new File( rootDirectory, fileName + ".data" ),
- this.blockDiskCacheAttributes.getBlockSizeBytes(),
+ cacheAttributes.getBlockSizeBytes(),
getElementSerializer() );
}
else
@@ -127,7 +121,7 @@ public class BlockDiskCache<K, V>
getElementSerializer() );
}
- keyStore = new BlockDiskKeyStore<>( this.blockDiskCacheAttributes, this );
+ keyStore = new BlockDiskKeyStore<>( cacheAttributes, this );
final boolean alright = verifyDisk();
@@ -200,25 +194,25 @@ public class BlockDiskCache<K, V>
}
/**
- * Returns the attributes.
+ * Gets the extra info for the event log.
*
- * @see org.apache.commons.jcs4.auxiliary.AuxiliaryCache#getAuxiliaryCacheAttributes()
+ * @return extra info for the event log
*/
@Override
- public AuxiliaryCacheAttributes getAuxiliaryCacheAttributes()
+ protected String getEventLoggingExtraInfo()
{
- return this.blockDiskCacheAttributes;
+ return dataFile.getFilePath();
}
/**
- * This is used by the event logging.
+ * Returns the cache configuration.
*
- * @return the location of the disk, either path or ip.
+ * @return cache configuration
*/
@Override
- protected String getDiskLocation()
+ public BlockDiskCacheAttributes getAuxiliaryCacheAttributes()
{
- return dataFile.getFilePath();
+ return (BlockDiskCacheAttributes) super.getAuxiliaryCacheAttributes();
}
/**
@@ -419,10 +413,11 @@ public class BlockDiskCache<K, V>
{
object = this.dataFile.read( ded );
}
- } finally {
+ }
+ finally
+ {
storageLock.readLock().unlock();
}
-
}
catch ( final IOException ioe )
{
@@ -629,12 +624,11 @@ public class BlockDiskCache<K, V>
{
// add this region to the persistence thread.
// TODO we might need to stagger this a bit.
- if ( this.blockDiskCacheAttributes.getKeyPersistenceIntervalSeconds() > 0 )
+ long interval = getAuxiliaryCacheAttributes().getKeyPersistenceIntervalSeconds();
+ if ( interval > 0 )
{
future = scheduledExecutor.scheduleAtFixedRate(keyStore::saveKeys,
- this.blockDiskCacheAttributes.getKeyPersistenceIntervalSeconds(),
- this.blockDiskCacheAttributes.getKeyPersistenceIntervalSeconds(),
- TimeUnit.SECONDS);
+ interval, interval, TimeUnit.SECONDS);
}
}
diff --git a/commons-jcs4-core/src/main/java/org/apache/commons/jcs4/auxiliary/disk/block/BlockDiskCacheFactory.java b/commons-jcs4-core/src/main/java/org/apache/commons/jcs4/auxiliary/disk/block/BlockDiskCacheFactory.java
index 034bb1b0..c250e387 100644
--- a/commons-jcs4-core/src/main/java/org/apache/commons/jcs4/auxiliary/disk/block/BlockDiskCacheFactory.java
+++ b/commons-jcs4-core/src/main/java/org/apache/commons/jcs4/auxiliary/disk/block/BlockDiskCacheFactory.java
@@ -53,10 +53,9 @@ public class BlockDiskCacheFactory
final ICompositeCacheManager cacheMgr, final ICacheEventLogger cacheEventLogger,
final IElementSerializer elementSerializer, final IKeyMatcher<K> keyMatcher)
{
- final BlockDiskCacheAttributes idca = (BlockDiskCacheAttributes) iaca;
- log.debug("Creating DiskCache for attributes = {0}", idca);
+ log.debug("Creating DiskCache for attributes = {0}", iaca);
- final BlockDiskCache<K, V> cache = new BlockDiskCache<>( idca, elementSerializer );
+ final BlockDiskCache<K, V> cache = new BlockDiskCache<>((BlockDiskCacheAttributes)iaca, elementSerializer );
cache.setCacheEventLogger(cacheEventLogger);
cache.setKeyMatcher(keyMatcher);
diff --git a/commons-jcs4-core/src/main/java/org/apache/commons/jcs4/auxiliary/disk/indexed/IndexedDiskCache.java b/commons-jcs4-core/src/main/java/org/apache/commons/jcs4/auxiliary/disk/indexed/IndexedDiskCache.java
index 1336e83d..c9fb8370 100644
--- a/commons-jcs4-core/src/main/java/org/apache/commons/jcs4/auxiliary/disk/indexed/IndexedDiskCache.java
+++ b/commons-jcs4-core/src/main/java/org/apache/commons/jcs4/auxiliary/disk/indexed/IndexedDiskCache.java
@@ -36,7 +36,7 @@ import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.atomic.AtomicLong;
import java.util.concurrent.locks.ReentrantReadWriteLock;
-import org.apache.commons.jcs4.auxiliary.AuxiliaryCacheAttributes;
+import org.apache.commons.jcs4.auxiliary.AbstractAuxiliaryCacheEventLogging;
import org.apache.commons.jcs4.auxiliary.disk.AbstractDiskCache;
import org.apache.commons.jcs4.auxiliary.disk.behavior.IDiskCacheAttributes.DiskLimitType;
import org.apache.commons.jcs4.engine.behavior.ICacheElement;
@@ -48,6 +48,7 @@ import org.apache.commons.jcs4.engine.logging.behavior.ICacheEventLogger.CacheEv
import org.apache.commons.jcs4.engine.stats.Stats;
import org.apache.commons.jcs4.engine.stats.behavior.IStats;
import org.apache.commons.jcs4.log.Log;
+import org.apache.commons.jcs4.utils.serialization.StandardSerializer;
import org.apache.commons.jcs4.utils.struct.AbstractLRUMap;
import org.apache.commons.jcs4.utils.struct.LRUMap;
import org.apache.commons.jcs4.utils.timing.ElapsedTimer;
@@ -264,9 +265,6 @@ public class IndexedDiskCache<K, V> extends AbstractDiskCache<K, V>
/** RECYCLE BIN -- array of empty spots */
private final ConcurrentSkipListSet<IndexedDiskElementDescriptor> recycle;
- /** User configurable parameters */
- private final IndexedDiskCacheAttributes cattr;
-
/** How many slots have we recycled. */
private int recycleCnt;
@@ -295,7 +293,7 @@ public class IndexedDiskCache<K, V> extends AbstractDiskCache<K, V>
*/
public IndexedDiskCache(final IndexedDiskCacheAttributes cacheAttributes)
{
- this(cacheAttributes, null);
+ this(cacheAttributes, new StandardSerializer());
}
/**
@@ -309,10 +307,7 @@ public class IndexedDiskCache<K, V> extends AbstractDiskCache<K, V>
public IndexedDiskCache(final IndexedDiskCacheAttributes cattr, final IElementSerializer elementSerializer)
{
super(cattr);
-
setElementSerializer(elementSerializer);
-
- this.cattr = cattr;
this.maxKeySize = cattr.getMaxKeySize();
this.isRealTimeOptimizationEnabled = cattr.getOptimizeAtRemoveCount() > 0;
this.isShutdownOptimizationEnabled = cattr.isOptimizeOnShutdown();
@@ -651,13 +646,14 @@ public class IndexedDiskCache<K, V> extends AbstractDiskCache<K, V>
*/
protected void doOptimizeRealTime()
{
+ int optRemoveCount = getAuxiliaryCacheAttributes().getOptimizeAtRemoveCount();
if (isRealTimeOptimizationEnabled && !isOptimizing
- && removeCount++ >= cattr.getOptimizeAtRemoveCount())
+ && removeCount++ >= optRemoveCount)
{
isOptimizing = true;
log.info("{0}: Optimizing file. removeCount [{1}] OptimizeAtRemoveCount [{2}]",
- logCacheName, removeCount, cattr.getOptimizeAtRemoveCount());
+ logCacheName, removeCount, optRemoveCount);
if (currentOptimizationThread == null)
{
@@ -719,15 +715,6 @@ public class IndexedDiskCache<K, V> extends AbstractDiskCache<K, V>
}
}
- /**
- * @return the AuxiliaryCacheAttributes.
- */
- @Override
- public AuxiliaryCacheAttributes getAuxiliaryCacheAttributes()
- {
- return this.cattr;
- }
-
/**
* Returns the number of bytes that are free. When an item is removed, its length is recorded.
* When a spot is used form the recycle bin, the length of the item stored is recorded.
@@ -769,17 +756,27 @@ public class IndexedDiskCache<K, V> extends AbstractDiskCache<K, V>
}
/**
- * This is used by the event logging.
- * <p>
+ * Gets the extra info for the event log.
*
- * @return the location of the disk, either path or ip.
+ * @return extra info for the event log
*/
@Override
- protected String getDiskLocation()
+ protected String getEventLoggingExtraInfo()
{
return dataFile.getFilePath();
}
+ /**
+ * Returns the cache configuration.
+ *
+ * @return cache configuration
+ */
+ @Override
+ public IndexedDiskCacheAttributes getAuxiliaryCacheAttributes()
+ {
+ return (IndexedDiskCacheAttributes) super.getAuxiliaryCacheAttributes();
+ }
+
/**
* Return the keys in this cache.
* <p>
@@ -1222,7 +1219,7 @@ public class IndexedDiskCache<K, V> extends AbstractDiskCache<K, V>
public void processDispose()
{
final ICacheEvent<String> cacheEvent = createICacheEvent(getCacheName(), "none",
- CacheEventType.DISPOSE_EVENT, this::getDiskLocation);
+ CacheEventType.DISPOSE_EVENT, this::getEventLoggingExtraInfo);
try
{
final Thread t = new Thread(this::disposeInternal, "IndexedDiskCache-DisposalThread");
@@ -1250,7 +1247,7 @@ public class IndexedDiskCache<K, V> extends AbstractDiskCache<K, V>
*
* @param key
* @return ICacheElement<K, V> or null
- * @see AbstractDiskCache#doGet
+ * @see AbstractAuxiliaryCacheEventLogging#getWithEventLogging
*/
@Override
protected ICacheElement<K, V> processGet(final K key)
@@ -1389,7 +1386,7 @@ public class IndexedDiskCache<K, V> extends AbstractDiskCache<K, V>
{
final ICacheEvent<String> cacheEvent =
createICacheEvent(getCacheName(), "all", CacheEventType.REMOVEALL_EVENT,
- this::getDiskLocation);
+ this::getEventLoggingExtraInfo);
try
{
reset();
diff --git a/commons-jcs4-core/src/main/java/org/apache/commons/jcs4/auxiliary/disk/jdbc/JDBCDiskCache.java b/commons-jcs4-core/src/main/java/org/apache/commons/jcs4/auxiliary/disk/jdbc/JDBCDiskCache.java
index 7f1cb6e6..3a0d9708 100644
--- a/commons-jcs4-core/src/main/java/org/apache/commons/jcs4/auxiliary/disk/jdbc/JDBCDiskCache.java
+++ b/commons-jcs4-core/src/main/java/org/apache/commons/jcs4/auxiliary/disk/jdbc/JDBCDiskCache.java
@@ -32,7 +32,6 @@ import java.util.concurrent.atomic.AtomicInteger;
import javax.sql.DataSource;
-import org.apache.commons.jcs4.auxiliary.AuxiliaryCacheAttributes;
import org.apache.commons.jcs4.auxiliary.disk.AbstractDiskCache;
import org.apache.commons.jcs4.auxiliary.disk.jdbc.TableState.TableStateType;
import org.apache.commons.jcs4.auxiliary.disk.jdbc.dsfactory.DataSourceFactory;
@@ -208,7 +207,7 @@ public class JDBCDiskCache<K, V>
logApplicationEvent( getAuxiliaryCacheAttributes().getName(),
CacheEventType.DELETEEXPIRED_EVENT,
- "Deleted expired elements. URL: " + getDiskLocation() );
+ "Deleted expired elements. URL: " + getEventLoggingExtraInfo() );
}
else
{
@@ -218,7 +217,7 @@ public class JDBCDiskCache<K, V>
catch ( final SQLException e )
{
logError( getAuxiliaryCacheAttributes().getName(), CacheEventType.DELETEEXPIRED_EVENT,
- e.getMessage() + " URL: " + getDiskLocation() );
+ e.getMessage() + " URL: " + getEventLoggingExtraInfo() );
log.error( "Problem removing expired elements from the table.", e );
reset();
}
@@ -263,15 +262,6 @@ public class JDBCDiskCache<K, V>
return exists;
}
- /**
- * @return the AuxiliaryCacheAttributes.
- */
- @Override
- public AuxiliaryCacheAttributes getAuxiliaryCacheAttributes()
- {
- return this.getJdbcDiskCacheAttributes();
- }
-
/**
* Public so managers can access it.
* @return the dsFactory
@@ -288,7 +278,7 @@ public class JDBCDiskCache<K, V>
* @return the location of the disk, either path or ip.
*/
@Override
- protected String getDiskLocation()
+ protected String getEventLoggingExtraInfo()
{
return this.jdbcDiskCacheAttributes.getUrl();
}
@@ -363,7 +353,7 @@ public class JDBCDiskCache<K, V>
stats.addStatElement("Update Count", updateCount);
stats.addStatElement("Get Count", getCount);
stats.addStatElement("Get Matching Count", getMatchingCount);
- stats.addStatElement("DB URL", getDiskLocation());
+ stats.addStatElement("DB URL", getEventLoggingExtraInfo());
return stats;
}
@@ -513,7 +503,7 @@ public class JDBCDiskCache<K, V>
public void processDispose()
{
final ICacheEvent<K> cacheEvent = createICacheEvent( getCacheName(), null,
- CacheEventType.DISPOSE_EVENT, this::getDiskLocation);
+ CacheEventType.DISPOSE_EVENT, this::getEventLoggingExtraInfo);
try
{
diff --git a/commons-jcs4-core/src/main/java/org/apache/commons/jcs4/auxiliary/lateral/socket/tcp/LateralTCPCache.java b/commons-jcs4-core/src/main/java/org/apache/commons/jcs4/auxiliary/lateral/socket/tcp/LateralTCPCache.java
index 45944de9..e6bc843a 100644
--- a/commons-jcs4-core/src/main/java/org/apache/commons/jcs4/auxiliary/lateral/socket/tcp/LateralTCPCache.java
+++ b/commons-jcs4-core/src/main/java/org/apache/commons/jcs4/auxiliary/lateral/socket/tcp/LateralTCPCache.java
@@ -46,12 +46,6 @@ public class LateralTCPCache<K, V>
/** The logger. */
private static final Log log = Log.getLog( LateralTCPCache.class );
- /** Generalize this, use another interface */
- private final ILateralTCPCacheAttributes lateralCacheAttributes;
-
- /** The region name */
- final String cacheName;
-
/** Either http, socket.udp, or socket.tcp can set in config */
private ICacheServiceNonLocal<K, V> lateralCacheService;
@@ -67,10 +61,9 @@ public class LateralTCPCache<K, V>
*/
public LateralTCPCache( final ILateralTCPCacheAttributes cattr, final ICacheServiceNonLocal<K, V> lateral, final LateralCacheMonitor monitor )
{
- this.cacheName = cattr.getCacheName();
- this.lateralCacheAttributes = cattr;
this.lateralCacheService = lateral;
this.monitor = monitor;
+ setAuxiliaryCacheAttributes(cattr);
}
/**
@@ -111,18 +104,7 @@ public class LateralTCPCache<K, V>
@Override
public ILateralTCPCacheAttributes getAuxiliaryCacheAttributes()
{
- return lateralCacheAttributes;
- }
-
- /**
- * Gets the cacheName attribute of the LateralTCPCache object
- *
- * @return The cacheName value
- */
- @Override
- public String getCacheName()
- {
- return cacheName;
+ return (ILateralTCPCacheAttributes) super.getAuxiliaryCacheAttributes();
}
/**
@@ -155,12 +137,12 @@ public class LateralTCPCache<K, V>
{
try
{
- return lateralCacheService.getKeySet( cacheName );
+ return lateralCacheService.getKeySet( getCacheName() );
}
catch ( final IOException ex )
{
- handleException( ex, "Failed to get key set from " + lateralCacheAttributes.getCacheName() + "@"
- + lateralCacheAttributes );
+ handleException( ex, "Failed to get key set from " + getAuxiliaryCacheAttributes().getCacheName() + "@"
+ + getAuxiliaryCacheAttributes() );
}
return Collections.emptySet();
}
@@ -210,7 +192,7 @@ public class LateralTCPCache<K, V>
{
log.error( "Disabling lateral cache due to error {0}", msg, ex );
- lateralCacheService = new ZombieCacheServiceNonLocal<>( lateralCacheAttributes.getZombieQueueMaxSize() );
+ lateralCacheService = new ZombieCacheServiceNonLocal<>( getAuxiliaryCacheAttributes().getZombieQueueMaxSize() );
// may want to flush if region specifies
// Notify the cache monitor about the error, and kick off the recovery
// process.
@@ -237,13 +219,13 @@ public class LateralTCPCache<K, V>
try
{
- lateralCacheService.dispose( this.lateralCacheAttributes.getCacheName() );
+ lateralCacheService.dispose( this.getAuxiliaryCacheAttributes().getCacheName() );
// Should remove connection
}
catch ( final IOException ex )
{
log.error( "Couldn't dispose", ex );
- handleException( ex, "Failed to dispose " + lateralCacheAttributes.getCacheName() );
+ handleException( ex, "Failed to dispose " + getAuxiliaryCacheAttributes().getCacheName() );
}
}
@@ -260,16 +242,16 @@ public class LateralTCPCache<K, V>
{
ICacheElement<K, V> obj = null;
- if ( !this.lateralCacheAttributes.getPutOnlyMode() )
+ if ( !this.getAuxiliaryCacheAttributes().getPutOnlyMode() )
{
try
{
- obj = lateralCacheService.get( cacheName, key );
+ obj = lateralCacheService.get( getCacheName(), key );
}
catch ( final Exception e )
{
log.error( e );
- handleException( e, "Failed to get [" + key + "] from " + lateralCacheAttributes.getCacheName() + "@" + lateralCacheAttributes );
+ handleException( e, "Failed to get [" + key + "] from " + getAuxiliaryCacheAttributes().getCacheName() + "@" + getAuxiliaryCacheAttributes() );
}
}
@@ -288,16 +270,16 @@ public class LateralTCPCache<K, V>
{
final Map<K, ICacheElement<K, V>> map = Collections.emptyMap();
- if ( !this.lateralCacheAttributes.getPutOnlyMode() )
+ if ( !this.getAuxiliaryCacheAttributes().getPutOnlyMode() )
{
try
{
- return lateralCacheService.getMatching( cacheName, pattern );
+ return lateralCacheService.getMatching( getCacheName(), pattern );
}
catch ( final IOException e )
{
log.error( e );
- handleException( e, "Failed to getMatching [" + pattern + "] from " + lateralCacheAttributes.getCacheName() + "@" + lateralCacheAttributes );
+ handleException( e, "Failed to getMatching [" + pattern + "] from " + getAuxiliaryCacheAttributes().getCacheName() + "@" + getAuxiliaryCacheAttributes() );
}
}
@@ -320,11 +302,11 @@ public class LateralTCPCache<K, V>
try
{
- lateralCacheService.remove( cacheName, key, CacheInfo.INSTANCE.listenerId());
+ lateralCacheService.remove( getCacheName(), key, CacheInfo.INSTANCE.listenerId());
}
catch ( final IOException ex )
{
- handleException( ex, "Failed to remove " + key + " from " + lateralCacheAttributes.getCacheName() + "@" + lateralCacheAttributes );
+ handleException( ex, "Failed to remove " + key + " from " + getAuxiliaryCacheAttributes().getCacheName() + "@" + getAuxiliaryCacheAttributes() );
}
return false;
}
@@ -341,11 +323,11 @@ public class LateralTCPCache<K, V>
{
try
{
- lateralCacheService.removeAll( cacheName, CacheInfo.INSTANCE.listenerId());
+ lateralCacheService.removeAll( getCacheName(), CacheInfo.INSTANCE.listenerId());
}
catch ( final IOException ex )
{
- handleException( ex, "Failed to remove all from " + lateralCacheAttributes.getCacheName() + "@" + lateralCacheAttributes );
+ handleException( ex, "Failed to remove all from " + getAuxiliaryCacheAttributes().getCacheName() + "@" + getAuxiliaryCacheAttributes() );
}
}
@@ -370,7 +352,7 @@ public class LateralTCPCache<K, V>
}
catch ( final IOException ex )
{
- handleException( ex, "Failed to put [" + ce.key() + "] to " + ce.cacheName() + "@" + lateralCacheAttributes );
+ handleException( ex, "Failed to put [" + ce.key() + "] to " + ce.cacheName() + "@" + getAuxiliaryCacheAttributes() );
}
}
@@ -382,8 +364,8 @@ public class LateralTCPCache<K, V>
{
final StringBuilder buf = new StringBuilder();
buf.append( "\n LateralTCPCache " );
- buf.append( "\n Cache Name [" + lateralCacheAttributes.getCacheName() + "]" );
- buf.append( "\n cattr = [" + lateralCacheAttributes + "]" );
+ buf.append( "\n Cache Name [" + getCacheName() + "]" );
+ buf.append( "\n cattr = [" + getAuxiliaryCacheAttributes() + "]" );
return buf.toString();
}
}
diff --git a/commons-jcs4-core/src/main/java/org/apache/commons/jcs4/auxiliary/lateral/socket/tcp/LateralTCPCacheNoWaitFacade.java b/commons-jcs4-core/src/main/java/org/apache/commons/jcs4/auxiliary/lateral/socket/tcp/LateralTCPCacheNoWaitFacade.java
index 7f00eac8..121395bc 100644
--- a/commons-jcs4-core/src/main/java/org/apache/commons/jcs4/auxiliary/lateral/socket/tcp/LateralTCPCacheNoWaitFacade.java
+++ b/commons-jcs4-core/src/main/java/org/apache/commons/jcs4/auxiliary/lateral/socket/tcp/LateralTCPCacheNoWaitFacade.java
@@ -57,15 +57,9 @@ public class LateralTCPCacheNoWaitFacade<K, V>
*/
private final ConcurrentHashMap<String, LateralTCPCacheNoWait<K, V>> noWaitMap;
- /** The region name */
- private final String cacheName;
-
/** A cache listener */
private ILateralCacheListener<K, V> listener;
- /** User configurable attributes. */
- private final ILateralTCPCacheAttributes lateralCacheAttributes;
-
/** Disposed state of this facade */
private final AtomicBoolean disposed = new AtomicBoolean();
@@ -84,8 +78,7 @@ public class LateralTCPCacheNoWaitFacade<K, V>
this.listener = listener;
this.noWaitMap = new ConcurrentHashMap<>();
noWaits.forEach(noWait -> noWaitMap.put(noWait.getIdentityKey(), noWait));
- this.cacheName = cattr.getCacheName();
- this.lateralCacheAttributes = cattr;
+ setAuxiliaryCacheAttributes(cattr);
}
/**
@@ -170,26 +163,6 @@ public class LateralTCPCacheNoWaitFacade<K, V>
.orElse(null);
}
- /**
- * @return the AuxiliaryCacheAttributes.
- */
- @Override
- public ILateralTCPCacheAttributes getAuxiliaryCacheAttributes()
- {
- return this.lateralCacheAttributes;
- }
-
- /**
- * Gets the cacheName attribute of the LateralTCPCacheNoWaitFacade object.
- *
- * @return The cacheName value
- */
- @Override
- public String getCacheName()
- {
- return cacheName;
- }
-
/**
* Gets the cacheType attribute of the LateralTCPCacheNoWaitFacade object.
*
@@ -406,12 +379,12 @@ public class LateralTCPCacheNoWaitFacade<K, V>
}
/**
- * @return "LateralTCPCacheNoWaitFacade: " + cacheName;
+ * @return "LateralTCPCacheNoWaitFacade: " + getCacheName();
*/
@Override
public String toString()
{
- return "LateralTCPCacheNoWaitFacade: " + cacheName;
+ return "LateralTCPCacheNoWaitFacade: " + getCacheName();
}
/**
diff --git a/commons-jcs4-core/src/main/java/org/apache/commons/jcs4/auxiliary/remote/AbstractRemoteAuxiliaryCache.java b/commons-jcs4-core/src/main/java/org/apache/commons/jcs4/auxiliary/remote/AbstractRemoteAuxiliaryCache.java
index df3a6c72..dce1e4c3 100644
--- a/commons-jcs4-core/src/main/java/org/apache/commons/jcs4/auxiliary/remote/AbstractRemoteAuxiliaryCache.java
+++ b/commons-jcs4-core/src/main/java/org/apache/commons/jcs4/auxiliary/remote/AbstractRemoteAuxiliaryCache.java
@@ -31,7 +31,6 @@ import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;
import org.apache.commons.jcs4.auxiliary.AbstractAuxiliaryCacheEventLogging;
-import org.apache.commons.jcs4.auxiliary.AuxiliaryCacheAttributes;
import org.apache.commons.jcs4.auxiliary.remote.behavior.IRemoteCacheAttributes;
import org.apache.commons.jcs4.auxiliary.remote.behavior.IRemoteCacheClient;
import org.apache.commons.jcs4.auxiliary.remote.behavior.IRemoteCacheListener;
@@ -63,15 +62,9 @@ public abstract class AbstractRemoteAuxiliaryCache<K, V>
*/
private ICacheServiceNonLocal<K, V> remoteCacheService;
- /** The cacheName */
- protected final String cacheName;
-
/** The listener. This can be null. */
private IRemoteCacheListener<K, V> remoteCacheListener;
- /** The configuration values. TODO, we'll need a base here. */
- private IRemoteCacheAttributes remoteCacheAttributes;
-
/** A thread pool for gets if configured. */
private ExecutorService pool;
@@ -88,26 +81,25 @@ public abstract class AbstractRemoteAuxiliaryCache<K, V>
public AbstractRemoteAuxiliaryCache( final IRemoteCacheAttributes cattr, final ICacheServiceNonLocal<K, V> remote,
final IRemoteCacheListener<K, V> listener )
{
- this.setRemoteCacheAttributes( cattr );
- this.cacheName = cattr.getCacheName();
+ this.setAuxiliaryCacheAttributes(cattr);
this.setRemoteCacheService( remote );
this.setRemoteCacheListener( listener );
if ( log.isDebugEnabled() )
{
log.debug( "Construct> cacheName={0}", cattr::getCacheName);
- log.debug( "irca = {0}", this::getRemoteCacheAttributes);
+ log.debug( "irca = {0}", this::getAuxiliaryCacheAttributes);
log.debug( "remote = {0}", remote );
log.debug( "listener = {0}", listener );
}
// use a pool if it is greater than 0
log.debug( "GetTimeoutMillis() = {0}",
- () -> getRemoteCacheAttributes().getGetTimeoutMillis() );
+ () -> getAuxiliaryCacheAttributes().getGetTimeoutMillis() );
- if ( getRemoteCacheAttributes().getGetTimeoutMillis() > 0 )
+ if ( getAuxiliaryCacheAttributes().getGetTimeoutMillis() > 0 )
{
- pool = ThreadPoolManager.getInstance().getExecutorService( getRemoteCacheAttributes().getThreadPoolName() );
+ pool = ThreadPoolManager.getInstance().getExecutorService( getAuxiliaryCacheAttributes().getThreadPoolName() );
log.debug( "Thread Pool = {0}", pool );
usePoolForGet = true;
}
@@ -156,20 +148,9 @@ public abstract class AbstractRemoteAuxiliaryCache<K, V>
* @return the AuxiliaryCacheAttributes.
*/
@Override
- public AuxiliaryCacheAttributes getAuxiliaryCacheAttributes()
- {
- return getRemoteCacheAttributes();
- }
-
- /**
- * Gets the cacheName attribute of the RemoteCache object.
- *
- * @return The cacheName value
- */
- @Override
- public String getCacheName()
+ public IRemoteCacheAttributes getAuxiliaryCacheAttributes()
{
- return cacheName;
+ return (IRemoteCacheAttributes) super.getAuxiliaryCacheAttributes();
}
/**
@@ -191,7 +172,7 @@ public abstract class AbstractRemoteAuxiliaryCache<K, V>
public Set<K> getKeySet()
throws IOException
{
- return getRemoteCacheService().getKeySet(cacheName);
+ return getRemoteCacheService().getKeySet(getCacheName());
}
/**
@@ -229,14 +210,6 @@ public abstract class AbstractRemoteAuxiliaryCache<K, V>
return -1;
}
- /**
- * @return the remoteCacheAttributes
- */
- protected IRemoteCacheAttributes getRemoteCacheAttributes()
- {
- return remoteCacheAttributes;
- }
-
/**
* @return the remoteCacheListener
*/
@@ -271,7 +244,7 @@ public abstract class AbstractRemoteAuxiliaryCache<K, V>
{
final IStats stats = new Stats("AbstractRemoteAuxiliaryCache");
- stats.addStatElement("Remote Type", this.getRemoteCacheAttributes().getRemoteTypeName() );
+ stats.addStatElement("Remote Type", this.getAuxiliaryCacheAttributes().getRemoteTypeName() );
// if ( this.getRemoteCacheAttributes().getRemoteType() == RemoteType.CLUSTER )
// {
@@ -314,11 +287,11 @@ public abstract class AbstractRemoteAuxiliaryCache<K, V>
public ICacheElement<K, V> getUsingPool( final K key )
throws IOException
{
- final int timeout = getRemoteCacheAttributes().getGetTimeoutMillis();
+ final int timeout = getAuxiliaryCacheAttributes().getGetTimeoutMillis();
try
{
- final Callable<ICacheElement<K, V>> command = () -> getRemoteCacheService().get( cacheName, key, getListenerId() );
+ final Callable<ICacheElement<K, V>> command = () -> getRemoteCacheService().get( getCacheName(), key, getListenerId() );
// execute using the pool
final Future<ICacheElement<K, V>> future = pool.submit(command);
@@ -385,7 +358,7 @@ public abstract class AbstractRemoteAuxiliaryCache<K, V>
catch ( final IOException ex )
{
log.error( "Couldn't dispose", ex );
- handleException( ex, "Failed to dispose [" + cacheName + "]", CacheEventType.DISPOSE_EVENT );
+ handleException( ex, "Failed to dispose [" + getCacheName() + "]", CacheEventType.DISPOSE_EVENT );
}
}
@@ -415,7 +388,7 @@ public abstract class AbstractRemoteAuxiliaryCache<K, V>
}
else
{
- retVal = getRemoteCacheService().get( cacheName, key, getListenerId() );
+ retVal = getRemoteCacheService().get( getCacheName(), key, getListenerId() );
}
// Eventually the instance of will not be necessary.
@@ -423,7 +396,7 @@ public abstract class AbstractRemoteAuxiliaryCache<K, V>
// clients are merely intra-remote cache communicators. Remote caches are assumed
// to have no ability to deserialize the objects.
if (retVal instanceof ICacheElementSerialized<K, V> serialized &&
- this.getRemoteCacheAttributes().getRemoteType() != RemoteType.CLUSTER)
+ this.getAuxiliaryCacheAttributes().getRemoteType() != RemoteType.CLUSTER)
{
retVal = SerializationConversionUtil.getDeSerializedCacheElement(serialized,
super.getElementSerializer() );
@@ -431,7 +404,7 @@ public abstract class AbstractRemoteAuxiliaryCache<K, V>
}
catch ( final IOException | ClassNotFoundException ex )
{
- handleException( ex, "Failed to get [" + key + "] from [" + cacheName + "]", CacheEventType.GET_EVENT );
+ handleException( ex, "Failed to get [" + key + "] from [" + getCacheName() + "]", CacheEventType.GET_EVENT );
}
return retVal;
}
@@ -450,7 +423,7 @@ public abstract class AbstractRemoteAuxiliaryCache<K, V>
final Map<K, ICacheElement<K, V>> results = new HashMap<>();
try
{
- final Map<K, ICacheElement<K, V>> rawResults = getRemoteCacheService().getMatching( cacheName, pattern, getListenerId() );
+ final Map<K, ICacheElement<K, V>> rawResults = getRemoteCacheService().getMatching( getCacheName(), pattern, getListenerId() );
// Eventually the instance of will not be necessary.
if ( rawResults != null )
@@ -463,7 +436,7 @@ public abstract class AbstractRemoteAuxiliaryCache<K, V>
// Never try to deserialize if you are a cluster client. Cluster
// clients are merely intra-remote cache communicators. Remote caches are assumed
// to have no ability to deserialize the objects.
- if ( this.getRemoteCacheAttributes().getRemoteType() != RemoteType.CLUSTER )
+ if ( this.getAuxiliaryCacheAttributes().getRemoteType() != RemoteType.CLUSTER )
{
unwrappedResult = SerializationConversionUtil
.getDeSerializedCacheElement(serialized,
@@ -480,7 +453,7 @@ public abstract class AbstractRemoteAuxiliaryCache<K, V>
}
catch ( final IOException | ClassNotFoundException ex )
{
- handleException( ex, "Failed to getMatching [" + pattern + "] from [" + cacheName + "]",
+ handleException( ex, "Failed to getMatching [" + pattern + "] from [" + getCacheName() + "]",
CacheEventType.GET_EVENT );
}
return results;
@@ -498,16 +471,16 @@ public abstract class AbstractRemoteAuxiliaryCache<K, V>
protected boolean processRemove( final K key )
throws IOException
{
- if ( !this.getRemoteCacheAttributes().getGetOnly() )
+ if ( !this.getAuxiliaryCacheAttributes().getGetOnly() )
{
log.debug( "remove> key={0}", key );
try
{
- getRemoteCacheService().remove( cacheName, key, getListenerId() );
+ getRemoteCacheService().remove( getCacheName(), key, getListenerId() );
}
catch ( final IOException ex )
{
- handleException( ex, "Failed to remove " + key + " from " + cacheName, CacheEventType.REMOVE_EVENT );
+ handleException( ex, "Failed to remove " + key + " from " + getCacheName(), CacheEventType.REMOVE_EVENT );
}
return true;
}
@@ -524,15 +497,15 @@ public abstract class AbstractRemoteAuxiliaryCache<K, V>
protected void processRemoveAll()
throws IOException
{
- if ( !this.getRemoteCacheAttributes().getGetOnly() )
+ if ( !this.getAuxiliaryCacheAttributes().getGetOnly() )
{
try
{
- getRemoteCacheService().removeAll( cacheName, getListenerId() );
+ getRemoteCacheService().removeAll( getCacheName(), getListenerId() );
}
catch ( final IOException ex )
{
- handleException( ex, "Failed to remove all from " + cacheName, CacheEventType.REMOVEALL_EVENT );
+ handleException( ex, "Failed to remove all from " + getCacheName(), CacheEventType.REMOVEALL_EVENT );
}
}
}
@@ -549,7 +522,7 @@ public abstract class AbstractRemoteAuxiliaryCache<K, V>
protected void processUpdate( final ICacheElement<K, V> ce )
throws IOException
{
- if ( !getRemoteCacheAttributes().getGetOnly() )
+ if ( !getAuxiliaryCacheAttributes().getGetOnly() )
{
try
{
@@ -598,14 +571,6 @@ public abstract class AbstractRemoteAuxiliaryCache<K, V>
}
}
- /**
- * @param remoteCacheAttributes the remoteCacheAttributes to set
- */
- protected void setRemoteCacheAttributes( final IRemoteCacheAttributes remoteCacheAttributes )
- {
- this.remoteCacheAttributes = remoteCacheAttributes;
- }
-
/**
* @param remoteCacheListener the remoteCacheListener to set
*/
diff --git a/commons-jcs4-core/src/main/java/org/apache/commons/jcs4/auxiliary/remote/AbstractRemoteCacheNoWaitFacade.java b/commons-jcs4-core/src/main/java/org/apache/commons/jcs4/auxiliary/remote/AbstractRemoteCacheNoWaitFacade.java
index 6691e101..b50930d6 100644
--- a/commons-jcs4-core/src/main/java/org/apache/commons/jcs4/auxiliary/remote/AbstractRemoteCacheNoWaitFacade.java
+++ b/commons-jcs4-core/src/main/java/org/apache/commons/jcs4/auxiliary/remote/AbstractRemoteCacheNoWaitFacade.java
@@ -48,9 +48,6 @@ public abstract class AbstractRemoteCacheNoWaitFacade<K, V>
/** The connection to a remote server, or a zombie. */
protected List<RemoteCacheNoWait<K, V>> noWaits;
- /** Holds failover and cluster information */
- private final RemoteCacheAttributes remoteCacheAttributes;
-
/**
* Constructs with the given remote cache, and fires events to any listeners.
*
@@ -63,7 +60,7 @@ public abstract class AbstractRemoteCacheNoWaitFacade<K, V>
final ICacheEventLogger cacheEventLogger, final IElementSerializer elementSerializer )
{
log.debug( "CONSTRUCTING NO WAIT FACADE" );
- this.remoteCacheAttributes = (RemoteCacheAttributes)rca;
+ setAuxiliaryCacheAttributes(rca);
setCacheEventLogger( cacheEventLogger );
setElementSerializer( elementSerializer );
this.noWaits = new ArrayList<>(noWaits);
@@ -111,18 +108,7 @@ public abstract class AbstractRemoteCacheNoWaitFacade<K, V>
@Override
public RemoteCacheAttributes getAuxiliaryCacheAttributes()
{
- return this.remoteCacheAttributes;
- }
-
- /**
- * Gets the cacheName attribute of the RemoteCacheNoWaitFacade object.
- *
- * @return The cacheName value
- */
- @Override
- public String getCacheName()
- {
- return remoteCacheAttributes.getCacheName();
+ return (RemoteCacheAttributes) super.getAuxiliaryCacheAttributes();
}
/**
@@ -303,8 +289,8 @@ public abstract class AbstractRemoteCacheNoWaitFacade<K, V>
@Override
public String toString()
{
- return "RemoteCacheNoWaitFacade: " + remoteCacheAttributes.getCacheName() +
- ", rca = " + remoteCacheAttributes;
+ return "RemoteCacheNoWaitFacade: " + getCacheName() +
+ ", rca = " + getAuxiliaryCacheAttributes();
}
/**
diff --git a/commons-jcs4-core/src/main/java/org/apache/commons/jcs4/auxiliary/remote/RemoteCache.java b/commons-jcs4-core/src/main/java/org/apache/commons/jcs4/auxiliary/remote/RemoteCache.java
index 8a2b8406..5fc6cdef 100644
--- a/commons-jcs4-core/src/main/java/org/apache/commons/jcs4/auxiliary/remote/RemoteCache.java
+++ b/commons-jcs4-core/src/main/java/org/apache/commons/jcs4/auxiliary/remote/RemoteCache.java
@@ -68,7 +68,7 @@ public class RemoteCache<K, V>
super( cattr, remote, listener );
this.monitor = monitor;
- RemoteUtils.configureGlobalCustomSocketFactory( getRemoteCacheAttributes().getRmiSocketFactoryTimeoutMillis() );
+ RemoteUtils.configureGlobalCustomSocketFactory( getAuxiliaryCacheAttributes().getRmiSocketFactoryTimeoutMillis() );
}
/**
@@ -102,9 +102,9 @@ public class RemoteCache<K, V>
protected String getIPAddressForService()
{
String ipAddress = "(null)";
- if (getRemoteCacheAttributes().getRemoteLocation() != null)
+ if (getAuxiliaryCacheAttributes().getRemoteLocation() != null)
{
- ipAddress = getRemoteCacheAttributes().getRemoteLocation().toString();
+ ipAddress = getAuxiliaryCacheAttributes().getRemoteLocation().toString();
}
return ipAddress;
}
@@ -118,7 +118,7 @@ public class RemoteCache<K, V>
final IStats stats = new Stats("Remote Cache");
stats.addStatElement("Remote Host:Port", getIPAddressForService() );
- stats.addStatElement("Remote Type", getRemoteCacheAttributes().getRemoteTypeName() );
+ stats.addStatElement("Remote Type", getAuxiliaryCacheAttributes().getRemoteTypeName() );
// if ( this.getRemoteCacheAttributes().getRemoteType() == RemoteType.CLUSTER )
// {
@@ -147,14 +147,14 @@ public class RemoteCache<K, V>
{
final String message = "Disabling remote cache due to error: " + msg;
- logError( cacheName, eventType, message );
+ logError( getCacheName(), eventType, message );
log.error( message, ex );
// we should not switch if the existing is a zombie.
if (!(getRemoteCacheService() instanceof ZombieCacheServiceNonLocal))
{
// TODO make configurable
- setRemoteCacheService( new ZombieCacheServiceNonLocal<>( getRemoteCacheAttributes().getZombieQueueMaxSize() ) );
+ setRemoteCacheService( new ZombieCacheServiceNonLocal<>( getAuxiliaryCacheAttributes().getZombieQueueMaxSize() ) );
}
// may want to flush if region specifies
// Notify the cache monitor about the error, and kick off the recovery
@@ -196,6 +196,6 @@ public class RemoteCache<K, V>
@Override
public String toString()
{
- return "RemoteCache: " + cacheName + " attributes = " + getRemoteCacheAttributes();
+ return "RemoteCache: " + getCacheName() + " attributes = " + getAuxiliaryCacheAttributes();
}
}
diff --git a/commons-jcs4-core/src/main/java/org/apache/commons/jcs4/auxiliary/remote/RemoteCacheNoWait.java b/commons-jcs4-core/src/main/java/org/apache/commons/jcs4/auxiliary/remote/RemoteCacheNoWait.java
index 839b69a4..47b4ec07 100644
--- a/commons-jcs4-core/src/main/java/org/apache/commons/jcs4/auxiliary/remote/RemoteCacheNoWait.java
+++ b/commons-jcs4-core/src/main/java/org/apache/commons/jcs4/auxiliary/remote/RemoteCacheNoWait.java
@@ -27,7 +27,6 @@ import java.util.Map;
import java.util.Set;
import org.apache.commons.jcs4.auxiliary.AbstractAuxiliaryCache;
-import org.apache.commons.jcs4.auxiliary.AuxiliaryCacheAttributes;
import org.apache.commons.jcs4.auxiliary.remote.behavior.IRemoteCacheClient;
import org.apache.commons.jcs4.engine.CacheAdaptor;
import org.apache.commons.jcs4.engine.CacheEventQueueFactory;
@@ -185,15 +184,6 @@ public class RemoteCacheNoWait<K, V>
return null;
}
- /**
- * @return the AuxiliaryCacheAttributes.
- */
- @Override
- public AuxiliaryCacheAttributes getAuxiliaryCacheAttributes()
- {
- return remoteCacheClient.getAuxiliaryCacheAttributes();
- }
-
/**
* This is for testing only. It allows you to take a look at the event queue.
*
diff --git a/commons-jcs4-core/src/main/java/org/apache/commons/jcs4/auxiliary/remote/http/client/RemoteHttpCache.java b/commons-jcs4-core/src/main/java/org/apache/commons/jcs4/auxiliary/remote/http/client/RemoteHttpCache.java
index 4180bef2..7ee84ae1 100644
--- a/commons-jcs4-core/src/main/java/org/apache/commons/jcs4/auxiliary/remote/http/client/RemoteHttpCache.java
+++ b/commons-jcs4-core/src/main/java/org/apache/commons/jcs4/auxiliary/remote/http/client/RemoteHttpCache.java
@@ -40,9 +40,6 @@ public class RemoteHttpCache<K, V>
/** For error notifications */
private final RemoteHttpCacheMonitor monitor;
- /** Keep the child copy here for the restore process. */
- private final RemoteHttpCacheAttributes remoteHttpCacheAttributes;
-
/**
* Constructor for the RemoteCache object. This object communicates with a remote cache server.
* One of these exists for each region. This also holds a reference to a listener. The same
@@ -58,8 +55,6 @@ public class RemoteHttpCache<K, V>
final IRemoteCacheListener<K, V> listener, final RemoteHttpCacheMonitor monitor )
{
super( remoteHttpCacheAttributes, remote, listener );
-
- this.remoteHttpCacheAttributes = remoteHttpCacheAttributes;
this.monitor = monitor;
}
@@ -72,14 +67,6 @@ public class RemoteHttpCache<K, V>
return null;
}
- /**
- * @return the remoteHttpCacheAttributes
- */
- public RemoteHttpCacheAttributes getRemoteHttpCacheAttributes()
- {
- return remoteHttpCacheAttributes;
- }
-
/**
* Nothing right now. This should setup a zombie and initiate recovery.
*
@@ -96,10 +83,10 @@ public class RemoteHttpCache<K, V>
if ( !( getRemoteCacheService() instanceof ZombieCacheServiceNonLocal))
{
final String message = "Disabling remote cache due to error: " + msg;
- logError( cacheName, eventType, message );
+ logError( getCacheName(), eventType, message );
log.error( message, ex );
- setRemoteCacheService( new ZombieCacheServiceNonLocal<>( getRemoteCacheAttributes().getZombieQueueMaxSize() ) );
+ setRemoteCacheService( new ZombieCacheServiceNonLocal<>( getAuxiliaryCacheAttributes().getZombieQueueMaxSize() ) );
monitor.notifyError( this );
}
diff --git a/commons-jcs4-core/src/main/java/org/apache/commons/jcs4/auxiliary/remote/http/client/RemoteHttpCacheMonitor.java b/commons-jcs4-core/src/main/java/org/apache/commons/jcs4/auxiliary/remote/http/client/RemoteHttpCacheMonitor.java
index 044fd377..e135cd75 100644
--- a/commons-jcs4-core/src/main/java/org/apache/commons/jcs4/auxiliary/remote/http/client/RemoteHttpCacheMonitor.java
+++ b/commons-jcs4-core/src/main/java/org/apache/commons/jcs4/auxiliary/remote/http/client/RemoteHttpCacheMonitor.java
@@ -85,7 +85,8 @@ public class RemoteHttpCacheMonitor extends AbstractAuxiliaryCacheMonitor
{
if ( remoteCache.getStatus() == CacheStatus.ERROR )
{
- final RemoteHttpCacheAttributes attributes = remoteCache.getRemoteHttpCacheAttributes();
+ final RemoteHttpCacheAttributes attributes =
+ (RemoteHttpCacheAttributes)remoteCache.getAuxiliaryCacheAttributes();
final IRemoteHttpCacheClient<Serializable, Serializable> remoteService =
factory.createRemoteHttpCacheClientForAttributes( attributes );
diff --git a/commons-jcs4-core/src/main/java/org/apache/commons/jcs4/auxiliary/remote/http/server/AbstractRemoteCacheService.java b/commons-jcs4-core/src/main/java/org/apache/commons/jcs4/auxiliary/remote/http/server/AbstractRemoteCacheService.java
index c68598d0..3c0eb1c2 100644
--- a/commons-jcs4-core/src/main/java/org/apache/commons/jcs4/auxiliary/remote/http/server/AbstractRemoteCacheService.java
+++ b/commons-jcs4-core/src/main/java/org/apache/commons/jcs4/auxiliary/remote/http/server/AbstractRemoteCacheService.java
@@ -70,37 +70,6 @@ public abstract class AbstractRemoteCacheService<K, V>
setCacheEventLogger(cacheEventLogger);
}
- /**
- * Logs an event if an event logger is configured.
- *
- * @param item
- * @param requesterId
- * @param eventType
- * @return ICacheEvent
- */
- protected ICacheEvent<ICacheElement<K, V>> createICacheEvent( final ICacheElement<K, V> item, final long requesterId, final CacheEventType eventType )
- {
- final String ipAddress = getExtraInfoForRequesterId( requesterId );
- return createICacheEvent( getEventLogSourceName(), item.cacheName(),
- eventType, ipAddress, item );
- }
-
- /**
- * Logs an event if an event logger is configured.
- *
- * @param cacheName
- * @param key
- * @param requesterId
- * @param eventType
- * @return ICacheEvent
- */
- protected <T> ICacheEvent<T> createICacheEvent( final String cacheName, final T key, final long requesterId, final CacheEventType eventType )
- {
- final String ipAddress = getExtraInfoForRequesterId( requesterId );
- return createICacheEvent( getEventLogSourceName(), cacheName,
- eventType, ipAddress, key );
- }
-
/**
* Frees the specified remote cache.
*
@@ -124,8 +93,8 @@ public abstract class AbstractRemoteCacheService<K, V>
public void dispose( final String cacheName, final long requesterId )
throws IOException
{
- final ICacheEvent<String> cacheEvent = createICacheEvent( cacheName, "none", requesterId,
- CacheEventType.DISPOSE_EVENT );
+ final ICacheEvent<String> cacheEvent = createICacheEvent(cacheName, "none",
+ CacheEventType.DISPOSE_EVENT, () -> getExtraInfoForRequesterId( requesterId ));
try
{
processDispose( cacheName, requesterId );
@@ -170,7 +139,8 @@ public abstract class AbstractRemoteCacheService<K, V>
throws IOException
{
ICacheElement<K, V> element = null;
- final ICacheEvent<K> cacheEvent = createICacheEvent( cacheName, key, requesterId, CacheEventType.GET_EVENT );
+ final ICacheEvent<K> cacheEvent = createICacheEvent(cacheName, key,
+ CacheEventType.GET_EVENT, () -> getExtraInfoForRequesterId( requesterId ));
try
{
element = processGet( cacheName, key, requesterId );
@@ -193,6 +163,7 @@ public abstract class AbstractRemoteCacheService<K, V>
/**
* @return the eventLogSourceName
*/
+ @Override
protected String getEventLogSourceName()
{
return eventLogSourceName;
@@ -247,8 +218,8 @@ public abstract class AbstractRemoteCacheService<K, V>
public Map<K, ICacheElement<K, V>> getMatching( final String cacheName, final String pattern, final long requesterId )
throws IOException
{
- final ICacheEvent<String> cacheEvent = createICacheEvent( cacheName, pattern, requesterId,
- CacheEventType.GETMATCHING_EVENT );
+ final ICacheEvent<String> cacheEvent = createICacheEvent(cacheName, pattern,
+ CacheEventType.GETMATCHING_EVENT, () -> getExtraInfoForRequesterId(requesterId));
try
{
return processGetMatching( cacheName, pattern, requesterId );
@@ -291,8 +262,9 @@ public abstract class AbstractRemoteCacheService<K, V>
public Map<K, ICacheElement<K, V>> getMultiple( final String cacheName, final Set<K> keys, final long requesterId )
throws IOException
{
- final ICacheEvent<Serializable> cacheEvent = createICacheEvent( cacheName, (Serializable) keys, requesterId,
- CacheEventType.GETMULTIPLE_EVENT );
+ final ICacheEvent<Serializable> cacheEvent = createICacheEvent(cacheName,
+ (Serializable) keys, CacheEventType.GETMULTIPLE_EVENT,
+ () -> getExtraInfoForRequesterId( requesterId ));
try
{
return processGetMultiple( cacheName, keys, requesterId );
@@ -442,7 +414,8 @@ public abstract class AbstractRemoteCacheService<K, V>
public void remove( final String cacheName, final K key, final long requesterId )
throws IOException
{
- final ICacheEvent<K> cacheEvent = createICacheEvent( cacheName, key, requesterId, CacheEventType.REMOVE_EVENT );
+ final ICacheEvent<K> cacheEvent = createICacheEvent(cacheName, key,
+ CacheEventType.REMOVE_EVENT, () -> getExtraInfoForRequesterId( requesterId ));
try
{
processRemove( cacheName, key, requesterId );
@@ -479,7 +452,8 @@ public abstract class AbstractRemoteCacheService<K, V>
public void removeAll( final String cacheName, final long requesterId )
throws IOException
{
- final ICacheEvent<String> cacheEvent = createICacheEvent( cacheName, "all", requesterId, CacheEventType.REMOVEALL_EVENT );
+ final ICacheEvent<String> cacheEvent = createICacheEvent(cacheName, "all",
+ CacheEventType.REMOVEALL_EVENT, () -> getExtraInfoForRequesterId( requesterId ));
try
{
processRemoveAll( cacheName, requesterId );
@@ -528,7 +502,8 @@ public abstract class AbstractRemoteCacheService<K, V>
public void update( final ICacheElement<K, V> item, final long requesterId )
throws IOException
{
- final ICacheEvent<ICacheElement<K, V>> cacheEvent = createICacheEvent( item, requesterId, CacheEventType.UPDATE_EVENT );
+ final ICacheEvent<K> cacheEvent = createICacheEvent( item,
+ CacheEventType.UPDATE_EVENT, () -> getExtraInfoForRequesterId( requesterId ));
try
{
logUpdateInfo( item );
diff --git a/commons-jcs4-core/src/main/java/org/apache/commons/jcs4/auxiliary/remote/http/server/RemoteHttpCacheService.java b/commons-jcs4-core/src/main/java/org/apache/commons/jcs4/auxiliary/remote/http/server/RemoteHttpCacheService.java
index ebb6fb2f..2809b207 100644
--- a/commons-jcs4-core/src/main/java/org/apache/commons/jcs4/auxiliary/remote/http/server/RemoteHttpCacheService.java
+++ b/commons-jcs4-core/src/main/java/org/apache/commons/jcs4/auxiliary/remote/http/server/RemoteHttpCacheService.java
@@ -69,7 +69,7 @@ public class RemoteHttpCacheService<K, V>
@Override
protected String getExtraInfoForRequesterId( final long requesterId )
{
- return requesterId + "";
+ return String.valueOf(requesterId);
}
/**
@@ -257,13 +257,4 @@ public class RemoteHttpCacheService<K, V>
{
//nothing.
}
-
- /**
- * @return the RemoteHttpCacheServerAttributes
- */
- @Override
- public RemoteHttpCacheServerAttributes getAuxiliaryCacheAttributes()
- {
- return remoteHttpCacheServerAttributes;
- }
}
diff --git a/commons-jcs4-core/src/main/java/org/apache/commons/jcs4/auxiliary/remote/value/RemoteCacheResponse.java b/commons-jcs4-core/src/main/java/org/apache/commons/jcs4/auxiliary/remote/value/RemoteCacheResponse.java
index a260d0fd..4ed2a2db 100644
--- a/commons-jcs4-core/src/main/java/org/apache/commons/jcs4/auxiliary/remote/value/RemoteCacheResponse.java
+++ b/commons-jcs4-core/src/main/java/org/apache/commons/jcs4/auxiliary/remote/value/RemoteCacheResponse.java
@@ -44,7 +44,7 @@ public record RemoteCacheResponse<T>(
/**
* Construct error message object
- * @param succcess
+ * @param success
* @param errorMessage
*/
public RemoteCacheResponse(final boolean success, final String errorMessage)
diff --git a/commons-jcs4-core/src/main/java/org/apache/commons/jcs4/engine/behavior/ICacheService.java b/commons-jcs4-core/src/main/java/org/apache/commons/jcs4/engine/behavior/ICacheService.java
index 7ad43be6..de433c5e 100644
--- a/commons-jcs4-core/src/main/java/org/apache/commons/jcs4/engine/behavior/ICacheService.java
+++ b/commons-jcs4-core/src/main/java/org/apache/commons/jcs4/engine/behavior/ICacheService.java
@@ -23,9 +23,6 @@ import java.io.IOException;
import java.util.Map;
import java.util.Set;
-import org.apache.commons.jcs4.access.exception.ObjectExistsException;
-import org.apache.commons.jcs4.access.exception.ObjectNotFoundException;
-
/**
* Used to retrieve and update the cache.
* <p>
@@ -49,11 +46,10 @@ public interface ICacheService<K, V>
* @param cacheName
* @param key
* @return the ICacheElement<K, V> or null if not found
- * @throws ObjectNotFoundException
* @throws IOException
*/
ICacheElement<K, V> get( String cacheName, K key )
- throws ObjectNotFoundException, IOException;
+ throws IOException;
/**
* Gets multiple items from the cache matching the pattern.
@@ -74,11 +70,10 @@ public interface ICacheService<K, V>
* @param keys
* @return a map of K key to ICacheElement<K, V> element, or an empty map if there is no
* data in cache for any of these keys
- * @throws ObjectNotFoundException
* @throws IOException
*/
Map<K, ICacheElement<K, V>> getMultiple( String cacheName, Set<K> keys )
- throws ObjectNotFoundException, IOException;
+ throws IOException;
/**
* Frees all caches.
@@ -109,9 +104,8 @@ public interface ICacheService<K, V>
* Puts a cache item to the cache.
*
* @param item
- * @throws ObjectExistsException
* @throws IOException
*/
void update( ICacheElement<K, V> item )
- throws ObjectExistsException, IOException;
+ throws IOException;
}
diff --git a/commons-jcs4-core/src/main/java/org/apache/commons/jcs4/engine/control/CompositeCache.java b/commons-jcs4-core/src/main/java/org/apache/commons/jcs4/engine/control/CompositeCache.java
index de2d2a4f..69062179 100644
--- a/commons-jcs4-core/src/main/java/org/apache/commons/jcs4/engine/control/CompositeCache.java
+++ b/commons-jcs4-core/src/main/java/org/apache/commons/jcs4/engine/control/CompositeCache.java
@@ -39,7 +39,6 @@ import java.util.stream.Collectors;
import java.util.stream.Stream;
import org.apache.commons.jcs4.access.exception.CacheException;
-import org.apache.commons.jcs4.access.exception.ObjectNotFoundException;
import org.apache.commons.jcs4.auxiliary.AuxiliaryCache;
import org.apache.commons.jcs4.engine.CacheStatus;
import org.apache.commons.jcs4.engine.behavior.ICache;
@@ -519,7 +518,7 @@ public class CompositeCache<K, V>
final ICacheElement<K, V> ce = get(key);
if (ce == null)
{
- throw new ObjectNotFoundException("key " + key + " is not found");
+ throw new CacheException("key " + key + " is not found");
}
return ce.elementAttributes();
}
diff --git a/commons-jcs4-core/src/main/java/org/apache/commons/jcs4/engine/memory/soft/SoftReferenceMemoryCache.java b/commons-jcs4-core/src/main/java/org/apache/commons/jcs4/engine/memory/soft/SoftReferenceMemoryCache.java
index 3783ef46..0fb13e23 100644
--- a/commons-jcs4-core/src/main/java/org/apache/commons/jcs4/engine/memory/soft/SoftReferenceMemoryCache.java
+++ b/commons-jcs4-core/src/main/java/org/apache/commons/jcs4/engine/memory/soft/SoftReferenceMemoryCache.java
@@ -39,7 +39,7 @@ import org.apache.commons.jcs4.log.Log;
/**
* A JCS IMemoryCache that has {@link SoftReference} to all its values.
- * This cache does not respect {@link ICompositeCacheAttributes#getMaxObjects()}
+ * This cache does not respect {@link ICompositeCacheAttributes#maxObjects()}
* as overflowing is handled by Java GC.
* <p>
* The cache also has strong references to a maximum number of objects given by
diff --git a/commons-jcs4-core/src/test/java/org/apache/commons/jcs4/access/CacheAccessUnitTest.java b/commons-jcs4-core/src/test/java/org/apache/commons/jcs4/access/CacheAccessUnitTest.java
index bcbc55a0..216a486f 100644
--- a/commons-jcs4-core/src/test/java/org/apache/commons/jcs4/access/CacheAccessUnitTest.java
+++ b/commons-jcs4-core/src/test/java/org/apache/commons/jcs4/access/CacheAccessUnitTest.java
@@ -33,7 +33,6 @@ import java.util.Set;
import org.apache.commons.jcs4.JCS;
import org.apache.commons.jcs4.access.exception.CacheException;
-import org.apache.commons.jcs4.access.exception.ObjectExistsException;
import org.apache.commons.jcs4.engine.CompositeCacheAttributes;
import org.apache.commons.jcs4.engine.ElementAttributes;
import org.apache.commons.jcs4.engine.TestCompositeCacheAttributes;
@@ -279,7 +278,7 @@ class CacheAccessUnitTest
}
catch ( final CacheException e )
{
- assertInstanceOf( ObjectExistsException.class, e, "Wrong type of exception." );
+ assertInstanceOf( CacheException.class, e, "Wrong type of exception." );
assertTrue( e.getMessage().indexOf( "[" + key + "]" ) != -1, "Should have the key in the error message." );
}
diff --git a/commons-jcs4-core/src/test/java/org/apache/commons/jcs4/auxiliary/MockAuxiliaryCache.java b/commons-jcs4-core/src/test/java/org/apache/commons/jcs4/auxiliary/MockAuxiliaryCache.java
index 42f188c9..79a43a94 100644
--- a/commons-jcs4-core/src/test/java/org/apache/commons/jcs4/auxiliary/MockAuxiliaryCache.java
+++ b/commons-jcs4-core/src/test/java/org/apache/commons/jcs4/auxiliary/MockAuxiliaryCache.java
@@ -67,15 +67,6 @@ public class MockAuxiliaryCache<K, V>
return null;
}
- /**
- * @return the AuxiliaryCacheAttributes.
- */
- @Override
- public AuxiliaryCacheAttributes getAuxiliaryCacheAttributes()
- {
- return null;
- }
-
/**
* @return null
*/
diff --git a/commons-jcs4-core/src/test/java/org/apache/commons/jcs4/auxiliary/disk/AbstractDiskCacheUnitTest.java b/commons-jcs4-core/src/test/java/org/apache/commons/jcs4/auxiliary/disk/AbstractDiskCacheUnitTest.java
index cfcc7c13..624fbcb8 100644
--- a/commons-jcs4-core/src/test/java/org/apache/commons/jcs4/auxiliary/disk/AbstractDiskCacheUnitTest.java
+++ b/commons-jcs4-core/src/test/java/org/apache/commons/jcs4/auxiliary/disk/AbstractDiskCacheUnitTest.java
@@ -34,7 +34,6 @@ import java.util.Map;
import java.util.Set;
import org.apache.commons.jcs4.TestLogConfigurationUtil;
-import org.apache.commons.jcs4.auxiliary.AuxiliaryCacheAttributes;
import org.apache.commons.jcs4.auxiliary.disk.behavior.IDiskCacheAttributes;
import org.apache.commons.jcs4.auxiliary.disk.indexed.IndexedDiskCacheAttributes;
import org.apache.commons.jcs4.engine.CacheElement;
@@ -69,22 +68,13 @@ class AbstractDiskCacheUnitTest
setAlive(true);
}
- /**
- * @return null
- */
- @Override
- public AuxiliaryCacheAttributes getAuxiliaryCacheAttributes()
- {
- return diskCacheAttributes;
- }
-
/**
* The location on disk
*
* @return "memory"
*/
@Override
- protected String getDiskLocation()
+ protected String getEventLoggingExtraInfo()
{
return "memory";
}
diff --git a/commons-jcs4-core/src/test/java/org/apache/commons/jcs4/auxiliary/remote/RemoteCacheClientTester.java b/commons-jcs4-core/src/test/java/org/apache/commons/jcs4/auxiliary/remote/RemoteCacheClientTester.java
index f89929f7..5ddad8f0 100644
--- a/commons-jcs4-core/src/test/java/org/apache/commons/jcs4/auxiliary/remote/RemoteCacheClientTester.java
+++ b/commons-jcs4-core/src/test/java/org/apache/commons/jcs4/auxiliary/remote/RemoteCacheClientTester.java
@@ -29,7 +29,6 @@ import java.rmi.server.ExportException;
import java.rmi.server.UnicastRemoteObject;
import org.apache.commons.jcs4.access.exception.CacheException;
-import org.apache.commons.jcs4.access.exception.ObjectExistsException;
import org.apache.commons.jcs4.auxiliary.remote.behavior.IRemoteCacheConstants;
import org.apache.commons.jcs4.auxiliary.remote.behavior.IRemoteCacheListener;
import org.apache.commons.jcs4.auxiliary.remote.server.behavior.RemoteType;
@@ -215,7 +214,7 @@ public class RemoteCacheClientTester
{
cache.update( cb );
}
- catch ( final ObjectExistsException oee )
+ catch ( final CacheException oee )
{
p( oee.toString() );
}
diff --git a/commons-jcs4-core/src/test/java/org/apache/commons/jcs4/engine/control/CompositeCacheDiskUsageUnitTest.java b/commons-jcs4-core/src/test/java/org/apache/commons/jcs4/engine/control/CompositeCacheDiskUsageUnitTest.java
index e0e1d285..b787301d 100644
--- a/commons-jcs4-core/src/test/java/org/apache/commons/jcs4/engine/control/CompositeCacheDiskUsageUnitTest.java
+++ b/commons-jcs4-core/src/test/java/org/apache/commons/jcs4/engine/control/CompositeCacheDiskUsageUnitTest.java
@@ -32,7 +32,6 @@ import org.apache.commons.jcs4.JCS;
import org.apache.commons.jcs4.access.CacheAccess;
import org.apache.commons.jcs4.access.exception.CacheException;
import org.apache.commons.jcs4.auxiliary.AbstractAuxiliaryCache;
-import org.apache.commons.jcs4.auxiliary.AuxiliaryCacheAttributes;
import org.apache.commons.jcs4.engine.CacheElement;
import org.apache.commons.jcs4.engine.CacheStatus;
import org.apache.commons.jcs4.engine.CompositeCacheAttributes;
@@ -88,15 +87,6 @@ class CompositeCacheDiskUsageUnitTest
return null;
}
- /**
- * @return the AuxiliaryCacheAttributes.
- */
- @Override
- public AuxiliaryCacheAttributes getAuxiliaryCacheAttributes()
- {
- return null;
- }
-
/** @return null */
@Override
public String getCacheName()