Skip to content

Commit

Permalink
Merge pull request naver#10 from jhpark816/joon-dev
Browse files Browse the repository at this point in the history
Throw AdminConnectTimeoutException if connecting to arcus admin timed out.
  • Loading branch information
hoonmin committed Jan 9, 2015
2 parents d9a65be + f1634c1 commit 56e3755
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 2 deletions.
27 changes: 27 additions & 0 deletions src/main/java/net/spy/memcached/AdminConnectTimeoutException.java
Original file line number Diff line number Diff line change
@@ -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);
}

}
13 changes: 11 additions & 2 deletions src/main/java/net/spy/memcached/CacheManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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(
Expand All @@ -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;
Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit 56e3755

Please sign in to comment.