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 11fce7568a4828f46997d8166182704542cf29d5 Author: Thomas Vandahl <[email protected]> AuthorDate: Wed Feb 4 16:05:36 2026 +0100 Reorganize hierarchy --- .../auxiliary/lateral/LateralCacheAttributes.java | 166 ---------------- .../auxiliary/lateral/LateralCacheMonitor.java | 15 +- .../lateral/behavior/ILateralCacheAttributes.java | 79 -------- .../tcp/LateralTCPCache.java} | 25 +-- ...ributes.java => LateralTCPCacheAttributes.java} | 112 ++++++++++- .../lateral/socket/tcp/LateralTCPCacheFactory.java | 67 +++---- .../tcp/LateralTCPCacheNoWait.java} | 20 +- .../tcp/LateralTCPCacheNoWaitFacade.java} | 50 ++--- .../socket/tcp/LateralTCPDiscoveryListener.java | 40 ++-- .../lateral/socket/tcp/LateralTCPListener.java | 14 +- .../lateral/socket/tcp/LateralTCPSender.java | 4 +- .../lateral/socket/tcp/LateralTCPService.java | 6 +- ...ibutes.java => ILateralTCPCacheAttributes.java} | 46 ++++- .../utils/discovery/UDPDiscoveryAttributes.java | 209 +++++++-------------- .../jcs4/utils/discovery/UDPDiscoveryManager.java | 26 +-- .../jcs4/utils/discovery/UDPDiscoverySender.java | 8 +- .../jcs4/utils/discovery/UDPDiscoveryService.java | 50 ++--- commons-jcs4-core/src/test/conf/cacheTCP1.ccf | 2 +- commons-jcs4-core/src/test/conf/cacheTCP2.ccf | 2 +- commons-jcs4-core/src/test/conf/cacheTCP3.ccf | 2 +- commons-jcs4-core/src/test/conf/cacheTCP4.ccf | 2 +- .../tcp}/LateralCacheNoWaitFacadeUnitTest.java | 27 ++- .../tcp/LateralTCPConcurrentRandomTestUtil.java | 2 +- .../tcp/LateralTCPDiscoveryListenerUnitTest.java | 53 +++--- .../LateralTCPFilterRemoveHashCodeUnitTest.java | 2 +- .../tcp/LateralTCPIssueRemoveOnPutUnitTest.java | 4 +- .../lateral/socket/tcp/TestTCPLateralUnitTest.java | 6 +- .../discovery/UDPDiscoveryServiceUnitTest.java | 10 +- .../jcs4/utils/discovery/UDPDiscoveryUnitTest.java | 15 +- .../src/test/test-conf/TestTCPLateralCache.ccf | 2 +- .../test-conf/TestTCPLateralCacheConcurrent.ccf | 2 +- .../test-conf/TestTCPLateralIssueRemoveCache.ccf | 2 +- .../test/test-conf/TestTCPLateralRemoveFilter.ccf | 2 +- .../src/test/test-conf/TestUDPDiscovery.ccf | 4 +- xdocs/LateralTCPProperties.xml | 7 + 35 files changed, 455 insertions(+), 628 deletions(-) diff --git a/commons-jcs4-core/src/main/java/org/apache/commons/jcs4/auxiliary/lateral/LateralCacheAttributes.java b/commons-jcs4-core/src/main/java/org/apache/commons/jcs4/auxiliary/lateral/LateralCacheAttributes.java deleted file mode 100644 index 8c280107..00000000 --- a/commons-jcs4-core/src/main/java/org/apache/commons/jcs4/auxiliary/lateral/LateralCacheAttributes.java +++ /dev/null @@ -1,166 +0,0 @@ -package org.apache.commons.jcs4.auxiliary.lateral; - -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -import org.apache.commons.jcs4.auxiliary.AbstractAuxiliaryCacheAttributes; -import org.apache.commons.jcs4.auxiliary.lateral.behavior.ILateralCacheAttributes; - -/** - * This class stores attributes for all of the available lateral cache auxiliaries. - */ -public class LateralCacheAttributes - extends AbstractAuxiliaryCacheAttributes - implements ILateralCacheAttributes -{ - /** Don't change */ - private static final long serialVersionUID = -3408449508837393660L; - - /** Default receive setting */ - private static final boolean DEFAULT_RECEIVE = true; - - /** This needs to change */ - private String udpMulticastAddr = "228.5.6.7"; - - /** This needs to change */ - private int udpMulticastPort = 6789; - - /** Disables gets from laterals */ - private boolean putOnlyMode = true; - - /** - * do we receive and broadcast or only broadcast this is useful when you don't want to get any - * notifications - */ - private boolean receive = DEFAULT_RECEIVE; - - /** If the primary fails, we will queue items before reconnect. This limits the number of items that can be queued. */ - private int zombieQueueMaxSize = DEFAULT_ZOMBIE_QUEUE_MAX_SIZE; - - /** - * @return The outgoingOnlyMode value. Stops gets from going remote. - */ - @Override - public boolean getPutOnlyMode() - { - return putOnlyMode; - } - - /** - * Gets the udpMulticastAddr attribute of the LateralCacheAttributes object - * @return The udpMulticastAddr value - */ - @Override - public String getUdpMulticastAddr() - { - return udpMulticastAddr; - } - - /** - * Gets the udpMulticastPort attribute of the LateralCacheAttributes object - * @return The udpMulticastPort value - */ - @Override - public int getUdpMulticastPort() - { - return udpMulticastPort; - } - - /** - * The number of elements the zombie queue will hold. This queue is used to store events if we - * loose our connection with the server. - * - * @return the zombieQueueMaxSize. - */ - @Override - public int getZombieQueueMaxSize() - { - return zombieQueueMaxSize; - } - - /** - * @return the receive. - */ - @Override - public boolean isReceive() - { - return receive; - } - - /** - * Sets the outgoingOnlyMode attribute of the ILateralCacheAttributes. When this is true the - * lateral cache will only issue put and remove order and will not try to retrieve elements from - * other lateral caches. - * @param val The new transmissionTypeName value - */ - public void setPutOnlyMode( final boolean val ) - { - this.putOnlyMode = val; - } - - /** - * @param receive The receive to set. - */ - public void setReceive( final boolean receive ) - { - this.receive = receive; - } - - /** - * Sets the udpMulticastAddr attribute of the LateralCacheAttributes object - * @param val The new udpMulticastAddr value - */ - public void setUdpMulticastAddr( final String val ) - { - udpMulticastAddr = val; - } - - /** - * Sets the udpMulticastPort attribute of the LateralCacheAttributes object - * @param val The new udpMulticastPort value - */ - public void setUdpMulticastPort( final int val ) - { - udpMulticastPort = val; - } - - /** - * The number of elements the zombie queue will hold. This queue is used to store events if we - * loose our connection with the server. - * - * @param zombieQueueMaxSize The zombieQueueMaxSize to set. - */ - public void setZombieQueueMaxSize( final int zombieQueueMaxSize ) - { - this.zombieQueueMaxSize = zombieQueueMaxSize; - } - - /** - * @return debug string. - */ - @Override - public String toString() - { - final StringBuilder buf = new StringBuilder(); - //buf.append( "cacheName=" + cacheName + "\n" ); - //buf.append( "putOnlyMode=" + putOnlyMode + "\n" ); - buf.append(udpMulticastAddr + String.valueOf( udpMulticastPort ) ); - return buf.toString(); - } -} diff --git a/commons-jcs4-core/src/main/java/org/apache/commons/jcs4/auxiliary/lateral/LateralCacheMonitor.java b/commons-jcs4-core/src/main/java/org/apache/commons/jcs4/auxiliary/lateral/LateralCacheMonitor.java index 10c779f2..554ce8dc 100644 --- a/commons-jcs4-core/src/main/java/org/apache/commons/jcs4/auxiliary/lateral/LateralCacheMonitor.java +++ b/commons-jcs4-core/src/main/java/org/apache/commons/jcs4/auxiliary/lateral/LateralCacheMonitor.java @@ -22,8 +22,9 @@ package org.apache.commons.jcs4.auxiliary.lateral; import java.util.concurrent.ConcurrentHashMap; import org.apache.commons.jcs4.auxiliary.AbstractAuxiliaryCacheMonitor; +import org.apache.commons.jcs4.auxiliary.lateral.socket.tcp.LateralTCPCacheNoWait; import org.apache.commons.jcs4.auxiliary.lateral.socket.tcp.LateralTCPCacheFactory; -import org.apache.commons.jcs4.auxiliary.lateral.socket.tcp.behavior.ITCPLateralCacheAttributes; +import org.apache.commons.jcs4.auxiliary.lateral.socket.tcp.behavior.ILateralTCPCacheAttributes; import org.apache.commons.jcs4.engine.CacheStatus; import org.apache.commons.jcs4.engine.ZombieCacheServiceNonLocal; import org.apache.commons.jcs4.engine.behavior.ICacheServiceNonLocal; @@ -40,7 +41,7 @@ public class LateralCacheMonitor extends AbstractAuxiliaryCacheMonitor /** * Map of caches to monitor */ - private final ConcurrentHashMap<String, LateralCacheNoWait<Object, Object>> caches; + private final ConcurrentHashMap<String, LateralTCPCacheNoWait<Object, Object>> caches; /** * Reference to the factory @@ -68,9 +69,9 @@ public class LateralCacheMonitor extends AbstractAuxiliaryCacheMonitor * @param cache the cache */ @SuppressWarnings("unchecked") // common map for all caches - public void addCache(final LateralCacheNoWait<?, ?> cache) + public void addCache(final LateralTCPCacheNoWait<?, ?> cache) { - this.caches.put(cache.getCacheName(), (LateralCacheNoWait<Object, Object>)cache); + this.caches.put(cache.getCacheName(), (LateralTCPCacheNoWait<Object, Object>)cache); // if not yet started, go ahead if (getState() == Thread.State.NEW) @@ -101,10 +102,10 @@ public class LateralCacheMonitor extends AbstractAuxiliaryCacheMonitor if (cache.getStatus() == CacheStatus.ERROR) { - log.info( "Found LateralCacheNoWait in error, " + cacheName ); + log.info( "Found LateralTCPCacheNoWait in error, " + cacheName ); - final ITCPLateralCacheAttributes lca = - (ITCPLateralCacheAttributes) cache.getAuxiliaryCacheAttributes(); + final ILateralTCPCacheAttributes lca = + (ILateralTCPCacheAttributes) cache.getAuxiliaryCacheAttributes(); // Get service instance final ICacheServiceNonLocal<Object, Object> cacheService = diff --git a/commons-jcs4-core/src/main/java/org/apache/commons/jcs4/auxiliary/lateral/behavior/ILateralCacheAttributes.java b/commons-jcs4-core/src/main/java/org/apache/commons/jcs4/auxiliary/lateral/behavior/ILateralCacheAttributes.java deleted file mode 100644 index c61e5e1e..00000000 --- a/commons-jcs4-core/src/main/java/org/apache/commons/jcs4/auxiliary/lateral/behavior/ILateralCacheAttributes.java +++ /dev/null @@ -1,79 +0,0 @@ -package org.apache.commons.jcs4.auxiliary.lateral.behavior; - -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -import org.apache.commons.jcs4.auxiliary.AuxiliaryCacheAttributes; - -/** - * This interface defines configuration options common to lateral cache plugins. - * <p> - * TODO it needs to be trimmed down. The old version had features for every lateral. Now, the - * individual laterals have their own specific attributes interfaces. - */ -public interface ILateralCacheAttributes - extends AuxiliaryCacheAttributes -{ - /** - * The number of elements the zombie queue will hold. This queue is used to store events if we - * loose our connection with the server. - */ - int DEFAULT_ZOMBIE_QUEUE_MAX_SIZE = 1000; - - /** - * @return The outgoingOnlyMode value. Stops gets from going remote. - */ - boolean getPutOnlyMode(); - - /** - * Gets the udpMulticastAddr attribute of the ILateralCacheAttributes object - * - * @return The udpMulticastAddr value - */ - String getUdpMulticastAddr(); - - /** - * Gets the udpMulticastPort attribute of the ILateralCacheAttributes object - * - * @return The udpMulticastPort value - */ - int getUdpMulticastPort(); - - /** - * The number of elements the zombie queue will hold. This queue is used to store events if we - * loose our connection with the server. - * - * @return the zombieQueueMaxSize. - */ - int getZombieQueueMaxSize(); - - /** - * Should a listener be created. By default this is true. - * <p> - * If this is false the lateral will connect to others but it will not create a listener to - * receive. - * <p> - * It is possible if two laterals are misconfigured that lateral A may have a region R1 that is - * not configured for the lateral but another is. And if cache B has region R1 configured for - * lateral distribution, A will get messages for R1 but not send them. - * - * @return true if we should have a listener connection - */ - boolean isReceive(); -} diff --git a/commons-jcs4-core/src/main/java/org/apache/commons/jcs4/auxiliary/lateral/LateralCache.java b/commons-jcs4-core/src/main/java/org/apache/commons/jcs4/auxiliary/lateral/socket/tcp/LateralTCPCache.java similarity index 92% rename from commons-jcs4-core/src/main/java/org/apache/commons/jcs4/auxiliary/lateral/LateralCache.java rename to commons-jcs4-core/src/main/java/org/apache/commons/jcs4/auxiliary/lateral/socket/tcp/LateralTCPCache.java index 0dc392a7..703d69e4 100644 --- a/commons-jcs4-core/src/main/java/org/apache/commons/jcs4/auxiliary/lateral/LateralCache.java +++ b/commons-jcs4-core/src/main/java/org/apache/commons/jcs4/auxiliary/lateral/socket/tcp/LateralTCPCache.java @@ -1,4 +1,4 @@ -package org.apache.commons.jcs4.auxiliary.lateral; +package org.apache.commons.jcs4.auxiliary.lateral.socket.tcp; /* * Licensed to the Apache Software Foundation (ASF) under one @@ -25,7 +25,8 @@ import java.util.Map; import java.util.Set; import org.apache.commons.jcs4.auxiliary.AbstractAuxiliaryCacheEventLogging; -import org.apache.commons.jcs4.auxiliary.lateral.behavior.ILateralCacheAttributes; +import org.apache.commons.jcs4.auxiliary.lateral.LateralCacheMonitor; +import org.apache.commons.jcs4.auxiliary.lateral.socket.tcp.behavior.ILateralTCPCacheAttributes; import org.apache.commons.jcs4.engine.CacheInfo; import org.apache.commons.jcs4.engine.CacheStatus; import org.apache.commons.jcs4.engine.ZombieCacheServiceNonLocal; @@ -39,14 +40,14 @@ import org.apache.commons.jcs4.log.Log; /** * Lateral distributor. Returns null on get by default. Net search not implemented. */ -public class LateralCache<K, V> +public class LateralTCPCache<K, V> extends AbstractAuxiliaryCacheEventLogging<K, V> { /** The logger. */ - private static final Log log = Log.getLog( LateralCache.class ); + private static final Log log = Log.getLog( LateralTCPCache.class ); /** Generalize this, use another interface */ - private final ILateralCacheAttributes lateralCacheAttributes; + private final ILateralTCPCacheAttributes lateralCacheAttributes; /** The region name */ final String cacheName; @@ -58,13 +59,13 @@ public class LateralCache<K, V> private final LateralCacheMonitor monitor; /** - * Constructor for the LateralCache object + * Constructor for the LateralTCPCache object * * @param cattr * @param lateral * @param monitor */ - public LateralCache( final ILateralCacheAttributes cattr, final ICacheServiceNonLocal<K, V> lateral, final LateralCacheMonitor monitor ) + public LateralTCPCache( final ILateralTCPCacheAttributes cattr, final ICacheServiceNonLocal<K, V> lateral, final LateralCacheMonitor monitor ) { this.cacheName = cattr.getCacheName(); this.lateralCacheAttributes = cattr; @@ -109,13 +110,13 @@ public class LateralCache<K, V> * @return the AuxiliaryCacheAttributes. */ @Override - public ILateralCacheAttributes getAuxiliaryCacheAttributes() + public ILateralTCPCacheAttributes getAuxiliaryCacheAttributes() { return lateralCacheAttributes; } /** - * Gets the cacheName attribute of the LateralCache object + * Gets the cacheName attribute of the LateralTCPCache object * * @return The cacheName value */ @@ -126,7 +127,7 @@ public class LateralCache<K, V> } /** - * Gets the cacheType attribute of the LateralCache object + * Gets the cacheType attribute of the LateralTCPCache object * * @return The cacheType value */ @@ -185,7 +186,7 @@ public class LateralCache<K, V> public IStats getStatistics() { final IStats stats = new Stats(); - stats.setTypeName( "LateralCache" ); + stats.setTypeName( "LateralTCPCache" ); return stats; } @@ -394,7 +395,7 @@ public class LateralCache<K, V> public String toString() { final StringBuilder buf = new StringBuilder(); - buf.append( "\n LateralCache " ); + buf.append( "\n LateralTCPCache " ); buf.append( "\n Cache Name [" + lateralCacheAttributes.getCacheName() + "]" ); buf.append( "\n cattr = [" + lateralCacheAttributes + "]" ); return buf.toString(); diff --git a/commons-jcs4-core/src/main/java/org/apache/commons/jcs4/auxiliary/lateral/socket/tcp/TCPLateralCacheAttributes.java b/commons-jcs4-core/src/main/java/org/apache/commons/jcs4/auxiliary/lateral/socket/tcp/LateralTCPCacheAttributes.java similarity index 78% rename from commons-jcs4-core/src/main/java/org/apache/commons/jcs4/auxiliary/lateral/socket/tcp/TCPLateralCacheAttributes.java rename to commons-jcs4-core/src/main/java/org/apache/commons/jcs4/auxiliary/lateral/socket/tcp/LateralTCPCacheAttributes.java index efa0d6bc..d0034666 100644 --- a/commons-jcs4-core/src/main/java/org/apache/commons/jcs4/auxiliary/lateral/socket/tcp/TCPLateralCacheAttributes.java +++ b/commons-jcs4-core/src/main/java/org/apache/commons/jcs4/auxiliary/lateral/socket/tcp/LateralTCPCacheAttributes.java @@ -19,16 +19,16 @@ package org.apache.commons.jcs4.auxiliary.lateral.socket.tcp; * under the License. */ -import org.apache.commons.jcs4.auxiliary.lateral.LateralCacheAttributes; -import org.apache.commons.jcs4.auxiliary.lateral.socket.tcp.behavior.ITCPLateralCacheAttributes; +import org.apache.commons.jcs4.auxiliary.AbstractAuxiliaryCacheAttributes; +import org.apache.commons.jcs4.auxiliary.lateral.socket.tcp.behavior.ILateralTCPCacheAttributes; /** * This interface defines functions that are particular to the TCP Lateral Cache plugin. It extends * the generic LateralCacheAttributes interface which in turn extends the AuxiliaryCache interface. */ -public class TCPLateralCacheAttributes - extends LateralCacheAttributes - implements ITCPLateralCacheAttributes +public class LateralTCPCacheAttributes + extends AbstractAuxiliaryCacheAttributes + implements ILateralTCPCacheAttributes { /** Don't change. */ private static final long serialVersionUID = 1077889204513905220L; @@ -75,6 +75,9 @@ public class TCPLateralCacheAttributes /** Udp discovery for tcp server */ private String udpDiscoveryAddr = DEFAULT_UDP_DISCOVERY_ADDRESS; + /** Udp discovery network interface */ + private String udpDiscoveryInterface = null; + /** Discovery port */ private int udpDiscoveryPort = DEFAULT_UDP_DISCOVERY_PORT; @@ -102,6 +105,22 @@ public class TCPLateralCacheAttributes /** Only block for openTimeOut seconds before timing out on startup. */ private int openTimeOut = DEFAULT_OPEN_TIMEOUT; + + /** Default receive setting */ + private static final boolean DEFAULT_RECEIVE = true; + + /** Disables gets from laterals */ + private boolean putOnlyMode = true; + + /** + * do we receive and broadcast or only broadcast this is useful when you don't want to get any + * notifications + */ + private boolean receive = DEFAULT_RECEIVE; + + /** If the primary fails, we will queue items before reconnect. This limits the number of items that can be queued. */ + private int zombieQueueMaxSize = DEFAULT_ZOMBIE_QUEUE_MAX_SIZE; + /** * @return the openTimeOut */ @@ -176,6 +195,17 @@ public class TCPLateralCacheAttributes } /** + * The UDP discovery network interface if UDPDiscovery is enabled. + * + * @return the udpDiscoveryInterface. + */ + @Override + public String getUdpDiscoveryInterface() + { + return this.udpDiscoveryInterface; + } + + /** * The port to use if UDPDiscovery is enabled. * * @return the udpDiscoveryPort. @@ -375,7 +405,7 @@ public class TCPLateralCacheAttributes } /** - * Can setup UDP Discovery. This only works for TCp laterals right now. It allows TCP laterals + * Can setup UDP Discovery. This only works for TCP laterals right now. It allows TCP laterals * to find each other by broadcasting to a multicast port. * * @param udpDiscoveryEnabled The udpDiscoveryEnabled to set. @@ -385,6 +415,16 @@ public class TCPLateralCacheAttributes this.udpDiscoveryEnabled = udpDiscoveryEnabled; } + /** + * Sets the UDP discovery network interface if UDPDiscovery is enabled. + * + * @param udpDiscoveryInterface the udpDiscoveryInterface to set (symbolic name) + */ + public void setUdpDiscoveryInterface(String udpDiscoveryInterface) + { + this.udpDiscoveryInterface = udpDiscoveryInterface; + } + /** * Sets the port to use if UDPDiscovery is enabled. * @@ -406,6 +446,66 @@ public class TCPLateralCacheAttributes this.udpTTL = udpTTL; } + /** + * @return The outgoingOnlyMode value. Stops gets from going remote. + */ + @Override + public boolean getPutOnlyMode() + { + return putOnlyMode; + } + + /** + * The number of elements the zombie queue will hold. This queue is used to store events if we + * loose our connection with the server. + * + * @return the zombieQueueMaxSize. + */ + @Override + public int getZombieQueueMaxSize() + { + return zombieQueueMaxSize; + } + + /** + * @return the receive. + */ + @Override + public boolean isReceive() + { + return receive; + } + + /** + * Sets the outgoingOnlyMode attribute of the ILateralCacheAttributes. When this is true the + * lateral cache will only issue put and remove order and will not try to retrieve elements from + * other lateral caches. + * @param val The new transmissionTypeName value + */ + public void setPutOnlyMode( final boolean val ) + { + this.putOnlyMode = val; + } + + /** + * @param receive The receive to set. + */ + public void setReceive( final boolean receive ) + { + this.receive = receive; + } + + /** + * The number of elements the zombie queue will hold. This queue is used to store events if we + * loose our connection with the server. + * + * @param zombieQueueMaxSize The zombieQueueMaxSize to set. + */ + public void setZombieQueueMaxSize( final int zombieQueueMaxSize ) + { + this.zombieQueueMaxSize = zombieQueueMaxSize; + } + /** * Used to key the instance TODO create another method for this and use toString for debugging * only. 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 d027167e..ed5b169d 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 @@ -25,12 +25,9 @@ import java.util.concurrent.ConcurrentHashMap; import org.apache.commons.jcs4.auxiliary.AbstractAuxiliaryCacheFactory; import org.apache.commons.jcs4.auxiliary.AuxiliaryCacheAttributes; -import org.apache.commons.jcs4.auxiliary.lateral.LateralCache; import org.apache.commons.jcs4.auxiliary.lateral.LateralCacheMonitor; -import org.apache.commons.jcs4.auxiliary.lateral.LateralCacheNoWait; -import org.apache.commons.jcs4.auxiliary.lateral.LateralCacheNoWaitFacade; import org.apache.commons.jcs4.auxiliary.lateral.behavior.ILateralCacheListener; -import org.apache.commons.jcs4.auxiliary.lateral.socket.tcp.behavior.ITCPLateralCacheAttributes; +import org.apache.commons.jcs4.auxiliary.lateral.socket.tcp.behavior.ILateralTCPCacheAttributes; import org.apache.commons.jcs4.engine.CacheWatchRepairable; import org.apache.commons.jcs4.engine.ZombieCacheServiceNonLocal; import org.apache.commons.jcs4.engine.ZombieCacheWatch; @@ -41,11 +38,12 @@ import org.apache.commons.jcs4.engine.behavior.IShutdownObserver; import org.apache.commons.jcs4.engine.control.CompositeCacheManager; import org.apache.commons.jcs4.engine.logging.behavior.ICacheEventLogger; import org.apache.commons.jcs4.log.Log; +import org.apache.commons.jcs4.utils.discovery.UDPDiscoveryAttributes; import org.apache.commons.jcs4.utils.discovery.UDPDiscoveryManager; import org.apache.commons.jcs4.utils.discovery.UDPDiscoveryService; /** - * Constructs a LateralCacheNoWaitFacade for the given configuration. Each lateral service / local + * Constructs a LateralTCPCacheNoWaitFacade for the given configuration. Each lateral service / local * relationship is managed by one manager. This manager can have multiple caches. The remote * relationships are consolidated and restored via these managers. * <p> @@ -63,12 +61,12 @@ public class LateralTCPCacheFactory * <p> * This should be called by create cache. * - * @param attr ITCPLateralCacheAttributes + * @param attr ILateralTCPCacheAttributes * @param cacheMgr the composite cache manager * @param serializer the serializer to use when receiving * @return the listener if created, else null */ - private static <K, V> ILateralCacheListener<K, V> createListener( final ITCPLateralCacheAttributes attr, + private static <K, V> ILateralCacheListener<K, V> createListener( final ILateralTCPCacheAttributes attr, final ICompositeCacheManager cacheMgr, final IElementSerializer elementSerializer ) { ILateralCacheListener<K, V> listener = null; @@ -130,7 +128,7 @@ public class LateralTCPCacheFactory * @param cacheMgr the composite cache manager * @param serializer the serializer to use when receiving */ - private void addListenerIfNeeded( final ITCPLateralCacheAttributes iaca, final ICompositeCacheManager cacheMgr, final IElementSerializer elementSerializer ) + private void addListenerIfNeeded( final ILateralTCPCacheAttributes iaca, final ICompositeCacheManager cacheMgr, final IElementSerializer elementSerializer ) { // don't create a listener if we are not receiving. if ( iaca.isReceive() ) @@ -159,15 +157,15 @@ public class LateralTCPCacheFactory * @param cacheMgr the cache manager * @param cacheEventLogger the event logger * @param elementSerializer the serializer to use when sending or receiving - * @return a LateralCacheNoWaitFacade + * @return a LateralTCPCacheNoWaitFacade */ @Override - public <K, V> LateralCacheNoWaitFacade<K, V> createCache( + public <K, V> LateralTCPCacheNoWaitFacade<K, V> createCache( final AuxiliaryCacheAttributes iaca, final ICompositeCacheManager cacheMgr, final ICacheEventLogger cacheEventLogger, final IElementSerializer elementSerializer ) { - final ITCPLateralCacheAttributes lac = (ITCPLateralCacheAttributes) iaca; - final ArrayList<LateralCacheNoWait<K, V>> noWaits = new ArrayList<>(); + final ILateralTCPCacheAttributes lac = (ILateralTCPCacheAttributes) iaca; + final ArrayList<LateralTCPCacheNoWait<K, V>> noWaits = new ArrayList<>(); // pairs up the tcp servers and set the tcpServer value and // get the manager and then get the cache @@ -180,10 +178,10 @@ public class LateralTCPCacheFactory for (final String server : servers) { log.debug( "tcp server = {0}", server ); - final TCPLateralCacheAttributes lacClone = (TCPLateralCacheAttributes) lac.clone(); + final LateralTCPCacheAttributes lacClone = (LateralTCPCacheAttributes) lac.clone(); lacClone.setTcpServer( server ); - final LateralCacheNoWait<K, V> lateralNoWait = createCacheNoWait(lacClone, cacheEventLogger, elementSerializer); + final LateralTCPCacheNoWait<K, V> lateralNoWait = createCacheNoWait(lacClone, cacheEventLogger, elementSerializer); addListenerIfNeeded( lacClone, cacheMgr, elementSerializer ); monitorCache(lateralNoWait); @@ -194,8 +192,8 @@ public class LateralTCPCacheFactory final ILateralCacheListener<K, V> listener = createListener( lac, cacheMgr, elementSerializer ); // create the no wait facade. - final LateralCacheNoWaitFacade<K, V> lcnwf = - new LateralCacheNoWaitFacade<>(listener, noWaits, lac); + final LateralTCPCacheNoWaitFacade<K, V> lcnwf = + new LateralTCPCacheNoWaitFacade<>(listener, noWaits, lac); // create udp discovery if available. createDiscoveryService( lac, lcnwf, cacheMgr, cacheEventLogger, elementSerializer ); @@ -204,30 +202,30 @@ public class LateralTCPCacheFactory } /** - * Create a LateralCacheNoWait for the server configured in lca + * Create a LateralTCPCacheNoWait for the server configured in lca * * @param <K> cache key type * @param <V> cache value type * @param lca the cache configuration object * @param cacheEventLogger the event logger * @param elementSerializer the serializer to use when sending or receiving - * @return a LateralCacheNoWait + * @return a LateralTCPCacheNoWait */ - public <K, V> LateralCacheNoWait<K, V> createCacheNoWait( final ITCPLateralCacheAttributes lca, + public <K, V> LateralTCPCacheNoWait<K, V> createCacheNoWait( final ILateralTCPCacheAttributes lca, final ICacheEventLogger cacheEventLogger, final IElementSerializer elementSerializer ) { final ICacheServiceNonLocal<K, V> lateralService = getCSNLInstance(lca, elementSerializer); - final LateralCache<K, V> cache = new LateralCache<>( lca, lateralService, this.monitor ); + final LateralTCPCache<K, V> cache = new LateralTCPCache<>( lca, lateralService, this.monitor ); cache.setCacheEventLogger( cacheEventLogger ); cache.setElementSerializer( elementSerializer ); log.debug( "Created cache for noWait, cache [{0}]", cache ); - final LateralCacheNoWait<K, V> lateralNoWait = new LateralCacheNoWait<>( cache ); + final LateralTCPCacheNoWait<K, V> lateralNoWait = new LateralTCPCacheNoWait<>( cache ); lateralNoWait.setIdentityKey(lca.getTcpServer()); - log.info( "Created LateralCacheNoWait for [{0}] LateralCacheNoWait = [{1}]", + log.info( "Created LateralTCPCacheNoWait for [{0}] LateralTCPCacheNoWait = [{1}]", lca, lateralNoWait ); return lateralNoWait; @@ -236,15 +234,15 @@ public class LateralTCPCacheFactory /** * Creates the discovery service. Only creates this for tcp laterals right now. * - * @param lac ITCPLateralCacheAttributes + * @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 ITCPLateralCacheAttributes lac, - final LateralCacheNoWaitFacade<K, V> lcnwf, + final ILateralTCPCacheAttributes lac, + final LateralTCPCacheNoWaitFacade<K, V> lcnwf, final ICompositeCacheManager cacheMgr, final ICacheEventLogger cacheEventLogger, final IElementSerializer elementSerializer ) @@ -261,10 +259,13 @@ public class LateralTCPCacheFactory // need a factory for this so it doesn't // get dereferenced, also we don't want one for every region. - discovery = UDPDiscoveryManager.getInstance().getService( - lac.getUdpDiscoveryAddr(), lac.getUdpDiscoveryPort(), - lac.getTcpListenerHost(), lac.getTcpListenerPort(), lac.getUdpTTL(), - cacheMgr, elementSerializer); + final UDPDiscoveryAttributes udpAttributes = new UDPDiscoveryAttributes( + lac.getTcpListenerHost(), lac.getTcpListenerPort(), lac.getUdpDiscoveryAddr(), + lac.getUdpDiscoveryInterface(), lac.getUdpDiscoveryPort(), lac.getUdpTTL(), + UDPDiscoveryAttributes.defaults().maxIdleTimeSec()); + + discovery = UDPDiscoveryManager.getInstance().getService(udpAttributes, cacheMgr, + elementSerializer); discovery.addParticipatingCacheName( lac.getCacheName() ); discovery.addDiscoveryListener( discoveryListener ); @@ -324,7 +325,7 @@ public class LateralTCPCacheFactory */ // Need to cast because of common map for all cache services @SuppressWarnings("unchecked") - public <K, V> ICacheServiceNonLocal<K, V> getCSNLInstance(final ITCPLateralCacheAttributes lca, + public <K, V> ICacheServiceNonLocal<K, V> getCSNLInstance(final ILateralTCPCacheAttributes lca, final IElementSerializer elementSerializer) { final String key = lca.getTcpServer(); @@ -373,13 +374,13 @@ public class LateralTCPCacheFactory /** * Gets the instance attribute of the LateralCacheTCPListener class. * - * @param ilca ITCPLateralCacheAttributes + * @param ilca ILateralTCPCacheAttributes * @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 * @return The instance value */ - private LateralTCPDiscoveryListener getDiscoveryListener(final ITCPLateralCacheAttributes ilca, + private LateralTCPDiscoveryListener getDiscoveryListener(final ILateralTCPCacheAttributes ilca, final ICompositeCacheManager cacheManager, final ICacheEventLogger cacheEventLogger, final IElementSerializer elementSerializer) { @@ -418,7 +419,7 @@ public class LateralTCPCacheFactory * @param cache the cache instance * @since 3.1 */ - public void monitorCache(final LateralCacheNoWait<?, ?> cache) + public void monitorCache(final LateralTCPCacheNoWait<?, ?> cache) { monitor.addCache(cache); } diff --git a/commons-jcs4-core/src/main/java/org/apache/commons/jcs4/auxiliary/lateral/LateralCacheNoWait.java b/commons-jcs4-core/src/main/java/org/apache/commons/jcs4/auxiliary/lateral/socket/tcp/LateralTCPCacheNoWait.java similarity index 94% rename from commons-jcs4-core/src/main/java/org/apache/commons/jcs4/auxiliary/lateral/LateralCacheNoWait.java rename to commons-jcs4-core/src/main/java/org/apache/commons/jcs4/auxiliary/lateral/socket/tcp/LateralTCPCacheNoWait.java index dd5df3a7..1711e3de 100644 --- a/commons-jcs4-core/src/main/java/org/apache/commons/jcs4/auxiliary/lateral/LateralCacheNoWait.java +++ b/commons-jcs4-core/src/main/java/org/apache/commons/jcs4/auxiliary/lateral/socket/tcp/LateralTCPCacheNoWait.java @@ -1,4 +1,4 @@ -package org.apache.commons.jcs4.auxiliary.lateral; +package org.apache.commons.jcs4.auxiliary.lateral.socket.tcp; /* * Licensed to the Apache Software Foundation (ASF) under one @@ -30,7 +30,7 @@ import java.util.Set; import java.util.stream.Collectors; import org.apache.commons.jcs4.auxiliary.AbstractAuxiliaryCache; -import org.apache.commons.jcs4.auxiliary.lateral.behavior.ILateralCacheAttributes; +import org.apache.commons.jcs4.auxiliary.lateral.socket.tcp.behavior.ILateralTCPCacheAttributes; import org.apache.commons.jcs4.engine.CacheAdaptor; import org.apache.commons.jcs4.engine.CacheEventQueueFactory; import org.apache.commons.jcs4.engine.CacheInfo; @@ -48,14 +48,14 @@ import org.apache.commons.jcs4.log.Log; * Used to queue up update requests to the underlying cache. These requests will be processed in * their order of arrival via the cache event queue processor. */ -public class LateralCacheNoWait<K, V> +public class LateralTCPCacheNoWait<K, V> extends AbstractAuxiliaryCache<K, V> { /** The logger. */ - private static final Log log = Log.getLog( LateralCacheNoWait.class ); + private static final Log log = Log.getLog( LateralTCPCacheNoWait.class ); /** The cache */ - private final LateralCache<K, V> cache; + private final LateralTCPCache<K, V> cache; /** Identify this object */ private String identityKey; @@ -78,14 +78,14 @@ public class LateralCacheNoWait<K, V> * * @param cache */ - public LateralCacheNoWait( final LateralCache<K, V> cache ) + public LateralTCPCacheNoWait( final LateralTCPCache<K, V> cache ) { this.cache = cache; this.identityKey = cache.getCacheName(); setCacheEventLogger(cache.getCacheEventLogger()); setElementSerializer(cache.getElementSerializer()); - log.debug( "Constructing LateralCacheNoWait, LateralCache = [{0}]", cache ); + log.debug( "Constructing LateralTCPCacheNoWait, LateralTCPCache = [{0}]", cache ); final CacheEventQueueFactory<K, V> fact = new CacheEventQueueFactory<>(); this.eventQueue = fact.createCacheEventQueue( new CacheAdaptor<>( cache ), @@ -173,13 +173,13 @@ public class LateralCacheNoWait<K, V> * @return the AuxiliaryCacheAttributes. */ @Override - public ILateralCacheAttributes getAuxiliaryCacheAttributes() + public ILateralTCPCacheAttributes getAuxiliaryCacheAttributes() { return cache.getAuxiliaryCacheAttributes(); } /** - * Gets the cacheName attribute of the LateralCacheNoWait object + * Gets the cacheName attribute of the LateralTCPCacheNoWait object * * @return The cacheName value */ @@ -431,7 +431,7 @@ public class LateralCacheNoWait<K, V> public String toString() { final StringBuilder buf = new StringBuilder(); - buf.append( " LateralCacheNoWait " ); + buf.append( " LateralTCPCacheNoWait " ); buf.append( " Status = " + this.getStatus() ); buf.append( " cache = [" + cache.toString() + "]" ); return buf.toString(); diff --git a/commons-jcs4-core/src/main/java/org/apache/commons/jcs4/auxiliary/lateral/LateralCacheNoWaitFacade.java b/commons-jcs4-core/src/main/java/org/apache/commons/jcs4/auxiliary/lateral/socket/tcp/LateralTCPCacheNoWaitFacade.java similarity index 85% rename from commons-jcs4-core/src/main/java/org/apache/commons/jcs4/auxiliary/lateral/LateralCacheNoWaitFacade.java rename to commons-jcs4-core/src/main/java/org/apache/commons/jcs4/auxiliary/lateral/socket/tcp/LateralTCPCacheNoWaitFacade.java index 1aec5a07..7dbc24dc 100644 --- a/commons-jcs4-core/src/main/java/org/apache/commons/jcs4/auxiliary/lateral/LateralCacheNoWaitFacade.java +++ b/commons-jcs4-core/src/main/java/org/apache/commons/jcs4/auxiliary/lateral/socket/tcp/LateralTCPCacheNoWaitFacade.java @@ -1,4 +1,4 @@ -package org.apache.commons.jcs4.auxiliary.lateral; +package org.apache.commons.jcs4.auxiliary.lateral.socket.tcp; /* * Licensed to the Apache Software Foundation (ASF) under one @@ -33,8 +33,8 @@ import java.util.concurrent.atomic.AtomicBoolean; import java.util.stream.Collectors; import org.apache.commons.jcs4.auxiliary.AbstractAuxiliaryCache; -import org.apache.commons.jcs4.auxiliary.lateral.behavior.ILateralCacheAttributes; import org.apache.commons.jcs4.auxiliary.lateral.behavior.ILateralCacheListener; +import org.apache.commons.jcs4.auxiliary.lateral.socket.tcp.behavior.ILateralTCPCacheAttributes; import org.apache.commons.jcs4.engine.CacheStatus; import org.apache.commons.jcs4.engine.behavior.ICacheElement; import org.apache.commons.jcs4.engine.stats.StatElement; @@ -45,20 +45,20 @@ import org.apache.commons.jcs4.log.Log; /** * Used to provide access to multiple services under nowait protection. Composite factory should - * construct LateralCacheNoWaitFacade to give to the composite cache out of caches it constructs + * construct LateralTCPCacheNoWaitFacade to give to the composite cache out of caches it constructs * from the varies manager to lateral services. Perhaps the lateralcache factory should be able to * do this. */ -public class LateralCacheNoWaitFacade<K, V> +public class LateralTCPCacheNoWaitFacade<K, V> extends AbstractAuxiliaryCache<K, V> { /** The logger */ - private static final Log log = Log.getLog( LateralCacheNoWaitFacade.class ); + private static final Log log = Log.getLog( LateralTCPCacheNoWaitFacade.class ); /** * The queuing facade to the client. */ - private final ConcurrentHashMap<String, LateralCacheNoWait<K, V>> noWaitMap; + private final ConcurrentHashMap<String, LateralTCPCacheNoWait<K, V>> noWaitMap; /** The region name */ private final String cacheName; @@ -67,7 +67,7 @@ public class LateralCacheNoWaitFacade<K, V> private ILateralCacheListener<K, V> listener; /** User configurable attributes. */ - private final ILateralCacheAttributes lateralCacheAttributes; + private final ILateralTCPCacheAttributes lateralCacheAttributes; /** Disposed state of this facade */ private final AtomicBoolean disposed = new AtomicBoolean(); @@ -80,8 +80,8 @@ public class LateralCacheNoWaitFacade<K, V> * @param cattr the configuration * @since 3.1 */ - public LateralCacheNoWaitFacade(final ILateralCacheListener<K, V> listener, - final List<LateralCacheNoWait<K, V>> noWaits, final ILateralCacheAttributes cattr ) + public LateralTCPCacheNoWaitFacade(final ILateralCacheListener<K, V> listener, + final List<LateralTCPCacheNoWait<K, V>> noWaits, final ILateralTCPCacheAttributes cattr ) { log.debug( "CONSTRUCTING NO WAIT FACADE" ); this.listener = listener; @@ -97,14 +97,14 @@ public class LateralCacheNoWaitFacade<K, V> * @param noWait * @return true if it wasn't already contained */ - public synchronized boolean addNoWait( final LateralCacheNoWait<K, V> noWait ) + public synchronized boolean addNoWait( final LateralTCPCacheNoWait<K, V> noWait ) { if ( noWait == null ) { return false; } - final LateralCacheNoWait<K,V> added = + final LateralTCPCacheNoWait<K,V> added = noWaitMap.putIfAbsent(noWait.getIdentityKey(), noWait); if (added != null) @@ -122,7 +122,7 @@ public class LateralCacheNoWaitFacade<K, V> * @param noWait * @return true if the noWait is in the list. */ - public boolean containsNoWait( final LateralCacheNoWait<K, V> noWait ) + public boolean containsNoWait( final LateralTCPCacheNoWait<K, V> noWait ) { return containsNoWait(noWait.getIdentityKey()); } @@ -152,7 +152,7 @@ public class LateralCacheNoWaitFacade<K, V> listener = null; } - noWaitMap.values().forEach(LateralCacheNoWait::dispose); + noWaitMap.values().forEach(LateralTCPCacheNoWait::dispose); noWaitMap.clear(); } } @@ -177,13 +177,13 @@ public class LateralCacheNoWaitFacade<K, V> * @return the AuxiliaryCacheAttributes. */ @Override - public ILateralCacheAttributes getAuxiliaryCacheAttributes() + public ILateralTCPCacheAttributes getAuxiliaryCacheAttributes() { return this.lateralCacheAttributes; } /** - * Gets the cacheName attribute of the LateralCacheNoWaitFacade object. + * Gets the cacheName attribute of the LateralTCPCacheNoWaitFacade object. * * @return The cacheName value */ @@ -194,7 +194,7 @@ public class LateralCacheNoWaitFacade<K, V> } /** - * Gets the cacheType attribute of the LateralCacheNoWaitFacade object. + * Gets the cacheType attribute of the LateralTCPCacheNoWaitFacade object. * * @return The cacheType value */ @@ -224,7 +224,7 @@ public class LateralCacheNoWaitFacade<K, V> public Set<K> getKeySet() throws IOException { final HashSet<K> allKeys = new HashSet<>(); - for (final LateralCacheNoWait<K, V> nw : noWaitMap.values()) + for (final LateralTCPCacheNoWait<K, V> nw : noWaitMap.values()) { final Set<K> keys = nw.getKeySet(); if (keys != null) @@ -335,7 +335,7 @@ public class LateralCacheNoWaitFacade<K, V> } /** - * Gets the status attribute of the LateralCacheNoWaitFacade object + * Gets the status attribute of the LateralTCPCacheNoWaitFacade object * @return The status value */ @Override @@ -352,7 +352,7 @@ public class LateralCacheNoWaitFacade<K, V> } final List<CacheStatus> statii = noWaitMap.values().stream() - .map(LateralCacheNoWait::getStatus) + .map(LateralTCPCacheNoWait::getStatus) .collect(Collectors.toList()); // It's alive if ANY of its nowaits is alive @@ -390,7 +390,7 @@ public class LateralCacheNoWaitFacade<K, V> @Override public void removeAll() { - noWaitMap.values().forEach(LateralCacheNoWait::removeAll); + noWaitMap.values().forEach(LateralTCPCacheNoWait::removeAll); } /** @@ -399,7 +399,7 @@ public class LateralCacheNoWaitFacade<K, V> * @param noWait * @return true if it was already in the array */ - public synchronized boolean removeNoWait( final LateralCacheNoWait<K, V> noWait ) + public synchronized boolean removeNoWait( final LateralTCPCacheNoWait<K, V> noWait ) { if (noWait == null) { @@ -424,7 +424,7 @@ public class LateralCacheNoWaitFacade<K, V> return false; } - final LateralCacheNoWait<K,V> contained = noWaitMap.remove(tcpServer); + final LateralTCPCacheNoWait<K,V> contained = noWaitMap.remove(tcpServer); if (contained != null) { @@ -435,12 +435,12 @@ public class LateralCacheNoWaitFacade<K, V> } /** - * @return "LateralCacheNoWaitFacade: " + cacheName; + * @return "LateralTCPCacheNoWaitFacade: " + cacheName; */ @Override public String toString() { - return "LateralCacheNoWaitFacade: " + cacheName; + return "LateralTCPCacheNoWaitFacade: " + cacheName; } /** @@ -455,7 +455,7 @@ public class LateralCacheNoWaitFacade<K, V> log.debug("updating through lateral cache facade, noWaits.length = {0}", noWaitMap::size); - for (final LateralCacheNoWait<K, V> nw : noWaitMap.values()) + for (final LateralTCPCacheNoWait<K, V> nw : noWaitMap.values()) { nw.update( ce ); } 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 e0537a7d..97de363e 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 @@ -24,8 +24,6 @@ import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentMap; import java.util.concurrent.CopyOnWriteArrayList; -import org.apache.commons.jcs4.auxiliary.lateral.LateralCacheNoWait; -import org.apache.commons.jcs4.auxiliary.lateral.LateralCacheNoWaitFacade; 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; @@ -48,7 +46,7 @@ public class LateralTCPDiscoveryListener * Map of no wait facades. these are used to determine which regions are locally configured to * use laterals. */ - private final ConcurrentMap<String, LateralCacheNoWaitFacade<?, ?>> facades = + private final ConcurrentMap<String, LateralTCPCacheNoWaitFacade<?, ?>> facades = new ConcurrentHashMap<>(); /** @@ -121,7 +119,7 @@ public class LateralTCPDiscoveryListener // for each region get the cache for (final String cacheName : regions) { - final LateralCacheNoWaitFacade<?, ?> facade = facades.get(cacheName); + final LateralTCPCacheNoWaitFacade<?, ?> facade = facades.get(cacheName); log.debug( "Got cache facade {0}", facade ); // add this to the nowaits for this cachename @@ -133,14 +131,14 @@ public class LateralTCPDiscoveryListener continue; } - final TCPLateralCacheAttributes lca = - (TCPLateralCacheAttributes) facade.getAuxiliaryCacheAttributes().clone(); + final LateralTCPCacheAttributes lca = + (LateralTCPCacheAttributes) facade.getAuxiliaryCacheAttributes().clone(); lca.setTcpServer(serverAndPort); final LateralTCPCacheFactory factory = (LateralTCPCacheFactory) cacheManager.registryFacGet(factoryName); - final LateralCacheNoWait<?, ?> noWait = + final LateralTCPCacheNoWait<?, ?> noWait = factory.createCacheNoWait(lca, cacheEventLogger, elementSerializer); factory.monitorCache(noWait); @@ -169,12 +167,12 @@ public class LateralTCPDiscoveryListener * @return true if we found the no wait and added it. False if the no wait was not present or if * we already had it. */ - protected <K, V> boolean addNoWait( final LateralCacheNoWait<K, V> noWait ) + protected <K, V> boolean addNoWait( final LateralTCPCacheNoWait<K, V> noWait ) { @SuppressWarnings("unchecked") // Need to cast because of common map for all facades final - LateralCacheNoWaitFacade<K, V> facade = - (LateralCacheNoWaitFacade<K, V>)facades.get( noWait.getCacheName() ); + LateralTCPCacheNoWaitFacade<K, V> facade = + (LateralTCPCacheNoWaitFacade<K, V>)facades.get( noWait.getCacheName() ); log.debug( "addNoWait > Got facade for {0} = {1}", noWait.getCacheName(), facade ); return addNoWait(noWait, facade); @@ -190,8 +188,8 @@ public class LateralTCPDiscoveryListener * we already had it. * @since 3.1 */ - protected <K, V> boolean addNoWait(final LateralCacheNoWait<K, V> noWait, - final LateralCacheNoWaitFacade<K, V> facade) + protected <K, V> boolean addNoWait(final LateralTCPCacheNoWait<K, V> noWait, + final LateralTCPCacheNoWaitFacade<K, V> facade) { if ( facade != null ) { @@ -218,7 +216,7 @@ public class LateralTCPDiscoveryListener * @param facade facade (for region) => multiple lateral clients. * @return true if the facade was not already registered. */ - public boolean addNoWaitFacade( final String cacheName, final LateralCacheNoWaitFacade<?, ?> facade ) + public boolean addNoWaitFacade( final String cacheName, final LateralTCPCacheNoWaitFacade<?, ?> facade ) { final boolean isNew = !containsNoWaitFacade( cacheName ); @@ -236,12 +234,12 @@ public class LateralTCPDiscoveryListener * @param noWait is this no wait in the facade * @return do we contain the no wait. true if so */ - public <K, V> boolean containsNoWait( final String cacheName, final LateralCacheNoWait<K, V> noWait ) + public <K, V> boolean containsNoWait( final String cacheName, final LateralTCPCacheNoWait<K, V> noWait ) { @SuppressWarnings("unchecked") // Need to cast because of common map for all facades final - LateralCacheNoWaitFacade<K, V> facade = - (LateralCacheNoWaitFacade<K, V>)facades.get( noWait.getCacheName() ); + LateralTCPCacheNoWaitFacade<K, V> facade = + (LateralTCPCacheNoWaitFacade<K, V>)facades.get( noWait.getCacheName() ); if ( facade == null ) { @@ -284,7 +282,7 @@ public class LateralTCPDiscoveryListener // for each region get the cache for (final String cacheName : regions) { - final LateralCacheNoWaitFacade<?, ?> facade = facades.get(cacheName); + final LateralTCPCacheNoWaitFacade<?, ?> facade = facades.get(cacheName); log.debug( "Got cache facade {0}", facade ); // remove this from the nowaits for this cachename @@ -307,12 +305,12 @@ public class LateralTCPDiscoveryListener * @param noWait * @return true if we found the no wait and removed it. False if the no wait was not present. */ - protected <K, V> boolean removeNoWait( final LateralCacheNoWait<K, V> noWait ) + protected <K, V> boolean removeNoWait( final LateralTCPCacheNoWait<K, V> noWait ) { @SuppressWarnings("unchecked") // Need to cast because of common map for all facades final - LateralCacheNoWaitFacade<K, V> facade = - (LateralCacheNoWaitFacade<K, V>)facades.get( noWait.getCacheName() ); + LateralTCPCacheNoWaitFacade<K, V> facade = + (LateralTCPCacheNoWaitFacade<K, V>)facades.get( noWait.getCacheName() ); log.debug( "removeNoWait > Got facade for {0} = {1}", noWait.getCacheName(), facade); return removeNoWait(facade, noWait.getCacheName(), noWait.getIdentityKey()); @@ -327,7 +325,7 @@ public class LateralTCPDiscoveryListener * @return true if we found the no wait and removed it. False if the no wait was not present. * @since 3.1 */ - protected <K, V> boolean removeNoWait(final LateralCacheNoWaitFacade<K, V> facade, + protected <K, V> boolean removeNoWait(final LateralTCPCacheNoWaitFacade<K, V> facade, final String cacheName, final String tcpServer) { if ( facade != null ) diff --git a/commons-jcs4-core/src/main/java/org/apache/commons/jcs4/auxiliary/lateral/socket/tcp/LateralTCPListener.java b/commons-jcs4-core/src/main/java/org/apache/commons/jcs4/auxiliary/lateral/socket/tcp/LateralTCPListener.java index ca32cf39..29804712 100644 --- a/commons-jcs4-core/src/main/java/org/apache/commons/jcs4/auxiliary/lateral/socket/tcp/LateralTCPListener.java +++ b/commons-jcs4-core/src/main/java/org/apache/commons/jcs4/auxiliary/lateral/socket/tcp/LateralTCPListener.java @@ -34,7 +34,7 @@ import java.util.concurrent.atomic.AtomicBoolean; import org.apache.commons.jcs4.auxiliary.lateral.LateralElementDescriptor; import org.apache.commons.jcs4.auxiliary.lateral.behavior.ILateralCacheListener; -import org.apache.commons.jcs4.auxiliary.lateral.socket.tcp.behavior.ITCPLateralCacheAttributes; +import org.apache.commons.jcs4.auxiliary.lateral.socket.tcp.behavior.ILateralTCPCacheAttributes; import org.apache.commons.jcs4.engine.CacheInfo; import org.apache.commons.jcs4.engine.behavior.ICacheElement; import org.apache.commons.jcs4.engine.behavior.ICompositeCacheManager; @@ -64,14 +64,14 @@ public class LateralTCPListener<K, V> /** * Gets the instance attribute of the LateralCacheTCPListener class. * - * @param ilca ITCPLateralCacheAttributes + * @param ilca ILateralTCPCacheAttributes * @param cacheMgr * @param serializer the serializer to use when receiving * @return The instance value */ @SuppressWarnings("unchecked") // Need to cast because of common map for all instances public static <K, V> LateralTCPListener<K, V> - getInstance( final ITCPLateralCacheAttributes ilca, final ICompositeCacheManager cacheMgr, final IElementSerializer serializer ) + getInstance( final ILateralTCPCacheAttributes ilca, final ICompositeCacheManager cacheMgr, final IElementSerializer serializer ) { return (LateralTCPListener<K, V>) instances.computeIfAbsent( String.valueOf( ilca.getTcpListenerPort() ), @@ -91,7 +91,7 @@ public class LateralTCPListener<K, V> private transient ICompositeCacheManager cacheManager; /** Configuration attributes */ - private ITCPLateralCacheAttributes tcpLateralCacheAttributes; + private ILateralTCPCacheAttributes tcpLateralCacheAttributes; /** The listener thread */ private Thread listenerThread; @@ -128,7 +128,7 @@ public class LateralTCPListener<K, V> * @param ilca * @param serializer the serializer to use when receiving */ - protected LateralTCPListener( final ITCPLateralCacheAttributes ilca, final IElementSerializer serializer ) + protected LateralTCPListener( final ILateralTCPCacheAttributes ilca, final IElementSerializer serializer ) { this.setTcpLateralCacheAttributes( ilca ); this.serializer = serializer; @@ -209,7 +209,7 @@ public class LateralTCPListener<K, V> /** * @return the tcpLateralCacheAttributes. */ - public ITCPLateralCacheAttributes getTcpLateralCacheAttributes() + public ILateralTCPCacheAttributes getTcpLateralCacheAttributes() { return tcpLateralCacheAttributes; } @@ -637,7 +637,7 @@ public class LateralTCPListener<K, V> /** * @param tcpLateralCacheAttributes The tcpLateralCacheAttributes to set. */ - public void setTcpLateralCacheAttributes( final ITCPLateralCacheAttributes tcpLateralCacheAttributes ) + public void setTcpLateralCacheAttributes( final ILateralTCPCacheAttributes tcpLateralCacheAttributes ) { this.tcpLateralCacheAttributes = tcpLateralCacheAttributes; } diff --git a/commons-jcs4-core/src/main/java/org/apache/commons/jcs4/auxiliary/lateral/socket/tcp/LateralTCPSender.java b/commons-jcs4-core/src/main/java/org/apache/commons/jcs4/auxiliary/lateral/socket/tcp/LateralTCPSender.java index 211b95ee..0369a3c9 100644 --- a/commons-jcs4-core/src/main/java/org/apache/commons/jcs4/auxiliary/lateral/socket/tcp/LateralTCPSender.java +++ b/commons-jcs4-core/src/main/java/org/apache/commons/jcs4/auxiliary/lateral/socket/tcp/LateralTCPSender.java @@ -30,7 +30,7 @@ import java.util.concurrent.locks.Lock; import java.util.concurrent.locks.ReentrantLock; import org.apache.commons.jcs4.auxiliary.lateral.LateralElementDescriptor; -import org.apache.commons.jcs4.auxiliary.lateral.socket.tcp.behavior.ITCPLateralCacheAttributes; +import org.apache.commons.jcs4.auxiliary.lateral.socket.tcp.behavior.ILateralTCPCacheAttributes; import org.apache.commons.jcs4.engine.behavior.IElementSerializer; import org.apache.commons.jcs4.log.Log; @@ -67,7 +67,7 @@ public class LateralTCPSender * @throws IOException * @since 3.1 */ - public LateralTCPSender( final ITCPLateralCacheAttributes lca, final IElementSerializer serializer ) + public LateralTCPSender( final ILateralTCPCacheAttributes lca, final IElementSerializer serializer ) throws IOException { this.socketOpenTimeOut = lca.getOpenTimeOut(); diff --git a/commons-jcs4-core/src/main/java/org/apache/commons/jcs4/auxiliary/lateral/socket/tcp/LateralTCPService.java b/commons-jcs4-core/src/main/java/org/apache/commons/jcs4/auxiliary/lateral/socket/tcp/LateralTCPService.java index 8bbcd898..6af8fb8c 100644 --- a/commons-jcs4-core/src/main/java/org/apache/commons/jcs4/auxiliary/lateral/socket/tcp/LateralTCPService.java +++ b/commons-jcs4-core/src/main/java/org/apache/commons/jcs4/auxiliary/lateral/socket/tcp/LateralTCPService.java @@ -27,7 +27,7 @@ import java.util.Set; import org.apache.commons.jcs4.auxiliary.lateral.LateralCommand; import org.apache.commons.jcs4.auxiliary.lateral.LateralElementDescriptor; -import org.apache.commons.jcs4.auxiliary.lateral.socket.tcp.behavior.ITCPLateralCacheAttributes; +import org.apache.commons.jcs4.auxiliary.lateral.socket.tcp.behavior.ILateralTCPCacheAttributes; import org.apache.commons.jcs4.engine.CacheElement; import org.apache.commons.jcs4.engine.CacheInfo; import org.apache.commons.jcs4.engine.behavior.ICacheElement; @@ -59,12 +59,12 @@ public class LateralTCPService<K, V> /** * Constructor for the LateralTCPService object * - * @param lca ITCPLateralCacheAttributes the configuration object + * @param lca ILateralTCPCacheAttributes the configuration object * @param serializer the serializer to use when sending * @throws IOException * @since 3.1 */ - public LateralTCPService( final ITCPLateralCacheAttributes lca, final IElementSerializer serializer ) + public LateralTCPService( final ILateralTCPCacheAttributes lca, final IElementSerializer serializer ) throws IOException { this.allowGet = lca.isAllowGet(); diff --git a/commons-jcs4-core/src/main/java/org/apache/commons/jcs4/auxiliary/lateral/socket/tcp/behavior/ITCPLateralCacheAttributes.java b/commons-jcs4-core/src/main/java/org/apache/commons/jcs4/auxiliary/lateral/socket/tcp/behavior/ILateralTCPCacheAttributes.java similarity index 71% rename from commons-jcs4-core/src/main/java/org/apache/commons/jcs4/auxiliary/lateral/socket/tcp/behavior/ITCPLateralCacheAttributes.java rename to commons-jcs4-core/src/main/java/org/apache/commons/jcs4/auxiliary/lateral/socket/tcp/behavior/ILateralTCPCacheAttributes.java index 4765f7dc..be3b7f23 100644 --- a/commons-jcs4-core/src/main/java/org/apache/commons/jcs4/auxiliary/lateral/socket/tcp/behavior/ITCPLateralCacheAttributes.java +++ b/commons-jcs4-core/src/main/java/org/apache/commons/jcs4/auxiliary/lateral/socket/tcp/behavior/ILateralTCPCacheAttributes.java @@ -19,16 +19,22 @@ package org.apache.commons.jcs4.auxiliary.lateral.socket.tcp.behavior; * under the License. */ -import org.apache.commons.jcs4.auxiliary.lateral.behavior.ILateralCacheAttributes; +import org.apache.commons.jcs4.auxiliary.AuxiliaryCacheAttributes; /** * This interface defines functions that are particular to the TCP Lateral Cache * plugin. It extends the generic LateralCacheAttributes interface which in turn * extends the AuxiliaryCache interface. */ -public interface ITCPLateralCacheAttributes - extends ILateralCacheAttributes +public interface ILateralTCPCacheAttributes + extends AuxiliaryCacheAttributes { + /** + * The number of elements the zombie queue will hold. This queue is used to store events if we + * loose our connection with the server. + */ + int DEFAULT_ZOMBIE_QUEUE_MAX_SIZE = 1000; + /** * @return the openTimeOut */ @@ -74,6 +80,13 @@ public interface ITCPLateralCacheAttributes */ String getUdpDiscoveryAddr(); + /** + * The UDP discovery network interface if UDPDiscovery is enabled. + * + * @return the udpDiscoveryInterface. + */ + String getUdpDiscoveryInterface(); + /** * The port to use if UDPDiscovery is enabled. * @@ -131,4 +144,31 @@ public interface ITCPLateralCacheAttributes * @return the udpDiscoveryEnabled. */ boolean isUdpDiscoveryEnabled(); + + /** + * @return The outgoingOnlyMode value. Stops gets from going remote. + */ + boolean getPutOnlyMode(); + + /** + * The number of elements the zombie queue will hold. This queue is used to store events if we + * loose our connection with the server. + * + * @return the zombieQueueMaxSize. + */ + int getZombieQueueMaxSize(); + + /** + * Should a listener be created. By default this is true. + * <p> + * If this is false the lateral will connect to others but it will not create a listener to + * receive. + * <p> + * It is possible if two laterals are misconfigured that lateral A may have a region R1 that is + * not configured for the lateral but another is. And if cache B has region R1 configured for + * lateral distribution, A will get messages for R1 but not send them. + * + * @return true if we should have a listener connection + */ + boolean isReceive(); } diff --git a/commons-jcs4-core/src/main/java/org/apache/commons/jcs4/utils/discovery/UDPDiscoveryAttributes.java b/commons-jcs4-core/src/main/java/org/apache/commons/jcs4/utils/discovery/UDPDiscoveryAttributes.java index 7c55965f..38085704 100644 --- a/commons-jcs4-core/src/main/java/org/apache/commons/jcs4/utils/discovery/UDPDiscoveryAttributes.java +++ b/commons-jcs4-core/src/main/java/org/apache/commons/jcs4/utils/discovery/UDPDiscoveryAttributes.java @@ -22,11 +22,31 @@ package org.apache.commons.jcs4.utils.discovery; /** * Configuration properties for UDP discover service. * <p> - * The service will allow out applications to find each other. + * The service will allow applications to find each other. * </p> */ -public final class UDPDiscoveryAttributes - implements Cloneable +public record UDPDiscoveryAttributes( + /** Service address */ + String serviceAddress, + + /** Service port */ + int servicePort, + + /** Udp discovery address */ + String udpDiscoveryAddr, + + /** Udp discovery network interface */ + String udpDiscoveryInterface, + + /** Udp discovery port */ + int udpDiscoveryPort, + + /** Udp datagram TTL */ + int udpTTL, + + /** Amount of time before we remove services that we haven't heard from */ + int maxIdleTimeSec +) { /** Default udp discovery address */ private static final String DEFAULT_UDP_DISCOVERY_ADDRESS = "228.4.5.6"; @@ -37,149 +57,62 @@ public final class UDPDiscoveryAttributes /** Default amount of time before we remove services that we haven't heard from */ private static final int DEFAULT_MAX_IDLE_TIME_SEC = 180; - /** Service address */ - private String serviceAddress; - - /** Service port */ - private int servicePort; - - /** Udp discovery address */ - private String udpDiscoveryAddr = DEFAULT_UDP_DISCOVERY_ADDRESS; - - /** Udp discovery network interface */ - private String udpDiscoveryInterface; - - /** Udp discovery port */ - private int udpDiscoveryPort = DEFAULT_UDP_DISCOVERY_PORT; - - /** Udp datagram TTL */ - private int udpTTL; - - /** Amount of time before we remove services that we haven't heard from */ - private int maxIdleTimeSec = DEFAULT_MAX_IDLE_TIME_SEC; - - /** @return a clone of this object */ - @Override - public UDPDiscoveryAttributes clone() - { - final UDPDiscoveryAttributes attributes = new UDPDiscoveryAttributes(); - attributes.setMaxIdleTimeSec( getMaxIdleTimeSec() ); - attributes.setServicePort( getServicePort() ); - attributes.setUdpDiscoveryAddr( getUdpDiscoveryAddr() ); - attributes.setUdpDiscoveryPort( getUdpDiscoveryPort() ); - return attributes; - } - - /** - * @return the maxIdleTimeSec. - */ - public int getMaxIdleTimeSec() - { - return maxIdleTimeSec; - } - - /** - * @return the serviceAddress. - */ - public String getServiceAddress() - { - return serviceAddress; - } - - /** - * @return the servicePort. - */ - public int getServicePort() - { - return servicePort; - } - - /** - * @return the udpDiscoveryAddr. - */ - public String getUdpDiscoveryAddr() - { - return udpDiscoveryAddr; - } - - /** - * @return the udpDiscoveryInterface. - */ - public String getUdpDiscoveryInterface() - { - return udpDiscoveryInterface; - } - - /** - * @return the udpDiscoveryPort. - */ - public int getUdpDiscoveryPort() - { - return udpDiscoveryPort; - } - - /** - * @return the udpTTL. - */ - public int getUdpTTL() - { - return udpTTL; - } - - /** - * @param maxIdleTimeSec The maxIdleTimeSec to set. - */ - public void setMaxIdleTimeSec( final int maxIdleTimeSec ) - { - this.maxIdleTimeSec = maxIdleTimeSec; - } - - /** - * @param serviceAddress The serviceAddress to set. - */ - public void setServiceAddress( final String serviceAddress ) - { - this.serviceAddress = serviceAddress; - } - - /** - * @param servicePort The servicePort to set. - */ - public void setServicePort( final int servicePort ) - { - this.servicePort = servicePort; - } - - /** - * @param udpDiscoveryAddr The udpDiscoveryAddr to set. - */ - public void setUdpDiscoveryAddr( final String udpDiscoveryAddr ) - { - this.udpDiscoveryAddr = udpDiscoveryAddr; - } + private static final UDPDiscoveryAttributes DEFAULT = new UDPDiscoveryAttributes( + null, + -1, + DEFAULT_UDP_DISCOVERY_ADDRESS, + null, + DEFAULT_UDP_DISCOVERY_PORT, + 0, + DEFAULT_MAX_IDLE_TIME_SEC + ); /** - * @param udpDiscoveryInterface The udpDiscoveryInterface to set. + * @return an object containing the default settings */ - public void setUdpDiscoveryInterface( final String udpDiscoveryInterface ) + public static UDPDiscoveryAttributes defaults() { - this.udpDiscoveryInterface = udpDiscoveryInterface; + return DEFAULT; } /** - * @param udpDiscoveryPort The udpDiscoveryPort to set. + * Constructor with necessary fields only + * + * @param servicePort + * @param udpDiscoveryAddr + * @param udpDiscoveryPort + * @param udpTTL */ - public void setUdpDiscoveryPort( final int udpDiscoveryPort ) + public UDPDiscoveryAttributes(int servicePort, String udpDiscoveryAddr, int udpDiscoveryPort, + int udpTTL) { - this.udpDiscoveryPort = udpDiscoveryPort; + this(defaults().serviceAddress(), + servicePort, + udpDiscoveryAddr, + defaults().udpDiscoveryInterface(), + udpDiscoveryPort, + udpTTL, + defaults().maxIdleTimeSec() + ); } /** - * @param udpTTL The udpTTL to set. + * Get a new record with the given serviceAddress + * + * @param serviceAddress new serviceAddress + * @return new record with the given serviceAddress */ - public void setUdpTTL( final int udpTTL ) + public UDPDiscoveryAttributes withServiceAddress(String serviceAddress) { - this.udpTTL = udpTTL; + return new UDPDiscoveryAttributes( + serviceAddress, + servicePort(), + udpDiscoveryAddr(), + udpDiscoveryInterface(), + udpDiscoveryPort(), + udpTTL(), + maxIdleTimeSec() + ); } /** @@ -189,12 +122,12 @@ public final class UDPDiscoveryAttributes public String toString() { final StringBuilder buf = new StringBuilder(); - buf.append( "\n UDPDiscoveryAttributes" ); - buf.append( "\n ServiceAddress = [" + getServiceAddress() + "]" ); - buf.append( "\n ServicePort = [" + getServicePort() + "]" ); - buf.append( "\n UdpDiscoveryAddr = [" + getUdpDiscoveryAddr() + "]" ); - buf.append( "\n UdpDiscoveryPort = [" + getUdpDiscoveryPort() + "]" ); - buf.append( "\n MaxIdleTimeSec = [" + getMaxIdleTimeSec() + "]" ); + buf.append("\n UDPDiscoveryAttributes"); + buf.append("\n ServiceAddress = [").append(serviceAddress()).append("]"); + buf.append("\n ServicePort = [").append(servicePort()).append("]"); + buf.append("\n UdpDiscovery = [").append(udpDiscoveryAddr()).append("]"); + buf.append("\n UdpDiscoveryPort = [").append(udpDiscoveryPort()).append("]"); + buf.append("\n MaxIdleTimeSec = [").append(maxIdleTimeSec()).append("]"); return buf.toString(); } } diff --git a/commons-jcs4-core/src/main/java/org/apache/commons/jcs4/utils/discovery/UDPDiscoveryManager.java b/commons-jcs4-core/src/main/java/org/apache/commons/jcs4/utils/discovery/UDPDiscoveryManager.java index c4d1c27b..b6c44dc3 100644 --- a/commons-jcs4-core/src/main/java/org/apache/commons/jcs4/utils/discovery/UDPDiscoveryManager.java +++ b/commons-jcs4-core/src/main/java/org/apache/commons/jcs4/utils/discovery/UDPDiscoveryManager.java @@ -64,32 +64,22 @@ public class UDPDiscoveryManager * We need to key this using the listener port too. * TODO think of making one discovery service work for multiple types of clients. * - * @param discoveryAddress - * @param discoveryPort - * @param serviceAddress - * @param servicePort - * @param updTTL - * @param cacheMgr - * @param serializer + * @param attributes configuration object + * @param cacheMgr the Cache Hub + * @param serializer the Serializer for UDP packets * @return UDPDiscoveryService - * @since 3.1 + * @since 4.0 */ - public UDPDiscoveryService getService( final String discoveryAddress, final int discoveryPort, - final String serviceAddress, final int servicePort, final int updTTL, + public UDPDiscoveryService getService(UDPDiscoveryAttributes attributes, final ICompositeCacheManager cacheMgr, final IElementSerializer serializer ) { - final String key = String.join(":", discoveryAddress, String.valueOf(discoveryPort), String.valueOf(servicePort)); + final String key = String.join(":", attributes.udpDiscoveryAddr(), + String.valueOf(attributes.udpDiscoveryPort()), + String.valueOf(attributes.servicePort())); final UDPDiscoveryService service = services.computeIfAbsent(key, k -> { log.info( "Creating service for address:port:servicePort [{0}]", key ); - final UDPDiscoveryAttributes attributes = new UDPDiscoveryAttributes(); - attributes.setUdpDiscoveryAddr(discoveryAddress); - attributes.setUdpDiscoveryPort(discoveryPort); - attributes.setServiceAddress(serviceAddress); - attributes.setServicePort(servicePort); - attributes.setUdpTTL(updTTL); - final UDPDiscoveryService newService = new UDPDiscoveryService(attributes, serializer); // register for shutdown notification diff --git a/commons-jcs4-core/src/main/java/org/apache/commons/jcs4/utils/discovery/UDPDiscoverySender.java b/commons-jcs4-core/src/main/java/org/apache/commons/jcs4/utils/discovery/UDPDiscoverySender.java index 934c2723..0b2324b8 100644 --- a/commons-jcs4-core/src/main/java/org/apache/commons/jcs4/utils/discovery/UDPDiscoverySender.java +++ b/commons-jcs4-core/src/main/java/org/apache/commons/jcs4/utils/discovery/UDPDiscoverySender.java @@ -127,10 +127,10 @@ public class UDPDiscoverySender implements AutoCloseable public UDPDiscoverySender(final UDPDiscoveryAttributes udpDiscoveryAttributes, final IElementSerializer serializer) throws IOException { - this(udpDiscoveryAttributes.getUdpDiscoveryInterface(), - udpDiscoveryAttributes.getUdpDiscoveryAddr(), - udpDiscoveryAttributes.getUdpDiscoveryPort(), - udpDiscoveryAttributes.getUdpTTL(), + this(udpDiscoveryAttributes.udpDiscoveryInterface(), + udpDiscoveryAttributes.udpDiscoveryAddr(), + udpDiscoveryAttributes.udpDiscoveryPort(), + udpDiscoveryAttributes.udpTTL(), serializer); } diff --git a/commons-jcs4-core/src/main/java/org/apache/commons/jcs4/utils/discovery/UDPDiscoveryService.java b/commons-jcs4-core/src/main/java/org/apache/commons/jcs4/utils/discovery/UDPDiscoveryService.java index d3f2e6ef..513c0f53 100644 --- a/commons-jcs4-core/src/main/java/org/apache/commons/jcs4/utils/discovery/UDPDiscoveryService.java +++ b/commons-jcs4-core/src/main/java/org/apache/commons/jcs4/utils/discovery/UDPDiscoveryService.java @@ -99,24 +99,24 @@ public class UDPDiscoveryService */ public UDPDiscoveryService(final UDPDiscoveryAttributes attributes, final IElementSerializer serializer) { - this.udpDiscoveryAttributes = attributes.clone(); + this.udpDiscoveryAttributes = attributes; this.serializer = serializer; try { final InetAddress multicastAddress = InetAddress.getByName( - getUdpDiscoveryAttributes().getUdpDiscoveryAddr()); + getUdpDiscoveryAttributes().udpDiscoveryAddr()); // Set service address if still empty - if (getUdpDiscoveryAttributes().getServiceAddress() == null || - getUdpDiscoveryAttributes().getServiceAddress().isEmpty()) + if (getUdpDiscoveryAttributes().serviceAddress() == null || + getUdpDiscoveryAttributes().serviceAddress().isEmpty()) { // Use same interface as for multicast NetworkInterface serviceInterface = null; - if (getUdpDiscoveryAttributes().getUdpDiscoveryInterface() != null) + if (getUdpDiscoveryAttributes().udpDiscoveryInterface() != null) { serviceInterface = NetworkInterface.getByName( - getUdpDiscoveryAttributes().getUdpDiscoveryInterface()); + getUdpDiscoveryAttributes().udpDiscoveryInterface()); } else { @@ -158,7 +158,9 @@ public class UDPDiscoveryService serviceAddress = HostNameUtil.getLocalHostLANAddress(); } - getUdpDiscoveryAttributes().setServiceAddress(serviceAddress.getHostAddress()); + setUdpDiscoveryAttributes( + getUdpDiscoveryAttributes().withServiceAddress( + serviceAddress.getHostAddress())); } catch ( final UnknownHostException e ) { @@ -168,17 +170,17 @@ public class UDPDiscoveryService // todo need some kind of recovery here. receiver = new UDPDiscoveryReceiver( this::processMessage, - getUdpDiscoveryAttributes().getUdpDiscoveryInterface(), + getUdpDiscoveryAttributes().udpDiscoveryInterface(), multicastAddress, - getUdpDiscoveryAttributes().getUdpDiscoveryPort() ); + getUdpDiscoveryAttributes().udpDiscoveryPort() ); receiver.setSerializer(serializer); } catch ( final IOException e ) { log.error( "Problem creating UDPDiscoveryReceiver, address [{0}] " + "port [{1}] we won't be able to find any other caches", - getUdpDiscoveryAttributes().getUdpDiscoveryAddr(), - getUdpDiscoveryAttributes().getUdpDiscoveryPort(), e ); + getUdpDiscoveryAttributes().udpDiscoveryAddr(), + getUdpDiscoveryAttributes().udpDiscoveryPort(), e ); } // initiate sender broadcast @@ -257,11 +259,11 @@ public class UDPDiscoveryService // the listeners need to be notified. getDiscoveredServices().stream() .filter(service -> { - if (now - service.getLastHearFromTime() > getUdpDiscoveryAttributes().getMaxIdleTimeSec() * 1000) + if (now - service.getLastHearFromTime() > getUdpDiscoveryAttributes().maxIdleTimeSec() * 1000) { log.info( "Removing service, since we haven't heard from it in " + "{0} seconds. service = {1}", - getUdpDiscoveryAttributes().getMaxIdleTimeSec(), service ); + getUdpDiscoveryAttributes().maxIdleTimeSec(), service ); return true; } @@ -334,10 +336,10 @@ public class UDPDiscoveryService { log.debug( "Creating sender for discoveryAddress = [{0}] and " + "discoveryPort = [{1}] myHostName = [{2}] and port = [{3}]", - () -> getUdpDiscoveryAttributes().getUdpDiscoveryAddr(), - () -> getUdpDiscoveryAttributes().getUdpDiscoveryPort(), - () -> getUdpDiscoveryAttributes().getServiceAddress(), - () -> getUdpDiscoveryAttributes().getServicePort() ); + () -> getUdpDiscoveryAttributes().udpDiscoveryAddr(), + () -> getUdpDiscoveryAttributes().udpDiscoveryPort(), + () -> getUdpDiscoveryAttributes().serviceAddress(), + () -> getUdpDiscoveryAttributes().servicePort() ); try (UDPDiscoverySender sender = new UDPDiscoverySender( getUdpDiscoveryAttributes(), getSerializer())) @@ -419,8 +421,8 @@ public class UDPDiscoveryService getUdpDiscoveryAttributes(), getSerializer())) { sender.passiveBroadcast( - getUdpDiscoveryAttributes().getServiceAddress(), - getUdpDiscoveryAttributes().getServicePort(), + getUdpDiscoveryAttributes().serviceAddress(), + getUdpDiscoveryAttributes().servicePort(), getCacheNames() ); log.debug( "Called sender to issue a passive broadcast" ); @@ -429,8 +431,8 @@ public class UDPDiscoveryService { log.error( "Problem calling the UDP Discovery Sender, address [{0}] " + "port [{1}]", - getUdpDiscoveryAttributes().getUdpDiscoveryAddr(), - getUdpDiscoveryAttributes().getUdpDiscoveryPort(), e ); + getUdpDiscoveryAttributes().udpDiscoveryAddr(), + getUdpDiscoveryAttributes().udpDiscoveryPort(), e ); } } @@ -449,7 +451,7 @@ public class UDPDiscoveryService // delay and the idle time. this.cleanupTaskFuture = scheduledExecutor.scheduleAtFixedRate( this::cleanup, 0, - getUdpDiscoveryAttributes().getMaxIdleTimeSec(), TimeUnit.SECONDS); + getUdpDiscoveryAttributes().maxIdleTimeSec(), TimeUnit.SECONDS); } /** @@ -508,8 +510,8 @@ public class UDPDiscoveryService getUdpDiscoveryAttributes(), getSerializer())) { sender.removeBroadcast( - getUdpDiscoveryAttributes().getServiceAddress(), - getUdpDiscoveryAttributes().getServicePort(), + getUdpDiscoveryAttributes().serviceAddress(), + getUdpDiscoveryAttributes().servicePort(), getCacheNames() ); log.debug( "Called sender to issue a remove broadcast in shutdown." ); diff --git a/commons-jcs4-core/src/test/conf/cacheTCP1.ccf b/commons-jcs4-core/src/test/conf/cacheTCP1.ccf index 1c83d5c7..d3d9ce82 100644 --- a/commons-jcs4-core/src/test/conf/cacheTCP1.ccf +++ b/commons-jcs4-core/src/test/conf/cacheTCP1.ccf @@ -56,7 +56,7 @@ jcs.region.testCache1.elementattributes.IsRemote=true # TCP jcs.auxiliary.LTCP=org.apache.commons.jcs4.auxiliary.lateral.socket.tcp.LateralTCPCacheFactory -jcs.auxiliary.LTCP.attributes=org.apache.commons.jcs4.auxiliary.lateral.socket.tcp.TCPLateralCacheAttributes +jcs.auxiliary.LTCP.attributes=org.apache.commons.jcs4.auxiliary.lateral.socket.tcp.LateralTCPCacheAttributes jcs.auxiliary.LTCP.attributes.TcpListenerPort=1118 jcs.auxiliary.LTCP.attributes.UdpDiscoveryAddr=228.5.6.8 jcs.auxiliary.LTCP.attributes.UdpDiscoveryPort=9780 diff --git a/commons-jcs4-core/src/test/conf/cacheTCP2.ccf b/commons-jcs4-core/src/test/conf/cacheTCP2.ccf index 9ac5257a..e3e86019 100644 --- a/commons-jcs4-core/src/test/conf/cacheTCP2.ccf +++ b/commons-jcs4-core/src/test/conf/cacheTCP2.ccf @@ -69,7 +69,7 @@ jcs.region.testCache2.elementattributes.IsRemote=true # TCP jcs.auxiliary.LTCP=org.apache.commons.jcs4.auxiliary.lateral.socket.tcp.LateralTCPCacheFactory -jcs.auxiliary.LTCP.attributes=org.apache.commons.jcs4.auxiliary.lateral.socket.tcp.TCPLateralCacheAttributes +jcs.auxiliary.LTCP.attributes=org.apache.commons.jcs4.auxiliary.lateral.socket.tcp.LateralTCPCacheAttributes jcs.auxiliary.LTCP.attributes.TcpListenerPort=1119 jcs.auxiliary.LTCP.attributes.UdpDiscoveryAddr=228.5.6.8 jcs.auxiliary.LTCP.attributes.UdpDiscoveryPort=9780 diff --git a/commons-jcs4-core/src/test/conf/cacheTCP3.ccf b/commons-jcs4-core/src/test/conf/cacheTCP3.ccf index 54ffe084..11d8cd0b 100644 --- a/commons-jcs4-core/src/test/conf/cacheTCP3.ccf +++ b/commons-jcs4-core/src/test/conf/cacheTCP3.ccf @@ -69,7 +69,7 @@ jcs.region.testCache2.elementattributes.IsRemote=true # almost complete jcs.auxiliary.LTCP=org.apache.commons.jcs4.auxiliary.lateral.socket.tcp.LateralTCPCacheFactory -jcs.auxiliary.LTCP.attributes=org.apache.commons.jcs4.auxiliary.lateral.socket.tcp.TCPLateralCacheAttributes +jcs.auxiliary.LTCP.attributes=org.apache.commons.jcs4.auxiliary.lateral.socket.tcp.LateralTCPCacheAttributes jcs.auxiliary.LTCP.attributes.TransmissionTypeName=TCP # jcs.auxiliary.LTCP.attributes.TcpServers= jcs.auxiliary.LTCP.attributes.TcpListenerPort=1120 diff --git a/commons-jcs4-core/src/test/conf/cacheTCP4.ccf b/commons-jcs4-core/src/test/conf/cacheTCP4.ccf index 2f25eea8..04120224 100644 --- a/commons-jcs4-core/src/test/conf/cacheTCP4.ccf +++ b/commons-jcs4-core/src/test/conf/cacheTCP4.ccf @@ -56,7 +56,7 @@ jcs.region.testCache1.elementattributes.IsRemote=true # almost complete jcs.auxiliary.LTCP=org.apache.commons.jcs4.auxiliary.lateral.socket.tcp.LateralTCPCacheFactory -jcs.auxiliary.LTCP.attributes=org.apache.commons.jcs4.auxiliary.lateral.socket.tcp.TCPLateralCacheAttributes +jcs.auxiliary.LTCP.attributes=org.apache.commons.jcs4.auxiliary.lateral.socket.tcp.LateralTCPCacheAttributes jcs.auxiliary.LTCP.attributes.TransmissionTypeName=TCP # jcs.auxiliary.LTCP.attributes.TcpServers= jcs.auxiliary.LTCP.attributes.TcpListenerPort=1121 diff --git a/commons-jcs4-core/src/test/java/org/apache/commons/jcs4/auxiliary/lateral/LateralCacheNoWaitFacadeUnitTest.java b/commons-jcs4-core/src/test/java/org/apache/commons/jcs4/auxiliary/lateral/socket/tcp/LateralCacheNoWaitFacadeUnitTest.java similarity index 76% rename from commons-jcs4-core/src/test/java/org/apache/commons/jcs4/auxiliary/lateral/LateralCacheNoWaitFacadeUnitTest.java rename to commons-jcs4-core/src/test/java/org/apache/commons/jcs4/auxiliary/lateral/socket/tcp/LateralCacheNoWaitFacadeUnitTest.java index 381d974b..0ee08a1c 100644 --- a/commons-jcs4-core/src/test/java/org/apache/commons/jcs4/auxiliary/lateral/LateralCacheNoWaitFacadeUnitTest.java +++ b/commons-jcs4-core/src/test/java/org/apache/commons/jcs4/auxiliary/lateral/socket/tcp/LateralCacheNoWaitFacadeUnitTest.java @@ -1,4 +1,4 @@ -package org.apache.commons.jcs4.auxiliary.lateral; +package org.apache.commons.jcs4.auxiliary.lateral.socket.tcp; /* * Licensed to the Apache Software Foundation (ASF) under one @@ -26,31 +26,30 @@ import static org.junit.jupiter.api.Assertions.assertTrue; import java.util.ArrayList; import java.util.List; -import org.apache.commons.jcs4.auxiliary.lateral.socket.tcp.TCPLateralCacheAttributes; import org.apache.commons.jcs4.engine.ZombieCacheServiceNonLocal; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; /** - * Tests for LateralCacheNoWaitFacade. + * Tests for LateralTCPCacheNoWaitFacade. */ class LateralCacheNoWaitFacadeUnitTest { - private LateralCacheNoWaitFacade<String, String> facade; - private LateralCache<String, String> cache; + private LateralTCPCacheNoWaitFacade<String, String> facade; + private LateralTCPCache<String, String> cache; @BeforeEach void setUp() throws Exception { // SETUP - final List<LateralCacheNoWait<String, String>> noWaits = new ArrayList<>(); - final TCPLateralCacheAttributes cattr = new TCPLateralCacheAttributes(); + final List<LateralTCPCacheNoWait<String, String>> noWaits = new ArrayList<>(); + final LateralTCPCacheAttributes cattr = new LateralTCPCacheAttributes(); cattr.setCacheName( "testCache1" ); cattr.setTcpServer("localhost:7890"); - facade = new LateralCacheNoWaitFacade<>( null, noWaits, cattr ); - cache = new LateralCache<>(cattr, new ZombieCacheServiceNonLocal<>(), null); + facade = new LateralTCPCacheNoWaitFacade<>( null, noWaits, cattr ); + cache = new LateralTCPCache<>(cattr, new ZombieCacheServiceNonLocal<>(), null); } /** @@ -59,7 +58,7 @@ class LateralCacheNoWaitFacadeUnitTest @Test void testAdd_InList() { - final LateralCacheNoWait<String, String> noWait = new LateralCacheNoWait<>( cache ); + final LateralTCPCacheNoWait<String, String> noWait = new LateralTCPCacheNoWait<>( cache ); // DO WORK facade.addNoWait( noWait ); @@ -76,7 +75,7 @@ class LateralCacheNoWaitFacadeUnitTest @Test void testAddThenRemoveNoWait_InList() { - final LateralCacheNoWait<String, String> noWait = new LateralCacheNoWait<>( cache ); + final LateralTCPCacheNoWait<String, String> noWait = new LateralTCPCacheNoWait<>( cache ); // DO WORK facade.addNoWait( noWait ); @@ -98,9 +97,9 @@ class LateralCacheNoWaitFacadeUnitTest @Test void testAddThenRemoveNoWait_InListSize2() { - final LateralCacheNoWait<String, String> noWait = new LateralCacheNoWait<>( cache ); + final LateralTCPCacheNoWait<String, String> noWait = new LateralTCPCacheNoWait<>( cache ); noWait.setIdentityKey("1234"); - final LateralCacheNoWait<String, String> noWait2 = new LateralCacheNoWait<>( cache ); + final LateralTCPCacheNoWait<String, String> noWait2 = new LateralTCPCacheNoWait<>( cache ); noWait2.setIdentityKey("2345"); // DO WORK @@ -127,7 +126,7 @@ class LateralCacheNoWaitFacadeUnitTest @Test void testAddThenRemoveNoWait_NotInList() { - final LateralCacheNoWait<String, String> noWait = new LateralCacheNoWait<>( cache ); + final LateralTCPCacheNoWait<String, String> noWait = new LateralTCPCacheNoWait<>( cache ); // DO WORK facade.removeNoWait( noWait ); diff --git a/commons-jcs4-core/src/test/java/org/apache/commons/jcs4/auxiliary/lateral/socket/tcp/LateralTCPConcurrentRandomTestUtil.java b/commons-jcs4-core/src/test/java/org/apache/commons/jcs4/auxiliary/lateral/socket/tcp/LateralTCPConcurrentRandomTestUtil.java index e5dc9c73..4b218455 100644 --- a/commons-jcs4-core/src/test/java/org/apache/commons/jcs4/auxiliary/lateral/socket/tcp/LateralTCPConcurrentRandomTestUtil.java +++ b/commons-jcs4-core/src/test/java/org/apache/commons/jcs4/auxiliary/lateral/socket/tcp/LateralTCPConcurrentRandomTestUtil.java @@ -69,7 +69,7 @@ public class LateralTCPConcurrentRandomTestUtil final CacheAccess<String, String> cache = JCS.getInstance( region ); - final TCPLateralCacheAttributes lattr2 = new TCPLateralCacheAttributes(); + final LateralTCPCacheAttributes lattr2 = new LateralTCPCacheAttributes(); lattr2.setTcpListenerPort( 1103 ); lattr2.setTcpServer( "localhost:1102" ); 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 0cee54d1..eb6cb0e4 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 @@ -25,9 +25,6 @@ import static org.junit.jupiter.api.Assertions.assertTrue; import java.util.ArrayList; import java.util.List; -import org.apache.commons.jcs4.auxiliary.lateral.LateralCache; -import org.apache.commons.jcs4.auxiliary.lateral.LateralCacheNoWait; -import org.apache.commons.jcs4.auxiliary.lateral.LateralCacheNoWaitFacade; import org.apache.commons.jcs4.engine.ZombieCacheServiceNonLocal; import org.apache.commons.jcs4.engine.behavior.IElementSerializer; import org.apache.commons.jcs4.engine.control.CompositeCacheManager; @@ -71,22 +68,22 @@ class LateralTCPDiscoveryListenerUnitTest cacheEventLogger, elementSerializer ); } - private LateralCacheNoWaitFacade<String, String> setupFacade(final String cacheName) + private LateralTCPCacheNoWaitFacade<String, String> setupFacade(final String cacheName) { - final List<LateralCacheNoWait<String, String>> noWaits = new ArrayList<>(); - final TCPLateralCacheAttributes cattr = new TCPLateralCacheAttributes(); + final List<LateralTCPCacheNoWait<String, String>> noWaits = new ArrayList<>(); + final LateralTCPCacheAttributes cattr = new LateralTCPCacheAttributes(); cattr.setCacheName( cacheName ); - return new LateralCacheNoWaitFacade<>( null, noWaits, cattr ); + return new LateralTCPCacheNoWaitFacade<>( null, noWaits, cattr ); } - private LateralCacheNoWait<String, String> setupNoWait(final String cacheName) + private LateralTCPCacheNoWait<String, String> setupNoWait(final String cacheName) { - final TCPLateralCacheAttributes cattr = new TCPLateralCacheAttributes(); + final LateralTCPCacheAttributes cattr = new LateralTCPCacheAttributes(); cattr.setCacheName( cacheName ); - final LateralCache<String, String> cache = new LateralCache<>(cattr, new ZombieCacheServiceNonLocal<>(), null); - return new LateralCacheNoWait<>( cache ); + final LateralTCPCache<String, String> cache = new LateralTCPCache<>(cattr, new ZombieCacheServiceNonLocal<>(), null); + return new LateralTCPCacheNoWait<>( cache ); } /** @@ -105,16 +102,16 @@ class LateralTCPDiscoveryListenerUnitTest service.setServiceAddress( "localhost" ); service.setServicePort( 9999 ); - final TCPLateralCacheAttributes lca = new TCPLateralCacheAttributes(); + final LateralTCPCacheAttributes lca = new LateralTCPCacheAttributes(); // used as identifying key by factory lca.setTcpServer( service.getServiceAddress() + ":" + service.getServicePort() ); lca.setCacheName(cacheName); - final LateralCacheNoWait<String, String> noWait = factory.createCacheNoWait(lca, cacheEventLogger, elementSerializer); + final LateralTCPCacheNoWait<String, String> noWait = factory.createCacheNoWait(lca, cacheEventLogger, elementSerializer); // this is the normal process, the discovery service expects it there cacheMgr.addAuxiliaryCache(factory.getName(), cacheName, noWait); cacheMgr.registryFacPut(factory); - final LateralCacheNoWaitFacade<String, String> facade = setupFacade(cacheName); + final LateralTCPCacheNoWaitFacade<String, String> facade = setupFacade(cacheName); listener.addNoWaitFacade( cacheName, facade ); // DO WORK @@ -132,10 +129,10 @@ class LateralTCPDiscoveryListenerUnitTest { // SETUP final String cacheName = "testAddNoWaitFacade_FacadeInList"; - final LateralCacheNoWaitFacade<String, String> facade = setupFacade(cacheName); + final LateralTCPCacheNoWaitFacade<String, String> facade = setupFacade(cacheName); listener.addNoWaitFacade( cacheName, facade ); - final LateralCacheNoWait<String, String> noWait = setupNoWait(cacheName); + final LateralTCPCacheNoWait<String, String> noWait = setupNoWait(cacheName); // DO WORK final boolean result = listener.addNoWait( noWait ); @@ -152,7 +149,7 @@ class LateralTCPDiscoveryListenerUnitTest { // SETUP final String cacheName = "testAddNoWaitFacade_FacadeInList"; - final LateralCacheNoWait<String, String> noWait = setupNoWait(cacheName); + final LateralTCPCacheNoWait<String, String> noWait = setupNoWait(cacheName); // DO WORK final boolean result = listener.addNoWait( noWait ); @@ -169,7 +166,7 @@ class LateralTCPDiscoveryListenerUnitTest { // SETUP final String cacheName = "testAddNoWaitFacade_NotInList"; - final LateralCacheNoWaitFacade<String, String> facade = setupFacade(cacheName); + final LateralTCPCacheNoWaitFacade<String, String> facade = setupFacade(cacheName); // DO WORK listener.addNoWaitFacade( cacheName, facade ); @@ -187,12 +184,12 @@ class LateralTCPDiscoveryListenerUnitTest // SETUP final String cacheName = "testEmptyNoWaits"; - final TCPLateralCacheAttributes lca = new TCPLateralCacheAttributes(); + final LateralTCPCacheAttributes lca = new LateralTCPCacheAttributes(); lca.setTcpServers(""); // default lca.setTcpListenerPort(1120); lca.setCacheName(cacheName); lca.setUdpDiscoveryEnabled(false); - final LateralCacheNoWaitFacade<String, String> noWait = factory.createCache(lca, cacheMgr, cacheEventLogger, elementSerializer); + final LateralTCPCacheNoWaitFacade<String, String> noWait = factory.createCache(lca, cacheMgr, cacheEventLogger, elementSerializer); // VERIFY assertFalse( noWait.containsNoWait( "" ), "No waits should be empty." ); @@ -215,16 +212,16 @@ class LateralTCPDiscoveryListenerUnitTest service.setServiceAddress( "localhost" ); service.setServicePort( 9999 ); - final TCPLateralCacheAttributes lca = new TCPLateralCacheAttributes(); + final LateralTCPCacheAttributes lca = new LateralTCPCacheAttributes(); // used as identifying key by factory lca.setTcpServer( service.getServiceAddress() + ":" + service.getServicePort() ); lca.setCacheName(cacheName); - final LateralCacheNoWait<String, String> noWait = factory.createCacheNoWait(lca, cacheEventLogger, elementSerializer); + final LateralTCPCacheNoWait<String, String> noWait = factory.createCacheNoWait(lca, cacheEventLogger, elementSerializer); // this is the normal process, the discovery service expects it there cacheMgr.addAuxiliaryCache(factory.getName(), cacheName, noWait); cacheMgr.registryFacPut(factory); - final LateralCacheNoWaitFacade<String, String> facade = setupFacade(cacheName); + final LateralTCPCacheNoWaitFacade<String, String> facade = setupFacade(cacheName); listener.addNoWaitFacade( cacheName, facade ); listener.addDiscoveredService( service ); @@ -243,10 +240,10 @@ class LateralTCPDiscoveryListenerUnitTest { // SETUP final String cacheName = "testRemoveNoWaitFacade_FacadeInListNoWaitIs"; - final LateralCacheNoWaitFacade<String, String> facade = setupFacade(cacheName); + final LateralTCPCacheNoWaitFacade<String, String> facade = setupFacade(cacheName); listener.addNoWaitFacade( cacheName, facade ); - final LateralCacheNoWait<String, String> noWait = setupNoWait(cacheName); + final LateralTCPCacheNoWait<String, String> noWait = setupNoWait(cacheName); listener.addNoWait( noWait ); // DO WORK @@ -264,10 +261,10 @@ class LateralTCPDiscoveryListenerUnitTest { // SETUP final String cacheName = "testAddNoWaitFacade_FacadeInList"; - final LateralCacheNoWaitFacade<String, String> facade = setupFacade(cacheName); + final LateralTCPCacheNoWaitFacade<String, String> facade = setupFacade(cacheName); listener.addNoWaitFacade( cacheName, facade ); - final LateralCacheNoWait<String, String> noWait = setupNoWait(cacheName); + final LateralTCPCacheNoWait<String, String> noWait = setupNoWait(cacheName); // DO WORK final boolean result = listener.removeNoWait( noWait ); @@ -284,7 +281,7 @@ class LateralTCPDiscoveryListenerUnitTest { // SETUP final String cacheName = "testRemoveNoWaitFacade_FacadeNotInList"; - final LateralCacheNoWait<String, String> noWait = setupNoWait(cacheName); + final LateralTCPCacheNoWait<String, String> noWait = setupNoWait(cacheName); // DO WORK final boolean result = listener.removeNoWait( noWait ); diff --git a/commons-jcs4-core/src/test/java/org/apache/commons/jcs4/auxiliary/lateral/socket/tcp/LateralTCPFilterRemoveHashCodeUnitTest.java b/commons-jcs4-core/src/test/java/org/apache/commons/jcs4/auxiliary/lateral/socket/tcp/LateralTCPFilterRemoveHashCodeUnitTest.java index 1f6d7726..a875b81e 100644 --- a/commons-jcs4-core/src/test/java/org/apache/commons/jcs4/auxiliary/lateral/socket/tcp/LateralTCPFilterRemoveHashCodeUnitTest.java +++ b/commons-jcs4-core/src/test/java/org/apache/commons/jcs4/auxiliary/lateral/socket/tcp/LateralTCPFilterRemoveHashCodeUnitTest.java @@ -73,7 +73,7 @@ public class LateralTCPFilterRemoveHashCodeUnitTest Thread.sleep( 100 ); - final TCPLateralCacheAttributes lattr2 = new TCPLateralCacheAttributes(); + final LateralTCPCacheAttributes lattr2 = new LateralTCPCacheAttributes(); lattr2.setTcpListenerPort( 1102 ); lattr2.setTcpServer( "localhost:" + serverPort ); lattr2.setIssueRemoveOnPut( true ); diff --git a/commons-jcs4-core/src/test/java/org/apache/commons/jcs4/auxiliary/lateral/socket/tcp/LateralTCPIssueRemoveOnPutUnitTest.java b/commons-jcs4-core/src/test/java/org/apache/commons/jcs4/auxiliary/lateral/socket/tcp/LateralTCPIssueRemoveOnPutUnitTest.java index 35a78b8c..0f5845cd 100644 --- a/commons-jcs4-core/src/test/java/org/apache/commons/jcs4/auxiliary/lateral/socket/tcp/LateralTCPIssueRemoveOnPutUnitTest.java +++ b/commons-jcs4-core/src/test/java/org/apache/commons/jcs4/auxiliary/lateral/socket/tcp/LateralTCPIssueRemoveOnPutUnitTest.java @@ -73,7 +73,7 @@ public class LateralTCPIssueRemoveOnPutUnitTest Thread.sleep( 100 ); - final TCPLateralCacheAttributes lattr2 = new TCPLateralCacheAttributes(); + final LateralTCPCacheAttributes lattr2 = new LateralTCPCacheAttributes(); lattr2.setTcpListenerPort( 1102 ); lattr2.setTcpServer( "localhost:" + serverPort ); lattr2.setIssueRemoveOnPut( true ); @@ -185,7 +185,7 @@ public class LateralTCPIssueRemoveOnPutUnitTest Thread.sleep( 100 ); - final TCPLateralCacheAttributes lattr2 = new TCPLateralCacheAttributes(); + final LateralTCPCacheAttributes lattr2 = new LateralTCPCacheAttributes(); lattr2.setTcpListenerPort( 1102 ); lattr2.setTcpServer( "localhost:" + serverPort ); lattr2.setIssueRemoveOnPut( false ); diff --git a/commons-jcs4-core/src/test/java/org/apache/commons/jcs4/auxiliary/lateral/socket/tcp/TestTCPLateralUnitTest.java b/commons-jcs4-core/src/test/java/org/apache/commons/jcs4/auxiliary/lateral/socket/tcp/TestTCPLateralUnitTest.java index 9da7e584..318e994c 100644 --- a/commons-jcs4-core/src/test/java/org/apache/commons/jcs4/auxiliary/lateral/socket/tcp/TestTCPLateralUnitTest.java +++ b/commons-jcs4-core/src/test/java/org/apache/commons/jcs4/auxiliary/lateral/socket/tcp/TestTCPLateralUnitTest.java @@ -53,7 +53,7 @@ class TestTCPLateralUnitTest private <K,V> CompositeCache<K, V> createCache(final int port) { - final TCPLateralCacheAttributes lattr = new TCPLateralCacheAttributes(); + final LateralTCPCacheAttributes lattr = new LateralTCPCacheAttributes(); lattr.setTcpListenerPort(port); final CompositeCache<K, V> cache = cacheMgr.getCache( "test" ); @@ -68,7 +68,7 @@ class TestTCPLateralUnitTest private <K, V> LateralTCPService<K, V> createService(final int listenerPort, final int serverPort, final long listenerId) throws IOException { - final TCPLateralCacheAttributes lattr2 = new TCPLateralCacheAttributes(); + final LateralTCPCacheAttributes lattr2 = new LateralTCPCacheAttributes(); lattr2.setTcpListenerPort(listenerPort); lattr2.setTcpServer("localhost:" + serverPort); @@ -93,7 +93,7 @@ class TestTCPLateralUnitTest // force initialization JCS.getInstance( "test" ); - final TCPLateralCacheAttributes lac = new TCPLateralCacheAttributes(); + final LateralTCPCacheAttributes lac = new LateralTCPCacheAttributes(); lac.setTcpServer( "localhost:" + port ); lac.setTcpListenerPort( port ); diff --git a/commons-jcs4-core/src/test/java/org/apache/commons/jcs4/utils/discovery/UDPDiscoveryServiceUnitTest.java b/commons-jcs4-core/src/test/java/org/apache/commons/jcs4/utils/discovery/UDPDiscoveryServiceUnitTest.java index 04490613..bcf1eba6 100644 --- a/commons-jcs4-core/src/test/java/org/apache/commons/jcs4/utils/discovery/UDPDiscoveryServiceUnitTest.java +++ b/commons-jcs4-core/src/test/java/org/apache/commons/jcs4/utils/discovery/UDPDiscoveryServiceUnitTest.java @@ -43,10 +43,12 @@ class UDPDiscoveryServiceUnitTest throws Exception { // SETUP - final UDPDiscoveryAttributes attributes = new UDPDiscoveryAttributes(); - attributes.setUdpDiscoveryAddr( host ); - attributes.setUdpDiscoveryPort( port ); - attributes.setServicePort( 1000 ); + final UDPDiscoveryAttributes attributes = new UDPDiscoveryAttributes( + 1000, + host, + port, + UDPDiscoveryAttributes.defaults().udpTTL() + ); // create the service service = new UDPDiscoveryService(attributes, new StandardSerializer()); diff --git a/commons-jcs4-core/src/test/java/org/apache/commons/jcs4/utils/discovery/UDPDiscoveryUnitTest.java b/commons-jcs4-core/src/test/java/org/apache/commons/jcs4/utils/discovery/UDPDiscoveryUnitTest.java index 195f9fd9..e344cd8c 100644 --- a/commons-jcs4-core/src/test/java/org/apache/commons/jcs4/utils/discovery/UDPDiscoveryUnitTest.java +++ b/commons-jcs4-core/src/test/java/org/apache/commons/jcs4/utils/discovery/UDPDiscoveryUnitTest.java @@ -41,11 +41,12 @@ class UDPDiscoveryUnitTest private void simpleUDPDiscovery(final String discoveryAddress) throws Exception { - final UDPDiscoveryAttributes attributes = new UDPDiscoveryAttributes(); - attributes.setUdpDiscoveryAddr(discoveryAddress); - attributes.setUdpDiscoveryPort(6789); - attributes.setServicePort(1000); - attributes.setUdpTTL(4); /* datagram TTL */ + final UDPDiscoveryAttributes attributes = new UDPDiscoveryAttributes( + 1000, + discoveryAddress, + 6789, + 4 /* datagram TTL */ + ); // create the service final UDPDiscoveryService service = new UDPDiscoveryService(attributes, new StandardSerializer()); @@ -58,8 +59,8 @@ class UDPDiscoveryUnitTest // create a receiver with the service final UDPDiscoveryReceiver receiver = new UDPDiscoveryReceiver( service::processMessage, null, - attributes.getUdpDiscoveryAddr(), - attributes.getUdpDiscoveryPort() ); + attributes.udpDiscoveryAddr(), + attributes.udpDiscoveryPort() ); receiver.setSerializer(service.getSerializer()); final Thread t = new Thread( receiver ); t.start(); diff --git a/commons-jcs4-core/src/test/test-conf/TestTCPLateralCache.ccf b/commons-jcs4-core/src/test/test-conf/TestTCPLateralCache.ccf index 10d46654..b7553a2c 100644 --- a/commons-jcs4-core/src/test/test-conf/TestTCPLateralCache.ccf +++ b/commons-jcs4-core/src/test/test-conf/TestTCPLateralCache.ccf @@ -35,7 +35,7 @@ jcs.region.testTcpRegion1.cacheattributes.MemoryCacheName=org.apache.commons.jcs # simple Lateral TCP auxiliary jcs.auxiliary.LTCP=org.apache.commons.jcs4.auxiliary.lateral.socket.tcp.LateralTCPCacheFactory -jcs.auxiliary.LTCP.attributes=org.apache.commons.jcs4.auxiliary.lateral.socket.tcp.TCPLateralCacheAttributes +jcs.auxiliary.LTCP.attributes=org.apache.commons.jcs4.auxiliary.lateral.socket.tcp.LateralTCPCacheAttributes jcs.auxiliary.LTCP.attributes.TcpServers=localhost:1111 jcs.auxiliary.LTCP.attributes.TcpListenerPort=1110 jcs.auxiliary.LTCP.attributes.TcpListenerHost=localhost diff --git a/commons-jcs4-core/src/test/test-conf/TestTCPLateralCacheConcurrent.ccf b/commons-jcs4-core/src/test/test-conf/TestTCPLateralCacheConcurrent.ccf index dc285afd..bd2f3b88 100644 --- a/commons-jcs4-core/src/test/test-conf/TestTCPLateralCacheConcurrent.ccf +++ b/commons-jcs4-core/src/test/test-conf/TestTCPLateralCacheConcurrent.ccf @@ -22,7 +22,7 @@ jcs.default.cacheattributes.MemoryCacheName=org.apache.commons.jcs4.engine.memor # #### AUXILIARY CACHES # simple Lateral TCP auxiliary jcs.auxiliary.LTCP=org.apache.commons.jcs4.auxiliary.lateral.socket.tcp.LateralTCPCacheFactory -jcs.auxiliary.LTCP.attributes=org.apache.commons.jcs4.auxiliary.lateral.socket.tcp.TCPLateralCacheAttributes +jcs.auxiliary.LTCP.attributes=org.apache.commons.jcs4.auxiliary.lateral.socket.tcp.LateralTCPCacheAttributes jcs.auxiliary.LTCP.attributes.TransmissionTypeName=TCP # jcs.auxiliary.LTCP.attributes.TcpServers= jcs.auxiliary.LTCP.attributes.TcpListenerPort=1102 diff --git a/commons-jcs4-core/src/test/test-conf/TestTCPLateralIssueRemoveCache.ccf b/commons-jcs4-core/src/test/test-conf/TestTCPLateralIssueRemoveCache.ccf index bbe87b4e..ce606bb6 100644 --- a/commons-jcs4-core/src/test/test-conf/TestTCPLateralIssueRemoveCache.ccf +++ b/commons-jcs4-core/src/test/test-conf/TestTCPLateralIssueRemoveCache.ccf @@ -35,7 +35,7 @@ jcs.region.testTcpRegion1.cacheattributes.MemoryCacheName=org.apache.commons.jcs # simple Lateral TCP auxiliary jcs.auxiliary.LTCP=org.apache.commons.jcs4.auxiliary.lateral.socket.tcp.LateralTCPCacheFactory -jcs.auxiliary.LTCP.attributes=org.apache.commons.jcs4.auxiliary.lateral.socket.tcp.TCPLateralCacheAttributes +jcs.auxiliary.LTCP.attributes=org.apache.commons.jcs4.auxiliary.lateral.socket.tcp.LateralTCPCacheAttributes jcs.auxiliary.LTCP.attributes.TcpServers=localhost:1117 jcs.auxiliary.LTCP.attributes.TcpListenerPort=1118 jcs.auxiliary.LTCP.attributes.AllowGet=false diff --git a/commons-jcs4-core/src/test/test-conf/TestTCPLateralRemoveFilter.ccf b/commons-jcs4-core/src/test/test-conf/TestTCPLateralRemoveFilter.ccf index 0c6d3b70..d9a71890 100644 --- a/commons-jcs4-core/src/test/test-conf/TestTCPLateralRemoveFilter.ccf +++ b/commons-jcs4-core/src/test/test-conf/TestTCPLateralRemoveFilter.ccf @@ -35,7 +35,7 @@ jcs.region.testTcpRegion1.cacheattributes.MemoryCacheName=org.apache.commons.jcs # simple Lateral TCP auxiliary jcs.auxiliary.LTCP=org.apache.commons.jcs4.auxiliary.lateral.socket.tcp.LateralTCPCacheFactory -jcs.auxiliary.LTCP.attributes=org.apache.commons.jcs4.auxiliary.lateral.socket.tcp.TCPLateralCacheAttributes +jcs.auxiliary.LTCP.attributes=org.apache.commons.jcs4.auxiliary.lateral.socket.tcp.LateralTCPCacheAttributes jcs.auxiliary.LTCP.attributes.TcpServers=localhost:1117 jcs.auxiliary.LTCP.attributes.TcpListenerPort=2001 jcs.auxiliary.LTCP.attributes.AllowGet=false diff --git a/commons-jcs4-core/src/test/test-conf/TestUDPDiscovery.ccf b/commons-jcs4-core/src/test/test-conf/TestUDPDiscovery.ccf index 1f9b3519..5e3d35a1 100644 --- a/commons-jcs4-core/src/test/test-conf/TestUDPDiscovery.ccf +++ b/commons-jcs4-core/src/test/test-conf/TestUDPDiscovery.ccf @@ -69,7 +69,7 @@ jcs.region.testCache2.elementattributes.IsRemote=true # Lateral TCp with UDP discovery enabled jcs.auxiliary.LTCP=org.apache.commons.jcs4.auxiliary.lateral.socket.tcp.LateralTCPCacheFactory -jcs.auxiliary.LTCP.attributes=org.apache.commons.jcs4.auxiliary.lateral.socket.tcp.TCPLateralCacheAttributes +jcs.auxiliary.LTCP.attributes=org.apache.commons.jcs4.auxiliary.lateral.socket.tcp.LateralTCPCacheAttributes jcs.auxiliary.LTCP.attributes.TcpServers= jcs.auxiliary.LTCP.attributes.TcpListenerPort=1111 jcs.auxiliary.LTCP.attributes.AllowGet=false @@ -80,7 +80,7 @@ jcs.auxiliary.LTCP.attributes.UdpDiscoveryEnabled=true # Lateral TCP with UDP discovery disabled jcs.auxiliary.LTCP2=org.apache.commons.jcs4.auxiliary.lateral.socket.tcp.LateralTCPCacheFactory -jcs.auxiliary.LTCP2.attributes=org.apache.commons.jcs4.auxiliary.lateral.socket.tcp.TCPLateralCacheAttributes +jcs.auxiliary.LTCP2.attributes=org.apache.commons.jcs4.auxiliary.lateral.socket.tcp.LateralTCPCacheAttributes jcs.auxiliary.LTCP2.attributes.TcpServers= jcs.auxiliary.LTCP2.attributes.TcpListenerPort=1110 jcs.auxiliary.LTCP2.attributes.AllowGet=false diff --git a/xdocs/LateralTCPProperties.xml b/xdocs/LateralTCPProperties.xml index bd28fee1..3571b1de 100644 --- a/xdocs/LateralTCPProperties.xml +++ b/xdocs/LateralTCPProperties.xml @@ -107,6 +107,13 @@ <td>N</td> <td>228.5.6.7</td> </tr> + <tr> + <td>UdpDiscoveryInterface</td> + <td> The network interface the UDP discovery process should + use for broadcasts, for example en0.</td> + <td>N</td> + <td>null</td> + </tr> <tr> <td>UdpDiscoveryPort</td> <td> The port the UDP discovery process should send messages to.
