Search in sources :

Example 71 with ExponentialBackoffRetry

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();
}
Also used : TestingServer(org.apache.curator.test.TestingServer) CuratorFramework(org.apache.curator.framework.CuratorFramework) ExponentialBackoffRetry(org.apache.curator.retry.ExponentialBackoffRetry) DefaultZooKeeperClient(com.spotify.helios.servicescommon.coordination.DefaultZooKeeperClient) Before(org.junit.Before)

Example 72 with ExponentialBackoffRetry

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;
}
Also used : CuratorFrameworkFactory(org.apache.curator.framework.CuratorFrameworkFactory) ExponentialBackoffRetry(org.apache.curator.retry.ExponentialBackoffRetry)

Example 73 with ExponentialBackoffRetry

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);
            });
        });*/
}
Also used : TreeCacheListener(org.apache.curator.framework.recipes.cache.TreeCacheListener) CuratorFrameworkFactory(org.apache.curator.framework.CuratorFrameworkFactory) CuratorListener(org.apache.curator.framework.api.CuratorListener) HashMap(java.util.HashMap) NamedThreadFactory(org.apache.dubbo.common.utils.NamedThreadFactory) StandardCharsets(java.nio.charset.StandardCharsets) Executors(java.util.concurrent.Executors) StringUtils(org.apache.dubbo.common.utils.StringUtils) ChildData(org.apache.curator.framework.recipes.cache.ChildData) CountDownLatch(java.util.concurrent.CountDownLatch) TreeCacheEvent(org.apache.curator.framework.recipes.cache.TreeCacheEvent) List(java.util.List) CuratorFramework(org.apache.curator.framework.CuratorFramework) ExponentialBackoffRetry(org.apache.curator.retry.ExponentialBackoffRetry) Map(java.util.Map) CuratorEvent(org.apache.curator.framework.api.CuratorEvent) PathChildrenCache(org.apache.curator.framework.recipes.cache.PathChildrenCache) TreeCache(org.apache.curator.framework.recipes.cache.TreeCache) ExecutorService(java.util.concurrent.ExecutorService) TreeCache(org.apache.curator.framework.recipes.cache.TreeCache) TreeCacheListener(org.apache.curator.framework.recipes.cache.TreeCacheListener) HashMap(java.util.HashMap) ExponentialBackoffRetry(org.apache.curator.retry.ExponentialBackoffRetry) CountDownLatch(java.util.concurrent.CountDownLatch) CuratorFramework(org.apache.curator.framework.CuratorFramework) ChildData(org.apache.curator.framework.recipes.cache.ChildData) TreeCacheEvent(org.apache.curator.framework.recipes.cache.TreeCacheEvent) HashMap(java.util.HashMap) Map(java.util.Map)

Example 74 with ExponentialBackoffRetry

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);
}
Also used : CuratorFramework(org.apache.curator.framework.CuratorFramework) ExponentialBackoffRetry(org.apache.curator.retry.ExponentialBackoffRetry) CuratorListener(org.apache.curator.framework.api.CuratorListener) CuratorEvent(org.apache.curator.framework.api.CuratorEvent)

Example 75 with ExponentialBackoffRetry

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);
}
Also used : TestingServer(org.apache.curator.test.TestingServer) DynamicConfigurationFactory(org.apache.dubbo.common.config.configcenter.DynamicConfigurationFactory) ExponentialBackoffRetry(org.apache.curator.retry.ExponentialBackoffRetry) BeforeEach(org.junit.jupiter.api.BeforeEach)

Aggregations

ExponentialBackoffRetry (org.apache.curator.retry.ExponentialBackoffRetry)181 CuratorFramework (org.apache.curator.framework.CuratorFramework)107 RetryPolicy (org.apache.curator.RetryPolicy)46 Before (org.junit.Before)26 TestingCluster (org.apache.curator.test.TestingCluster)23 Test (org.testng.annotations.Test)23 IOException (java.io.IOException)18 TestingServer (org.apache.curator.test.TestingServer)18 Timing (org.apache.curator.test.Timing)16 CountDownLatch (java.util.concurrent.CountDownLatch)15 CuratorFrameworkFactory (org.apache.curator.framework.CuratorFrameworkFactory)12 ACLProvider (org.apache.curator.framework.api.ACLProvider)12 Test (org.junit.Test)12 ArrayList (java.util.ArrayList)11 ConnectionState (org.apache.curator.framework.state.ConnectionState)11 ExecutorService (java.util.concurrent.ExecutorService)10 ConnectionStateListener (org.apache.curator.framework.state.ConnectionStateListener)10 TestingServerStarter (io.pravega.test.common.TestingServerStarter)9 KeeperException (org.apache.zookeeper.KeeperException)8 HashMap (java.util.HashMap)7