use of org.apache.curator.retry.RetryNTimes in project apex-malhar by apache.
the class ZKAssistedDiscovery method setup.
@Override
public void setup(com.datatorrent.api.Context context) {
ObjectMapper om = new ObjectMapper();
instanceSerializerFactory = new InstanceSerializerFactory(om.reader(), om.writer());
curatorFramework = CuratorFrameworkFactory.builder().connectionTimeoutMs(connectionTimeoutMillis).retryPolicy(new RetryNTimes(connectionRetryCount, conntectionRetrySleepMillis)).connectString(connectionString).build();
curatorFramework.start();
discovery = getDiscovery(curatorFramework);
try {
discovery.start();
} catch (Exception ex) {
Throwables.propagate(ex);
}
}
use of org.apache.curator.retry.RetryNTimes in project paascloud-master by paascloud.
the class IncrementIdGenerator method nextId.
/**
* Next id long.
*
* @return the long
*/
@Override
public Long nextId() {
String app = this.registerDto.getApp();
String host = this.registerDto.getHost();
CoordinatorRegistryCenter regCenter = this.registerDto.getCoordinatorRegistryCenter();
String path = GlobalConstant.ZK_REGISTRY_ID_ROOT_PATH + GlobalConstant.Symbol.SLASH + app + GlobalConstant.Symbol.SLASH + host;
if (regCenter.isExisted(path)) {
// 如果已经有该节点,表示已经为当前的host上部署的该app分配的编号(应对某个服务重启之后编号不变的问题),直接获取该id,而无需生成
return Long.valueOf(regCenter.getDirectly(GlobalConstant.ZK_REGISTRY_ID_ROOT_PATH + GlobalConstant.Symbol.SLASH + app + GlobalConstant.Symbol.SLASH + host));
} else {
// 节点不存在,那么需要生成id,利用zk节点的版本号每写一次就自增的机制来实现
regCenter.increment(GlobalConstant.ZK_REGISTRY_SEQ, new RetryNTimes(2000, 3));
// 生成id
Integer id = regCenter.getAtomicValue(GlobalConstant.ZK_REGISTRY_SEQ, new RetryNTimes(2000, 3)).postValue();
// 将数据写入节点
regCenter.persist(path);
regCenter.persist(path, String.valueOf(id));
return Long.valueOf(id);
}
}
use of org.apache.curator.retry.RetryNTimes in project tutorials by eugenp.
the class BaseTest method newClient.
protected CuratorFramework newClient() {
int sleepMsBetweenRetries = 100;
int maxRetries = 3;
RetryPolicy retryPolicy = new RetryNTimes(maxRetries, sleepMsBetweenRetries);
return CuratorFrameworkFactory.newClient("127.0.0.1:2181", retryPolicy);
}
use of org.apache.curator.retry.RetryNTimes in project tutorials by eugenp.
the class ConnectionManagementManualTest method givenRunningZookeeper_whenOpenConnection_thenClientIsOpened.
@Test
public void givenRunningZookeeper_whenOpenConnection_thenClientIsOpened() throws Exception {
int sleepMsBetweenRetries = 100;
int maxRetries = 3;
RetryPolicy retryPolicy = new RetryNTimes(maxRetries, sleepMsBetweenRetries);
try (CuratorFramework client = CuratorFrameworkFactory.newClient("127.0.0.1:2181", retryPolicy)) {
client.start();
assertThat(client.checkExists().forPath("/")).isNotNull();
}
}
use of org.apache.curator.retry.RetryNTimes in project tutorials by eugenp.
the class ConnectionManagementManualTest method givenRunningZookeeper_whenOpenConnectionUsingAsyncBlocking_thenClientIsOpened.
@Test
public void givenRunningZookeeper_whenOpenConnectionUsingAsyncBlocking_thenClientIsOpened() throws InterruptedException {
int sleepMsBetweenRetries = 100;
int maxRetries = 3;
RetryPolicy retryPolicy = new RetryNTimes(maxRetries, sleepMsBetweenRetries);
try (CuratorFramework client = CuratorFrameworkFactory.newClient("127.0.0.1:2181", retryPolicy)) {
client.start();
AsyncCuratorFramework async = AsyncCuratorFramework.wrap(client);
AtomicBoolean exists = new AtomicBoolean(false);
async.checkExists().forPath("/").thenAccept(s -> exists.set(s != null));
await().until(() -> assertThat(exists.get()).isTrue());
}
}
Aggregations