use of org.apache.curator.retry.ExponentialBackoffRetry in project helios by spotify.
the class DeploymentGroupTest method setUp.
@Before
public void setUp() throws Exception {
MockitoAnnotations.initMocks(this);
zkServer = new TestingServer(true);
final CuratorFramework curatorFramework = CuratorFrameworkFactory.builder().connectString(zkServer.getConnectString()).retryPolicy(new ExponentialBackoffRetry(100, 3)).build();
client = new DefaultZooKeeperClient(curatorFramework);
client.start();
}
use of org.apache.curator.retry.ExponentialBackoffRetry in project exhibitor by soabase.
the class Exhibitor method getLocalConnection.
/**
* Return a connection ot the ZK instance (creating it if needed)
*
* @return connection
* @throws IOException errors
*/
public synchronized CuratorFramework getLocalConnection() throws IOException {
if (localConnection == null) {
CuratorFrameworkFactory.Builder builder = CuratorFrameworkFactory.builder().connectString("localhost:" + configManager.getConfig().getInt(IntConfigs.CLIENT_PORT)).sessionTimeoutMs(arguments.connectionTimeOutMs * 10).connectionTimeoutMs(arguments.connectionTimeOutMs).retryPolicy(new ExponentialBackoffRetry(1000, 3));
if (arguments.aclProvider != null) {
builder = builder.aclProvider(arguments.aclProvider);
}
localConnection = builder.build();
localConnection.start();
}
return localConnection;
}
use of org.apache.curator.retry.ExponentialBackoffRetry in project dubbo by alibaba.
the class ZKTools method testTreeCache.
public static void testTreeCache() throws Exception {
CuratorFramework client = CuratorFrameworkFactory.newClient("127.0.0.1:2181", 60 * 1000, 60 * 1000, new ExponentialBackoffRetry(1000, 3));
client.start();
CountDownLatch latch = new CountDownLatch(1);
TreeCache treeCache = TreeCache.newBuilder(client, "/dubbo/config").setCacheData(true).build();
treeCache.start();
treeCache.getListenable().addListener(new TreeCacheListener() {
@Override
public void childEvent(CuratorFramework client, TreeCacheEvent event) throws Exception {
TreeCacheEvent.Type type = event.getType();
ChildData data = event.getData();
if (type == TreeCacheEvent.Type.INITIALIZED) {
latch.countDown();
}
System.out.println(data.getPath() + "\n");
if (data.getPath().split("/").length == 5) {
byte[] value = data.getData();
String stringValue = new String(value, StandardCharsets.UTF_8);
// fire event to all listeners
Map<String, Object> added = null;
Map<String, Object> changed = null;
Map<String, Object> deleted = null;
switch(type) {
case NODE_ADDED:
added = new HashMap<>(1);
added.put(pathToKey(data.getPath()), stringValue);
added.forEach((k, v) -> System.out.println(k + " " + v));
break;
case NODE_REMOVED:
deleted = new HashMap<>(1);
deleted.put(pathToKey(data.getPath()), stringValue);
deleted.forEach((k, v) -> System.out.println(k + " " + v));
break;
case NODE_UPDATED:
changed = new HashMap<>(1);
changed.put(pathToKey(data.getPath()), stringValue);
changed.forEach((k, v) -> System.out.println(k + " " + v));
}
}
}
});
latch.await();
/* Map<String, ChildData> dataMap = treeCache.getCurrentChildren("/dubbo/config");
dataMap.forEach((k, v) -> {
System.out.println(k);
treeCache.getCurrentChildren("/dubbo/config/" + k).forEach((ck, cv) -> {
System.out.println(ck);
});
});*/
}
use of org.apache.curator.retry.ExponentialBackoffRetry in project dubbo by alibaba.
the class ZKTools method main.
public static void main(String[] args) throws Exception {
client = CuratorFrameworkFactory.newClient("127.0.0.1:2181", 60 * 1000, 60 * 1000, new ExponentialBackoffRetry(1000, 3));
client.start();
client.getCuratorListenable().addListener(new CuratorListener() {
@Override
public void eventReceived(CuratorFramework client, CuratorEvent event) throws Exception {
System.out.println("event notification: " + event.getPath());
System.out.println(event);
}
}, executor);
testMigrationRule();
// tesConditionRule();
// testStartupConfig();
// testProviderConfig();
// testPathCache();
// testTreeCache();
// testCuratorListener();
// Thread.sleep(100000);
}
use of org.apache.curator.retry.ExponentialBackoffRetry in project dubbo by alibaba.
the class ZookeeperDynamicConfigurationTest method setUp.
@BeforeEach
public void setUp() throws Exception {
zkServer = new TestingServer(zkServerPort, true);
client = CuratorFrameworkFactory.newClient("127.0.0.1:" + zkServerPort, 60 * 1000, 60 * 1000, new ExponentialBackoffRetry(1000, 3));
client.start();
try {
setData("/dubbo/config/dubbo/dubbo.properties", "The content from dubbo.properties");
setData("/dubbo/config/appname", "The content from higher level node");
setData("/dubbo/config/dubbo/never.change.DemoService.configurators", "Never change value from configurators");
} catch (Exception e) {
e.printStackTrace();
}
configUrl = URL.valueOf("zookeeper://127.0.0.1:" + zkServerPort);
configuration = ExtensionLoader.getExtensionLoader(DynamicConfigurationFactory.class).getExtension(configUrl.getProtocol()).getDynamicConfiguration(configUrl);
}
Aggregations