org.apache.curator.x.discovery.details.ServiceDiscoveryImpl Java Examples
The following examples show how to use
org.apache.curator.x.discovery.details.ServiceDiscoveryImpl.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: CuratorServiceDiscoveryCompatibilityTest.java From armeria with Apache License 2.0 | 5 votes |
@Test void registeredInstancesAreSameWhenUsingServiceDiscoveryImplAndUpdatingListener() throws Throwable { final Endpoint endpoint = ZooKeeperTestUtil.sampleEndpoints(1).get(0); final CuratorFramework client = CuratorFrameworkFactory.builder() .connectString(zkInstance.connectString()) .retryPolicy(new ExponentialBackoffRetry(1000, 3)) .build(); client.start(); final JsonInstanceSerializer<Void> serializer = new JsonInstanceSerializer<>(Void.class); final ServiceInstance<Void> registered = serviceInstance(endpoint); final ServiceDiscoveryImpl<Void> serviceDiscovery = new ServiceDiscoveryImpl<>(client, Z_NODE, serializer, registered, false); serviceDiscovery.start(); assertInstance(registered); serviceDiscovery.close(); await().untilAsserted(() -> zkInstance.assertNotExists(Z_NODE + "/foo/bar")); final ZooKeeperRegistrationSpec registrationSpec = ZooKeeperRegistrationSpec.builderForCurator("foo") .serviceId("bar") .serviceAddress("foo.com") .port(endpoint.port()) .uriSpec(CURATOR_X_URI_SPEC) .build(); final ZooKeeperUpdatingListener listener = ZooKeeperUpdatingListener.builder(zkInstance.connectString(), Z_NODE, registrationSpec).build(); final Server server = Server.builder() .http(endpoint.port()) .service("/", (ctx, req) -> HttpResponse.of(200)) .build(); server.addListener(listener); server.start().join(); assertInstance(registered); server.stop().join(); client.close(); }
Example #2
Source File: ServiceDiscoveryBuilder.java From curator with Apache License 2.0 | 5 votes |
/** * Build a new service discovery with the currently set values. If not set, the builder will be * defaulted with a {@link JsonInstanceSerializer}. * * @return new service discovery */ public ServiceDiscovery<T> build() { if ( serializer == null ) { serializer(new JsonInstanceSerializer<T>(payloadClass)); } return new ServiceDiscoveryImpl<T>(client, basePath, serializer, thisInstance, watchInstances); }