diff --git a/src/main/java/net/spy/memcached/CacheManager.java b/src/main/java/net/spy/memcached/CacheManager.java index 318793f81..6ae61d439 100644 --- a/src/main/java/net/spy/memcached/CacheManager.java +++ b/src/main/java/net/spy/memcached/CacheManager.java @@ -398,6 +398,17 @@ public void run() { waitBeforeRetryMonitorCheck(1000L - elapsed); } } + + // Handling cacheList changes to a MemcachedConnection resulting + // from the processing of a CacheMonitor's Watch event. + for (ArcusClient ac : getAC()) { + try { + ac.getMemcachedConnection().handleCacheNodesChange(); + } catch (IOException e) { + getLogger().error("Cache List update error in ArcusClient {}, exception = {}", + ac.getName(), e.getCause()); + } + } } } getLogger().info("Close cache manager."); @@ -482,6 +493,10 @@ public void commandCacheListChange(List children) { MemcachedConnection conn = ac.getMemcachedConnection(); conn.setCacheNodesChange(addrs); } + + synchronized (this) { + notifyAll(); // awake CacheManager Thread. + } } /* ENABLE_MIGRATION if */ diff --git a/src/main/java/net/spy/memcached/MemcachedConnection.java b/src/main/java/net/spy/memcached/MemcachedConnection.java index 0ef7282a1..55db5d7db 100644 --- a/src/main/java/net/spy/memcached/MemcachedConnection.java +++ b/src/main/java/net/spy/memcached/MemcachedConnection.java @@ -44,6 +44,7 @@ import java.util.SortedMap; import java.util.TreeMap; import java.util.concurrent.ConcurrentLinkedQueue; +import java.util.concurrent.CopyOnWriteArrayList; import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicReference; @@ -142,7 +143,7 @@ public MemcachedConnection(String name, ConnectionFactory f, timeoutRatioThreshold = f.getTimeoutRatioThreshold(); timeoutDurationThreshold = f.getTimeoutDurationThreshold(); selector = Selector.open(); - List connections = new ArrayList(a.size()); + List connections = new CopyOnWriteArrayList(); for (SocketAddress sa : a) { connections.add(makeMemcachedNode(connName, sa)); } @@ -304,9 +305,6 @@ public void handleIO() throws IOException { } /* ENABLE_REPLICATION end */ - // Deal with the memcached server group that's been added by CacheManager. - handleCacheNodesChange(); - if (!reconnectQueue.isEmpty()) { attemptReconnects(); }