From 4b7ec9b60c2106a14b41719b11360e8e718d7134 Mon Sep 17 00:00:00 2001 From: axb Date: Thu, 28 Apr 2016 03:18:58 +0800 Subject: [PATCH] make zookeeper registry configurable --- .../registry/support/AbstractRegistryFactory.java | 2 +- .../zookeeper/ZookeeperRegistryFactory.java | 13 +++++++++---- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/motan-core/src/main/java/com/weibo/api/motan/registry/support/AbstractRegistryFactory.java b/motan-core/src/main/java/com/weibo/api/motan/registry/support/AbstractRegistryFactory.java index 991213a82..2c89a2f1d 100644 --- a/motan-core/src/main/java/com/weibo/api/motan/registry/support/AbstractRegistryFactory.java +++ b/motan-core/src/main/java/com/weibo/api/motan/registry/support/AbstractRegistryFactory.java @@ -60,7 +60,7 @@ public Registry getRegistry(URL url) { registries.put(registryUri, registry); return registry; } catch (Exception e) { - throw new MotanFrameworkException("Create registry false for url:" + url, MotanErrorMsgConstant.FRAMEWORK_INIT_ERROR); + throw new MotanFrameworkException("Create registry false for url:" + url, e, MotanErrorMsgConstant.FRAMEWORK_INIT_ERROR); } finally { lock.unlock(); } diff --git a/motan-registry-zookeeper/src/main/java/com/weibo/api/motan/registry/zookeeper/ZookeeperRegistryFactory.java b/motan-registry-zookeeper/src/main/java/com/weibo/api/motan/registry/zookeeper/ZookeeperRegistryFactory.java index a353fe19f..5145270be 100644 --- a/motan-registry-zookeeper/src/main/java/com/weibo/api/motan/registry/zookeeper/ZookeeperRegistryFactory.java +++ b/motan-registry-zookeeper/src/main/java/com/weibo/api/motan/registry/zookeeper/ZookeeperRegistryFactory.java @@ -16,6 +16,7 @@ package com.weibo.api.motan.registry.zookeeper; +import com.weibo.api.motan.common.URLParamType; import com.weibo.api.motan.core.extension.SpiMeta; import com.weibo.api.motan.registry.Registry; import com.weibo.api.motan.registry.support.AbstractRegistryFactory; @@ -34,13 +35,17 @@ public class ZookeeperRegistryFactory extends AbstractRegistryFactory { @Override - protected Registry createRegistry(URL url) { - ZkClient client = null; + protected Registry createRegistry(URL registryUrl) { try { - client = new ZkClient(url.getParameter("address")); + int timeout = registryUrl.getIntParameter(URLParamType.requestTimeout.getName(), URLParamType.requestTimeout.getIntValue()); + int sessionTimeout = + registryUrl.getIntParameter(URLParamType.registrySessionTimeout.getName(), + URLParamType.registrySessionTimeout.getIntValue()); + ZkClient zkClient = new ZkClient(registryUrl.getParameter("address"), sessionTimeout, timeout); + return new ZookeeperRegistry(registryUrl, zkClient); } catch (ZkException e) { LoggerUtil.error("[ZookeeperRegistry] fail to connect zookeeper, cause: " + e.getMessage()); + throw e; } - return new ZookeeperRegistry(url, client); } }