diff --git a/src/main/java/net/spy/memcached/AdminConnectTimeoutException.java b/src/main/java/net/spy/memcached/AdminConnectTimeoutException.java new file mode 100644 index 00000000..e4251807 --- /dev/null +++ b/src/main/java/net/spy/memcached/AdminConnectTimeoutException.java @@ -0,0 +1,27 @@ +/* + * arcus-java-client : Arcus Java client + * Copyright 2014 JaM2in Co., Ltd. + * + * Licensed 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 + * + * http://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. + */ +package net.spy.memcached; + +public class AdminConnectTimeoutException extends RuntimeException { + + private static final long serialVersionUID = -1461409015284668293L; + + public AdminConnectTimeoutException(String message) { + super(message); + } + +} diff --git a/src/main/java/net/spy/memcached/CacheManager.java b/src/main/java/net/spy/memcached/CacheManager.java index ac85607e..f4402da4 100644 --- a/src/main/java/net/spy/memcached/CacheManager.java +++ b/src/main/java/net/spy/memcached/CacheManager.java @@ -52,7 +52,7 @@ public class CacheManager extends SpyThread implements Watcher, private static final int SESSION_TIMEOUT = 15000; - private static final long ZK_CONNECT_TIMEOUT = 2000L; + private static final long ZK_CONNECT_TIMEOUT = 5000L; private final String hostPort; @@ -106,7 +106,11 @@ private void initZooKeeperClient() { zk = new ZooKeeper(hostPort, SESSION_TIMEOUT, this); try { - zkInitLatch.await(ZK_CONNECT_TIMEOUT, TimeUnit.MILLISECONDS); + if (zkInitLatch.await(ZK_CONNECT_TIMEOUT, TimeUnit.MILLISECONDS) == false) { + getLogger().fatal("Connecting to Arcus admin(%s) timed out : %d miliseconds", + hostPort, ZK_CONNECT_TIMEOUT); + throw new AdminConnectTimeoutException(hostPort); + } if (zk.exists(CacheManager.CACHE_LIST_PATH + serviceCode, false) == null) { getLogger().fatal( @@ -127,6 +131,9 @@ private void initZooKeeperClient() { zk.create(path, null, Ids.OPEN_ACL_UNSAFE, CreateMode.EPHEMERAL); } + } catch (AdminConnectTimeoutException e) { + shutdownZooKeeperClient(); + throw e; } catch (NotExistsServiceCodeException e) { shutdownZooKeeperClient(); throw e; @@ -214,6 +221,8 @@ public void run() { try { shutdownZooKeeperClient(); initZooKeeperClient(); + } catch (AdminConnectTimeoutException e) { + Thread.sleep(5000L); } catch (NotExistsServiceCodeException e) { Thread.sleep(5000L); } catch (InitializeClientException e) {