use of org.apache.flink.shaded.curator5.org.apache.curator.retry.ExponentialBackoffRetry in project BRFS by zhangnianli.
the class TestService method main.
public static void main(String[] args) throws Exception {
RetryPolicy retryPolicy = new ExponentialBackoffRetry(1000, 3);
CuratorFramework client = CuratorFrameworkFactory.newClient("192.168.101.86:2181", 3000, 3000, retryPolicy);
client.start();
client.blockUntilConnected();
ServiceManager sm = new DefaultServiceManager(client.usingNamespace("test"));
sm.start();
Service s = new Service();
s.setServiceGroup("group");
s.setServiceId("ser_" + ID);
s.setHost("local");
sm.registerService(s);
Service tmp = sm.getServiceById(s.getServiceGroup(), s.getServiceId());
System.out.println(tmp);
sm.addServiceStateListener("group", new ServiceStateListener() {
@Override
public void serviceRemoved(Service service) {
System.out.println("remove--" + service.getServiceId());
}
@Override
public void serviceAdded(Service service) {
System.out.println("add--" + service.getServiceId());
}
});
System.out.println(sm.getServiceById(s.getServiceGroup(), s.getServiceId()));
}
use of org.apache.flink.shaded.curator5.org.apache.curator.retry.ExponentialBackoffRetry in project BRFS by zhangnianli.
the class DiscoveryExample method main.
public static void main(String[] args) throws Exception {
// This method is scaffolding to get the example up and running
CuratorFramework client = null;
ServiceDiscovery<InstanceDetails> serviceDiscovery = null;
Map<String, ServiceProvider<InstanceDetails>> providers = Maps.newHashMap();
try {
client = CuratorFrameworkFactory.newClient("192.168.101.86:2181", new ExponentialBackoffRetry(1000, 3));
client.start();
JsonInstanceSerializer<InstanceDetails> serializer = new JsonInstanceSerializer<InstanceDetails>(InstanceDetails.class);
serviceDiscovery = ServiceDiscoveryBuilder.builder(InstanceDetails.class).client(client).basePath(PATH).serializer(serializer).build();
serviceDiscovery.start();
processCommands(serviceDiscovery, providers, client);
} finally {
for (ServiceProvider<InstanceDetails> cache : providers.values()) {
CloseableUtils.closeQuietly(cache);
}
CloseableUtils.closeQuietly(serviceDiscovery);
CloseableUtils.closeQuietly(client);
}
}
use of org.apache.flink.shaded.curator5.org.apache.curator.retry.ExponentialBackoffRetry in project BRFS by zhangnianli.
the class TestServiceManager method main.
public static void main(String[] args) throws Exception {
RetryPolicy retryPolicy = new ExponentialBackoffRetry(1000, 3);
CuratorFramework client = CuratorFrameworkFactory.newClient(zk_address, 5 * 1000, 30 * 1000, retryPolicy);
client.start();
client.blockUntilConnected();
ServiceManager sm = new DefaultServiceManager(client.usingNamespace("test_c"));
sm.start();
sm.addServiceStateListener("ss_g", new ServiceStateListener() {
@Override
public void serviceRemoved(Service service) {
// TODO Auto-generated method stub
}
@Override
public void serviceAdded(Service service) {
System.out.println("##########################################before add " + service);
}
});
sm.registerService(new Service("ss_1", "ss_g", "localhost", 999));
Thread.sleep(1000);
sm.addServiceStateListener("ss_g", new ServiceStateListener() {
@Override
public void serviceRemoved(Service service) {
// TODO Auto-generated method stub
}
@Override
public void serviceAdded(Service service) {
System.out.println("##########################################after add " + service);
}
});
sm.addServiceStateListener("ss_g", new ServiceStateListener() {
@Override
public void serviceRemoved(Service service) {
// TODO Auto-generated method stub
}
@Override
public void serviceAdded(Service service) {
System.out.println("##########################################after_2 add " + service);
}
});
sm.registerService(new Service("ss_2", "ss_g", "localhost", 1222));
synchronized (sm) {
sm.wait();
}
}
use of org.apache.flink.shaded.curator5.org.apache.curator.retry.ExponentialBackoffRetry in project incubator-dubbo-ops by apache.
the class ConfigCenterTest method setup.
@Before
public void setup() throws Exception {
int zkServerPort = NetUtils.getAvailablePort();
zkAddress = "zookeeper://127.0.0.1:" + zkServerPort;
zkServer = new TestingServer(zkServerPort, true);
zkClient = CuratorFrameworkFactory.builder().connectString(zkServer.getConnectString()).retryPolicy(new ExponentialBackoffRetry(1000, 3)).build();
zkClient.start();
}
use of org.apache.flink.shaded.curator5.org.apache.curator.retry.ExponentialBackoffRetry in project incubator-gobblin by apache.
the class ZookeeperBasedJobLock method initializeCuratorFramework.
private static synchronized void initializeCuratorFramework(Properties properties) {
if (curatorFrameworkShutdownHook == null) {
curatorFrameworkShutdownHook = new CuratorFrameworkShutdownHook();
Runtime.getRuntime().addShutdownHook(curatorFrameworkShutdownHook);
}
if (curatorFramework == null) {
CuratorFramework newCuratorFramework = CuratorFrameworkFactory.builder().connectString(properties.getProperty(CONNECTION_STRING, CONNECTION_STRING_DEFAULT)).connectionTimeoutMs(getMilliseconds(properties, CONNECTION_TIMEOUT_SECONDS, CONNECTION_TIMEOUT_SECONDS_DEFAULT)).sessionTimeoutMs(getMilliseconds(properties, SESSION_TIMEOUT_SECONDS, SESSION_TIMEOUT_SECONDS_DEFAULT)).retryPolicy(new ExponentialBackoffRetry(getMilliseconds(properties, RETRY_BACKOFF_SECONDS, RETRY_BACKOFF_SECONDS_DEFAULT), getInt(properties, MAX_RETRY_COUNT, MAX_RETRY_COUNT_DEFAULT))).build();
newCuratorFramework.getConnectionStateListenable().addListener(new ConnectionStateListener() {
@Override
public void stateChanged(CuratorFramework curatorFramework, ConnectionState connectionState) {
switch(connectionState) {
case LOST:
log.warn("Lost connection with zookeeper");
for (Map.Entry<String, JobLockEventListener> lockEventListener : lockEventListeners.entrySet()) {
log.warn("Informing job {} that lock was lost", lockEventListener.getKey());
lockEventListener.getValue().onLost();
}
break;
case SUSPENDED:
log.warn("Suspended connection with zookeeper");
for (Map.Entry<String, JobLockEventListener> lockEventListener : lockEventListeners.entrySet()) {
log.warn("Informing job {} that lock was suspended", lockEventListener.getKey());
lockEventListener.getValue().onLost();
}
break;
case CONNECTED:
log.info("Connected with zookeeper");
break;
case RECONNECTED:
log.warn("Regained connection with zookeeper");
break;
case READ_ONLY:
log.warn("Zookeeper connection went into read-only mode");
break;
}
}
});
newCuratorFramework.start();
try {
if (!newCuratorFramework.blockUntilConnected(getInt(properties, CONNECTION_TIMEOUT_SECONDS, CONNECTION_TIMEOUT_SECONDS_DEFAULT), TimeUnit.SECONDS)) {
throw new RuntimeException("Time out while waiting to connect to zookeeper");
}
} catch (InterruptedException e) {
throw new RuntimeException("Interrupted while waiting to connect to zookeeper");
}
curatorFramework = newCuratorFramework;
}
}
Aggregations