Search in sources :

Example 1 with ServiceProvider

use of org.apache.curator.x.discovery.ServiceProvider in project xian by happyyangyuan.

the class DiscoveryExample method main.

public static void main(String[] args) throws Exception {
    // This method is scaffolding to get the example up and running
    TestingServer server = new TestingServer();
    CuratorFramework client = null;
    ServiceDiscovery<InstanceDetails> serviceDiscovery = null;
    Map<String, ServiceProvider<InstanceDetails>> providers = Maps.newHashMap();
    try {
        client = CuratorFrameworkFactory.newClient(server.getConnectString(), 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);
        CloseableUtils.closeQuietly(server);
    }
}
Also used : TestingServer(org.apache.curator.test.TestingServer) CuratorFramework(org.apache.curator.framework.CuratorFramework) JsonInstanceSerializer(org.apache.curator.x.discovery.details.JsonInstanceSerializer) ExponentialBackoffRetry(org.apache.curator.retry.ExponentialBackoffRetry) ServiceProvider(org.apache.curator.x.discovery.ServiceProvider)

Example 2 with ServiceProvider

use of org.apache.curator.x.discovery.ServiceProvider 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);
    }
}
Also used : CuratorFramework(org.apache.curator.framework.CuratorFramework) JsonInstanceSerializer(org.apache.curator.x.discovery.details.JsonInstanceSerializer) ExponentialBackoffRetry(org.apache.curator.retry.ExponentialBackoffRetry) ServiceProvider(org.apache.curator.x.discovery.ServiceProvider)

Aggregations

CuratorFramework (org.apache.curator.framework.CuratorFramework)2 ExponentialBackoffRetry (org.apache.curator.retry.ExponentialBackoffRetry)2 ServiceProvider (org.apache.curator.x.discovery.ServiceProvider)2 JsonInstanceSerializer (org.apache.curator.x.discovery.details.JsonInstanceSerializer)2 TestingServer (org.apache.curator.test.TestingServer)1