use of org.apache.curator.retry.ExponentialBackoffRetry in project metron by apache.
the class MaaSHandler method start.
public void start() throws Exception {
if (client == null) {
RetryPolicy retryPolicy = new ExponentialBackoffRetry(1000, 3);
client = CuratorFrameworkFactory.newClient(zkQuorum, retryPolicy);
client.start();
}
config = ConfigUtil.INSTANCE.read(client, root, new MaaSConfig(), MaaSConfig.class);
cache = new NodeCache(client, root);
cache.getListenable().addListener(() -> {
byte[] data = cache.getCurrentData().getData();
Lock wLock = lock.writeLock();
wLock.lock();
try {
config = _mapper.readValue(data, MaaSConfig.class);
} finally {
wLock.unlock();
}
});
discoverer = new ServiceDiscoverer(client, config.getServiceRoot());
discoverer.start();
}
use of org.apache.curator.retry.ExponentialBackoffRetry in project Saturn by vipshop.
the class ZookeeperRegistryCenter method buildZkClient.
private CuratorFramework buildZkClient() {
if (zkConfig.isUseNestedZookeeper()) {
NestedZookeeperServers.getInstance().startServerIfNotStarted(zkConfig.getNestedPort(), zkConfig.getNestedDataDir());
}
Builder builder = CuratorFrameworkFactory.builder().connectString(zkConfig.getServerLists()).retryPolicy(new ExponentialBackoffRetry(zkConfig.getBaseSleepTimeMilliseconds(), zkConfig.getMaxRetries(), zkConfig.getMaxSleepTimeMilliseconds())).namespace(zkConfig.getNamespace());
if (0 != zkConfig.getSessionTimeoutMilliseconds()) {
sessionTimeout = zkConfig.getSessionTimeoutMilliseconds();
} else {
sessionTimeout = calculateSessionTimeout();
}
builder.sessionTimeoutMs(sessionTimeout);
int connectionTimeout;
if (0 != zkConfig.getConnectionTimeoutMilliseconds()) {
connectionTimeout = zkConfig.getConnectionTimeoutMilliseconds();
} else {
connectionTimeout = calculateConnectionTimeout();
}
builder.connectionTimeoutMs(connectionTimeout);
if (!Strings.isNullOrEmpty(zkConfig.getDigest())) {
builder.authorization("digest", zkConfig.getDigest().getBytes(Charset.forName(Constant.CHARSET_UTF8))).aclProvider(new ACLProvider() {
@Override
public List<ACL> getDefaultAcl() {
return ZooDefs.Ids.CREATOR_ALL_ACL;
}
@Override
public List<ACL> getAclForPath(final String path) {
return ZooDefs.Ids.CREATOR_ALL_ACL;
}
});
}
LogUtils.info(log, LogEvents.ExecutorEvent.COMMON, "Saturn job: zookeeper registry center init, server lists is: {}, connection_timeout: {}, session_timeout: {}, retry_times: {}", zkConfig.getServerLists(), connectionTimeout, sessionTimeout, zkConfig.getMaxRetries());
return builder.build();
}
use of org.apache.curator.retry.ExponentialBackoffRetry in project Saturn by vipshop.
the class ZookeeperRegistryCenterTest method testZkClientConfig.
@Test
public void testZkClientConfig() throws Exception {
// default settings
CuratorFramework client = initZk("127.0.0.1:" + PORT, "ut-ns");
assertEquals(20000L, client.getZookeeperClient().getConnectionTimeoutMs());
assertEquals(20000L, client.getZookeeperClient().getZooKeeper().getSessionTimeout());
ExponentialBackoffRetry retryPolicy = (ExponentialBackoffRetry) client.getZookeeperClient().getRetryPolicy();
assertEquals(3, retryPolicy.getN());
// set VIP_SATURN_ZK_CLIENT_CONNECTION_TIMEOUT = true
System.setProperty("VIP_SATURN_USE_UNSTABLE_NETWORK_SETTING", "true");
SystemEnvProperties.loadProperties();
client = initZk("127.0.0.1:" + PORT, "ut-ns");
assertEquals(40000L, client.getZookeeperClient().getConnectionTimeoutMs());
assertEquals(40000L, client.getZookeeperClient().getZooKeeper().getSessionTimeout());
retryPolicy = (ExponentialBackoffRetry) client.getZookeeperClient().getRetryPolicy();
assertEquals(9, retryPolicy.getN());
}
use of org.apache.curator.retry.ExponentialBackoffRetry in project Saturn by vipshop.
the class CuratorRepositoryImpl method connect.
@Override
public CuratorFramework connect(final String connectString, final String namespace, final String digest) {
Builder builder = CuratorFrameworkFactory.builder().connectString(connectString).sessionTimeoutMs(SESSION_TIMEOUT).connectionTimeoutMs(CONNECTION_TIMEOUT).retryPolicy(new ExponentialBackoffRetry(1000, 3, 3000));
if (namespace != null) {
builder.namespace(namespace);
}
if (!Strings.isNullOrEmpty(digest)) {
builder.authorization("digest", digest.getBytes(Charset.forName("UTF-8"))).aclProvider(new ACLProvider() {
@Override
public List<ACL> getDefaultAcl() {
return ZooDefs.Ids.CREATOR_ALL_ACL;
}
@Override
public List<ACL> getAclForPath(final String path) {
return ZooDefs.Ids.CREATOR_ALL_ACL;
}
});
}
CuratorFramework client = builder.build();
client.start();
boolean established = false;
try {
established = client.blockUntilConnected(WAITING_SECONDS, TimeUnit.SECONDS);
} catch (final InterruptedException ex) {
Thread.currentThread().interrupt();
}
if (established) {
return client;
}
CloseableUtils.closeQuietly(client);
return null;
}
use of org.apache.curator.retry.ExponentialBackoffRetry in project Saturn by vipshop.
the class DemoJavaJob method main.
/**
* @param args
* @throws Exception
*/
public static void main(String[] args) throws Exception {
RetryPolicy retryPolicy = new ExponentialBackoffRetry(1000, 3);
CuratorFramework client = CuratorFrameworkFactory.builder().connectString("localhost:2181").namespace("mydomain").sessionTimeoutMs(10000).retryPolicy(retryPolicy).build();
client.start();
addJavaJob(client, "demoJavaJob");
System.out.println("done add a java-job.");
}
Aggregations