use of com.alipay.sofa.ark.config.RegistryConfig in project sofa-ark by alipay.
the class ZookeeperConfigActivator method start.
@Override
public void start(final PluginContext context) {
if (!enableZkServer) {
LOGGER.warn("config server is disabled.");
return;
}
String config = ArkConfigs.getStringValue(Constants.CONFIG_SERVER_ADDRESS);
RegistryConfig registryConfig = ZookeeperConfigurator.buildConfig(config);
String address = registryConfig.getAddress();
int idx = address.indexOf(Constants.ZOOKEEPER_CONTEXT_SPLIT);
if (idx != -1) {
rootPath = address.substring(idx);
if (!rootPath.endsWith(Constants.ZOOKEEPER_CONTEXT_SPLIT)) {
rootPath += Constants.ZOOKEEPER_CONTEXT_SPLIT;
}
address = address.substring(0, idx);
}
RetryPolicy retryPolicy = new ExponentialBackoffRetry(1000, 3);
CuratorFrameworkFactory.Builder zkClientBuilder = CuratorFrameworkFactory.builder().connectString(address).sessionTimeoutMs(3 * registryConfig.getConnectTimeout()).connectionTimeoutMs(registryConfig.getConnectTimeout()).canBeReadOnly(false).retryPolicy(retryPolicy).defaultData(null);
List<AuthInfo> authInfos = buildAuthInfo(registryConfig);
if (!authInfos.isEmpty()) {
zkClientBuilder = zkClientBuilder.aclProvider(getDefaultAclProvider()).authorization(authInfos);
}
zkClient = zkClientBuilder.build();
zkClient.getConnectionStateListenable().addListener(new ConnectionStateListener() {
@Override
public void stateChanged(CuratorFramework client, ConnectionState newState) {
LOGGER.info("Reconnect to zookeeper, re-register config resource.");
if (newState == ConnectionState.RECONNECTED) {
unSubscribeIpConfig();
registryResource(ipResourcePath, CreateMode.EPHEMERAL);
subscribeIpConfig();
}
}
});
zkClient.start();
registryResource(bizResourcePath, CreateMode.PERSISTENT);
registryResource(ipResourcePath, CreateMode.EPHEMERAL);
subscribeIpConfig();
subscribeBizConfig();
registerEventHandler(context);
}
use of com.alipay.sofa.ark.config.RegistryConfig in project sofa-ark by alipay.
the class ZookeeperConfigurator method buildConfig.
public static RegistryConfig buildConfig(String config) {
String zkAddress = parseAddress(config);
Map<String, String> parameters = parseParam(config);
return new RegistryConfig().setAddress(zkAddress).setProtocol(Constants.CONFIG_PROTOCOL_ZOOKEEPER).setParameters(parameters);
}
Aggregations