Skip to content

Commit

Permalink
add timeout config to zookeeper client (#4963)
Browse files Browse the repository at this point in the history
  • Loading branch information
LiZhenNet authored and beiwei30 committed Sep 2, 2019
1 parent 5bdbc88 commit 36fc6c5
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
Expand Up @@ -16,6 +16,7 @@
*/
package com.alibaba.dubbo.remoting.zookeeper.curator;

import com.alibaba.dubbo.common.Constants;
import com.alibaba.dubbo.common.URL;
import com.alibaba.dubbo.common.utils.StringUtils;
import com.alibaba.dubbo.remoting.zookeeper.ChildListener;
Expand Down Expand Up @@ -43,10 +44,11 @@ public class CuratorZookeeperClient extends AbstractZookeeperClient<CuratorWatch
public CuratorZookeeperClient(URL url) {
super(url);
try {
int timeout = url.getParameter(Constants.TIMEOUT_KEY, 5000);
CuratorFrameworkFactory.Builder builder = CuratorFrameworkFactory.builder()
.connectString(url.getBackupAddress())
.retryPolicy(new RetryNTimes(1, 1000))
.connectionTimeoutMs(5000);
.connectionTimeoutMs(timeout);
String authority = url.getAuthority();
if (authority != null && authority.length() > 0) {
builder = builder.authorization("digest", authority.getBytes());
Expand Down
Expand Up @@ -16,11 +16,11 @@
*/
package com.alibaba.dubbo.remoting.zookeeper.zkclient;

import com.alibaba.dubbo.common.Constants;
import com.alibaba.dubbo.common.URL;
import com.alibaba.dubbo.remoting.zookeeper.ChildListener;
import com.alibaba.dubbo.remoting.zookeeper.StateListener;
import com.alibaba.dubbo.remoting.zookeeper.support.AbstractZookeeperClient;

import org.I0Itec.zkclient.IZkChildListener;
import org.I0Itec.zkclient.IZkStateListener;
import org.I0Itec.zkclient.exception.ZkNoNodeException;
Expand All @@ -37,7 +37,8 @@ public class ZkclientZookeeperClient extends AbstractZookeeperClient<IZkChildLis

public ZkclientZookeeperClient(URL url) {
super(url);
client = new ZkClientWrapper(url.getBackupAddress(), 30000);
long timeout = url.getParameter(Constants.TIMEOUT_KEY, 30000L);
client = new ZkClientWrapper(url.getBackupAddress(), timeout);
client.addListener(new IZkStateListener() {
@Override
public void handleStateChanged(KeeperState state) throws Exception {
Expand Down

0 comments on commit 36fc6c5

Please sign in to comment.