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 d473430a5f2b49790e676e95d0d853c1cd8c8782 Author: Thomas Vandahl <[email protected]> AuthorDate: Mon Feb 16 14:15:32 2026 +0100 Make sure that all configurations reach their target. --- .../jcs4/auxiliary/AbstractAuxiliaryCache.java | 2 -- .../commons/jcs4/auxiliary/AuxiliaryCache.java | 18 +---------- .../jcs4/auxiliary/AuxiliaryCacheConfigurator.java | 2 +- .../lateral/socket/tcp/LateralTCPCacheFactory.java | 37 +++++++++++----------- .../socket/tcp/LateralTCPDiscoveryListener.java | 14 +++++--- .../jcs4/auxiliary/remote/RemoteCacheManager.java | 2 +- .../remote/http/client/RemoteHttpCacheFactory.java | 3 +- .../tcp/LateralTCPDiscoveryListenerUnitTest.java | 8 +++-- 8 files changed, 38 insertions(+), 48 deletions(-) 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 30a511e0..6332f170 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 @@ -219,7 +219,6 @@ public abstract class AbstractAuxiliaryCache<K, V> * * @param cacheEventLogger */ - @Override public void setCacheEventLogger( final ICacheEventLogger cacheEventLogger ) { this.cacheEventLogger = cacheEventLogger; @@ -233,7 +232,6 @@ public abstract class AbstractAuxiliaryCache<K, V> * * @param elementSerializer */ - @Override public void setElementSerializer( final IElementSerializer elementSerializer ) { if ( elementSerializer != null ) 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 94eb06e3..02362eae 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,8 +23,6 @@ import java.io.IOException; import java.util.Set; import org.apache.commons.jcs4.engine.behavior.ICache; -import org.apache.commons.jcs4.engine.behavior.IElementSerializer; -import org.apache.commons.jcs4.engine.logging.behavior.ICacheEventLogger; import org.apache.commons.jcs4.engine.stats.behavior.IStats; /** @@ -58,20 +56,6 @@ public interface AuxiliaryCache<K, V> /** * @return the historical and statistical data for a region's auxiliary cache. */ + @Override IStats getStatistics(); - - /** - * Every Auxiliary must allow for the use of an event logger. - * - * @param cacheEventLogger - */ - void setCacheEventLogger( ICacheEventLogger cacheEventLogger ); - - /** - * Allows you to inject a custom serializer. A good example would be a compressing standard - * serializer. - * - * @param elementSerializer - */ - void setElementSerializer( IElementSerializer elementSerializer ); } diff --git a/commons-jcs4-core/src/main/java/org/apache/commons/jcs4/auxiliary/AuxiliaryCacheConfigurator.java b/commons-jcs4-core/src/main/java/org/apache/commons/jcs4/auxiliary/AuxiliaryCacheConfigurator.java index 0801789b..85f5b58e 100644 --- a/commons-jcs4-core/src/main/java/org/apache/commons/jcs4/auxiliary/AuxiliaryCacheConfigurator.java +++ b/commons-jcs4-core/src/main/java/org/apache/commons/jcs4/auxiliary/AuxiliaryCacheConfigurator.java @@ -74,7 +74,7 @@ public class AuxiliaryCacheConfigurator } else { - log.info( "No cache event logger defined for auxiliary [{0}]", auxPrefix ); + log.debug( "No cache event logger defined for auxiliary [{0}]", auxPrefix ); } return cacheEventLogger; } diff --git a/commons-jcs4-core/src/main/java/org/apache/commons/jcs4/auxiliary/lateral/socket/tcp/LateralTCPCacheFactory.java b/commons-jcs4-core/src/main/java/org/apache/commons/jcs4/auxiliary/lateral/socket/tcp/LateralTCPCacheFactory.java index 8a15bdee..c83ad167 100644 --- a/commons-jcs4-core/src/main/java/org/apache/commons/jcs4/auxiliary/lateral/socket/tcp/LateralTCPCacheFactory.java +++ b/commons-jcs4-core/src/main/java/org/apache/commons/jcs4/auxiliary/lateral/socket/tcp/LateralTCPCacheFactory.java @@ -183,12 +183,12 @@ public class LateralTCPCacheFactory final LateralTCPCacheAttributes lacClone = (LateralTCPCacheAttributes) lac.clone(); lacClone.setTcpServer( server ); - final LateralTCPCacheNoWait<K, V> lateralNoWait = createCacheNoWait(lacClone, cacheEventLogger, elementSerializer); - lateralNoWait.setKeyMatcher(keyMatcher); + final LateralTCPCacheNoWait<K, V> lateralNoWait = createCacheNoWait(lacClone, + cacheEventLogger, elementSerializer, keyMatcher); addListenerIfNeeded(lacClone, cacheMgr, elementSerializer); monitorCache(lateralNoWait); - noWaits.add( lateralNoWait ); + noWaits.add(lateralNoWait); } } @@ -197,10 +197,12 @@ public class LateralTCPCacheFactory // create the no wait facade. final LateralTCPCacheNoWaitFacade<K, V> lcnwf = new LateralTCPCacheNoWaitFacade<>(listener, noWaits, lac); + lcnwf.setCacheEventLogger(cacheEventLogger); + lcnwf.setElementSerializer(elementSerializer); lcnwf.setKeyMatcher(keyMatcher); // create udp discovery if available. - createDiscoveryService( lac, lcnwf, cacheMgr, cacheEventLogger, elementSerializer ); + createDiscoveryService(lac, lcnwf, cacheMgr); return lcnwf; } @@ -213,16 +215,19 @@ public class LateralTCPCacheFactory * @param lca the cache configuration object * @param cacheEventLogger the event logger * @param elementSerializer the serializer to use when sending or receiving + * @param keyMatcher the key matcher for getMatching() calls * @return a LateralTCPCacheNoWait */ public <K, V> LateralTCPCacheNoWait<K, V> createCacheNoWait( final ILateralTCPCacheAttributes lca, - final ICacheEventLogger cacheEventLogger, final IElementSerializer elementSerializer ) + final ICacheEventLogger cacheEventLogger, final IElementSerializer elementSerializer, + final IKeyMatcher<K> keyMatcher) { final ICacheServiceNonLocal<K, V> lateralService = getCSNLInstance(lca, elementSerializer); final LateralTCPCache<K, V> cache = new LateralTCPCache<>( lca, lateralService, this.monitor ); cache.setCacheEventLogger( cacheEventLogger ); cache.setElementSerializer( elementSerializer ); + cache.setKeyMatcher(keyMatcher); log.debug( "Created cache for noWait, cache [{0}]", cache ); @@ -241,30 +246,27 @@ public class LateralTCPCacheFactory * @param lac ILateralTCPCacheAttributes * @param lcnwf the lateral facade * @param cacheMgr a reference to the global cache manager - * @param cacheEventLogger Reference to the cache event logger for auxiliary cache creation - * @param elementSerializer Reference to the cache element serializer for auxiliary cache */ private synchronized <K, V> void createDiscoveryService( final ILateralTCPCacheAttributes lac, final LateralTCPCacheNoWaitFacade<K, V> lcnwf, - final ICompositeCacheManager cacheMgr, - final ICacheEventLogger cacheEventLogger, - final IElementSerializer elementSerializer ) + final ICompositeCacheManager cacheMgr) { // create the UDP discovery for the TCP lateral if ( lac.isUdpDiscoveryEnabled() ) { // One can be used for all regions final LateralTCPDiscoveryListener discoveryListener = - getDiscoveryListener(lac, cacheMgr, cacheEventLogger, elementSerializer); + getDiscoveryListener(lac, cacheMgr, lcnwf.getCacheEventLogger(), + lcnwf.getElementSerializer(), lcnwf.getKeyMatcher()); discoveryListener.addNoWaitFacade( lac.getCacheName(), lcnwf ); // need a factory for this so it doesn't // get dereferenced, also we don't want one for every region. final UDPDiscoveryAttributes udpAttributes = new UDPDiscoveryAttributes(lac); - UDPDiscoveryService discovery = UDPDiscoveryManager.getInstance().getService(udpAttributes, cacheMgr, - elementSerializer); + UDPDiscoveryService discovery = UDPDiscoveryManager.getInstance().getService( + udpAttributes, cacheMgr, lcnwf.getElementSerializer()); discovery.addParticipatingCacheName( lac.getCacheName() ); discovery.addDiscoveryListener( discoveryListener ); @@ -348,7 +350,6 @@ public class LateralTCPCacheFactory try { log.info( "Creating TCP service, lca = {0}", lca ); - newService = new LateralTCPService<>(lca, elementSerializer); } catch ( final IOException ex ) @@ -357,7 +358,6 @@ public class LateralTCPCacheFactory // Configure this LateralCacheManager instance to use the // "zombie" services. log.error( "Failure, lateral instance will use zombie service", ex ); - newService = new ZombieCacheServiceNonLocal<>(lca.getZombieQueueMaxSize()); // Notify the cache monitor about the error, and kick off @@ -377,11 +377,12 @@ public class LateralTCPCacheFactory * @param cacheManager a reference to the global cache manager * @param cacheEventLogger Reference to the cache event logger for auxiliary cache creation * @param elementSerializer Reference to the cache element serializer for auxiliary cache + * @param keyMatcher the key matcher for getMatching() calls * @return The instance value */ private LateralTCPDiscoveryListener getDiscoveryListener(final ILateralTCPCacheAttributes ilca, final ICompositeCacheManager cacheManager, final ICacheEventLogger cacheEventLogger, - final IElementSerializer elementSerializer) + final IElementSerializer elementSerializer, final IKeyMatcher<?> keyMatcher) { final String key = ilca.getUdpDiscoveryAddr() + ":" + ilca.getUdpDiscoveryPort(); @@ -389,8 +390,8 @@ public class LateralTCPCacheFactory log.info("Created new discovery listener for cacheName {0} and request {1}", ilca.getCacheName(), key1); return new LateralTCPDiscoveryListener( getName(), - (CompositeCacheManager) cacheManager, - cacheEventLogger, elementSerializer); + (CompositeCacheManager) cacheManager, cacheEventLogger, + elementSerializer, keyMatcher); }); } diff --git a/commons-jcs4-core/src/main/java/org/apache/commons/jcs4/auxiliary/lateral/socket/tcp/LateralTCPDiscoveryListener.java b/commons-jcs4-core/src/main/java/org/apache/commons/jcs4/auxiliary/lateral/socket/tcp/LateralTCPDiscoveryListener.java index 8d5afc7f..75725723 100644 --- a/commons-jcs4-core/src/main/java/org/apache/commons/jcs4/auxiliary/lateral/socket/tcp/LateralTCPDiscoveryListener.java +++ b/commons-jcs4-core/src/main/java/org/apache/commons/jcs4/auxiliary/lateral/socket/tcp/LateralTCPDiscoveryListener.java @@ -27,6 +27,7 @@ import java.util.concurrent.CopyOnWriteArrayList; import org.apache.commons.jcs4.engine.behavior.IElementSerializer; import org.apache.commons.jcs4.engine.control.CompositeCacheManager; import org.apache.commons.jcs4.engine.logging.behavior.ICacheEventLogger; +import org.apache.commons.jcs4.engine.match.behavior.IKeyMatcher; import org.apache.commons.jcs4.log.Log; import org.apache.commons.jcs4.utils.discovery.DiscoveredService; import org.apache.commons.jcs4.utils.discovery.behavior.IDiscoveryListener; @@ -68,6 +69,9 @@ public class LateralTCPDiscoveryListener /** Reference to the cache element serializer for auxiliary cache creation */ private final IElementSerializer elementSerializer; + /** Reference to the key matcher for auxiliary cache creation */ + private final IKeyMatcher<?> keyMatcher; + /** * This plugs into the udp discovery system. It will receive add and remove events. * @@ -76,17 +80,18 @@ public class LateralTCPDiscoveryListener * @param cacheEventLogger Reference to the cache event logger for auxiliary cache creation * @param elementSerializer Reference to the cache element serializer for auxiliary cache * creation + * @param keyMatcher the key matcher for getMatching() calls * @since 3.1 */ protected LateralTCPDiscoveryListener( final String factoryName, - final CompositeCacheManager cacheManager, - final ICacheEventLogger cacheEventLogger, - final IElementSerializer elementSerializer) + final CompositeCacheManager cacheManager, final ICacheEventLogger cacheEventLogger, + final IElementSerializer elementSerializer, final IKeyMatcher<?> keyMatcher) { this.factoryName = factoryName; this.cacheManager = cacheManager; this.cacheEventLogger = cacheEventLogger; this.elementSerializer = elementSerializer; + this.keyMatcher = keyMatcher; } /** @@ -139,7 +144,8 @@ public class LateralTCPDiscoveryListener (LateralTCPCacheFactory) cacheManager.getRegisteredAuxiliaryFactory(factoryName); final LateralTCPCacheNoWait<?, ?> noWait = - factory.createCacheNoWait(lca, cacheEventLogger, elementSerializer); + factory.createCacheNoWait(lca, cacheEventLogger, elementSerializer, + keyMatcher); factory.monitorCache(noWait); if (addNoWait(noWait)) diff --git a/commons-jcs4-core/src/main/java/org/apache/commons/jcs4/auxiliary/remote/RemoteCacheManager.java b/commons-jcs4-core/src/main/java/org/apache/commons/jcs4/auxiliary/remote/RemoteCacheManager.java index 5205ffb9..f76169e9 100644 --- a/commons-jcs4-core/src/main/java/org/apache/commons/jcs4/auxiliary/remote/RemoteCacheManager.java +++ b/commons-jcs4-core/src/main/java/org/apache/commons/jcs4/auxiliary/remote/RemoteCacheManager.java @@ -270,7 +270,7 @@ public class RemoteCacheManager listener, e ); } - final IRemoteCacheClient<K, V> remoteCacheClient = + final RemoteCache<K, V> remoteCacheClient = new RemoteCache<>(cattr, (ICacheServiceNonLocal<K, V>) remoteService, listener, monitor); remoteCacheClient.setCacheEventLogger( cacheEventLogger ); remoteCacheClient.setElementSerializer( elementSerializer ); diff --git a/commons-jcs4-core/src/main/java/org/apache/commons/jcs4/auxiliary/remote/http/client/RemoteHttpCacheFactory.java b/commons-jcs4-core/src/main/java/org/apache/commons/jcs4/auxiliary/remote/http/client/RemoteHttpCacheFactory.java index b82262ef..ba875599 100644 --- a/commons-jcs4-core/src/main/java/org/apache/commons/jcs4/auxiliary/remote/http/client/RemoteHttpCacheFactory.java +++ b/commons-jcs4-core/src/main/java/org/apache/commons/jcs4/auxiliary/remote/http/client/RemoteHttpCacheFactory.java @@ -22,7 +22,6 @@ package org.apache.commons.jcs4.auxiliary.remote.http.client; import org.apache.commons.jcs4.auxiliary.AbstractAuxiliaryCacheFactory; import org.apache.commons.jcs4.auxiliary.AuxiliaryCacheAttributes; import org.apache.commons.jcs4.auxiliary.remote.RemoteCacheNoWait; -import org.apache.commons.jcs4.auxiliary.remote.behavior.IRemoteCacheClient; import org.apache.commons.jcs4.auxiliary.remote.http.client.behavior.IRemoteHttpCacheClient; import org.apache.commons.jcs4.auxiliary.remote.server.behavior.RemoteType; import org.apache.commons.jcs4.engine.behavior.ICompositeCacheManager; @@ -77,7 +76,7 @@ public class RemoteHttpCacheFactory final IRemoteHttpCacheClient<K, V> remoteService = createRemoteHttpCacheClientForAttributes(rca); - final IRemoteCacheClient<K, V> remoteCacheClient = + final RemoteHttpCache<K, V> remoteCacheClient = new RemoteHttpCache<>( rca, remoteService, listener, monitor ); remoteCacheClient.setCacheEventLogger( cacheEventLogger ); remoteCacheClient.setElementSerializer( elementSerializer ); diff --git a/commons-jcs4-core/src/test/java/org/apache/commons/jcs4/auxiliary/lateral/socket/tcp/LateralTCPDiscoveryListenerUnitTest.java b/commons-jcs4-core/src/test/java/org/apache/commons/jcs4/auxiliary/lateral/socket/tcp/LateralTCPDiscoveryListenerUnitTest.java index d9748a6d..7f779916 100644 --- a/commons-jcs4-core/src/test/java/org/apache/commons/jcs4/auxiliary/lateral/socket/tcp/LateralTCPDiscoveryListenerUnitTest.java +++ b/commons-jcs4-core/src/test/java/org/apache/commons/jcs4/auxiliary/lateral/socket/tcp/LateralTCPDiscoveryListenerUnitTest.java @@ -71,7 +71,7 @@ class LateralTCPDiscoveryListenerUnitTest keyMatcher = new MockKeyMatcher<>(); listener = new LateralTCPDiscoveryListener( factory.getName(), cacheMgr, - cacheEventLogger, elementSerializer ); + cacheEventLogger, elementSerializer, keyMatcher); } private LateralTCPCacheNoWaitFacade<String, String> setupFacade(final String cacheName) @@ -112,7 +112,8 @@ class LateralTCPDiscoveryListenerUnitTest // used as identifying key by factory lca.setTcpServer( service.getServiceAddress() + ":" + service.getServicePort() ); lca.setCacheName(cacheName); - final LateralTCPCacheNoWait<String, String> noWait = factory.createCacheNoWait(lca, cacheEventLogger, elementSerializer); + final LateralTCPCacheNoWait<String, String> noWait = factory.createCacheNoWait(lca, + cacheEventLogger, elementSerializer, keyMatcher); // this is the normal process, the discovery service expects it there cacheMgr.addAuxiliaryCache(factory.getName(), cacheName, noWait); cacheMgr.registerAuxiliaryFactory(factory); @@ -223,7 +224,8 @@ class LateralTCPDiscoveryListenerUnitTest // used as identifying key by factory lca.setTcpServer( service.getServiceAddress() + ":" + service.getServicePort() ); lca.setCacheName(cacheName); - final LateralTCPCacheNoWait<String, String> noWait = factory.createCacheNoWait(lca, cacheEventLogger, elementSerializer); + final LateralTCPCacheNoWait<String, String> noWait = factory.createCacheNoWait(lca, + cacheEventLogger, elementSerializer, keyMatcher); // this is the normal process, the discovery service expects it there cacheMgr.addAuxiliaryCache(factory.getName(), cacheName, noWait); cacheMgr.registerAuxiliaryFactory(factory);
