public void releaseServiceObject(Object object) { ServiceDiscovery.releaseServiceObject(serviceDiscovery, object); }
/** * Release the service object retrieved using <code>get</code> methods from the service type interface. * It searches for the reference associated with the given object and release it. * @param discovery the service discovery * @param svcObject the service object */ public static void releaseServiceObject(io.vertx.rxjava.servicediscovery.ServiceDiscovery discovery, Object svcObject) { io.vertx.servicediscovery.ServiceDiscovery.releaseServiceObject(discovery.getDelegate(), svcObject); }
public static void releaseServiceObject(io.vertx.servicediscovery.ServiceDiscovery j_receiver, io.vertx.servicediscovery.ServiceDiscovery discovery, java.lang.Object svcObject) { io.vertx.servicediscovery.ServiceDiscovery.releaseServiceObject(discovery, io.vertx.core.impl.ConversionHelper.toObject(svcObject)); } }
/** * Release the service object retrieved using <code>get</code> methods from the service type interface. * It searches for the reference associated with the given object and release it. * @param discovery the service discovery * @param svcObject the service object */ public static void releaseServiceObject(io.vertx.rxjava.servicediscovery.ServiceDiscovery discovery, Object svcObject) { io.vertx.servicediscovery.ServiceDiscovery.releaseServiceObject(discovery.getDelegate(), svcObject); }
return Functional.allOfFutures(futures) .map(r -> { ServiceDiscovery.releaseServiceObject(discovery, client); return r; });
future.fail(ar.cause()); ServiceDiscovery.releaseServiceObject(discovery, client); // Release the resources. }); return future;
cbFuture.complete(); ServiceDiscovery.releaseServiceObject(discovery, client); }); });
@Test public void testUsingGetMethod() { HelloService svc = new HelloServiceImpl("stuff"); ProxyHelper.registerService(HelloService.class, vertx, svc, "address"); Record record = EventBusService.createRecord("Hello", "address", HelloService.class); discovery.publish(record, (r) -> { }); await().until(() -> record.getRegistration() != null); AtomicReference<HelloService> found = new AtomicReference<>(); EventBusService.getProxy(discovery, HelloService.class, ar -> { found.set(ar.result()); }); await().until(() -> found.get() != null); Assertions.assertThat(discovery.bindings()).hasSize(1); HelloService hello = found.get(); AtomicReference<String> result = new AtomicReference<>(); hello.hello(name, ar -> result.set(ar.result())); await().untilAtomic(result, not(nullValue())); ServiceDiscovery.releaseServiceObject(discovery, found.get()); Assertions.assertThat(discovery.bindings()).hasSize(0); }
@Test public void testUsingGetMethod() { HelloService svc = new HelloServiceImpl("stuff"); ProxyHelper.registerService(HelloService.class, vertx, svc, "address"); Record record = EventBusService.createRecord("Hello", "address", HelloService.class); discovery.publish(record, (r) -> { }); await().until(() -> record.getRegistration() != null); AtomicReference<HelloService> found = new AtomicReference<>(); EventBusService.getProxy(discovery, HelloService.class, ar -> { found.set(ar.result()); }); await().until(() -> found.get() != null); Assertions.assertThat(discovery.bindings()).hasSize(1); HelloService hello = found.get(); AtomicReference<String> result = new AtomicReference<>(); hello.hello(name, ar -> result.set(ar.result())); await().untilAtomic(result, not(nullValue())); ServiceDiscovery.releaseServiceObject(discovery, found.get()); Assertions.assertThat(discovery.bindings()).hasSize(0); }
@Test public void testPublicationAndConsumptionWithConfigurationAsWebClient(TestContext context) { Async async = context.async(); // Publish the service Record record = HttpEndpoint.createRecord("hello-service", "localhost", 8080, "/foo"); discovery.publish(record, rec -> { Record published = rec.result(); HttpEndpoint.getWebClient(discovery, new JsonObject().put("name", "hello-service"), new JsonObject().put("keepAlive", false), found -> { context.assertTrue(found.succeeded()); context.assertTrue(found.result() != null); WebClient client = found.result(); client.get("/foo").send(ar -> { if (ar.failed()) { context.fail(ar.cause()); } HttpResponse<Buffer> response = ar.result(); context.assertEquals(response.statusCode(), 200); context.assertEquals(response.getHeader("connection"), "close"); context.assertEquals(response.body().toString(), "hello"); ServiceDiscovery.releaseServiceObject(discovery, client); discovery.unpublish(published.getRegistration(), v -> async.complete()); }); }); }); }
@Test public void testPublicationAndConsumptionWithConfigurationAsWebClient(TestContext context) { Async async = context.async(); // Publish the service Record record = HttpEndpoint.createRecord("hello-service", "localhost", 8080, "/foo"); discovery.publish(record, rec -> { Record published = rec.result(); HttpEndpoint.getWebClient(discovery, new JsonObject().put("name", "hello-service"), new JsonObject().put("keepAlive", false), found -> { context.assertTrue(found.succeeded()); context.assertTrue(found.result() != null); WebClient client = found.result(); client.get("/foo").send(ar -> { if (ar.failed()) { context.fail(ar.cause()); } HttpResponse<Buffer> response = ar.result(); context.assertEquals(response.statusCode(), 200); context.assertEquals(response.getHeader("connection"), "close"); context.assertEquals(response.body().toString(), "hello"); ServiceDiscovery.releaseServiceObject(discovery, client); discovery.unpublish(published.getRegistration(), v -> async.complete()); }); }); }); }
@Test public void testPublicationAndConsumptionWithConfiguration(TestContext context) { Async async = context.async(); // Publish the service Record record = HttpEndpoint.createRecord("hello-service", "localhost", 8080, "/foo"); discovery.publish(record, rec -> { Record published = rec.result(); HttpEndpoint.getClient(discovery, new JsonObject().put("name", "hello-service"), new JsonObject().put ("keepAlive", false), found -> { context.assertTrue(found.succeeded()); context.assertTrue(found.result() != null); HttpClient client = found.result(); client.getNow("/foo", response -> { context.assertEquals(response.statusCode(), 200); context.assertEquals(response.getHeader("connection"), "close"); response.bodyHandler(body -> { context.assertEquals(body.toString(), "hello"); ServiceDiscovery.releaseServiceObject(discovery, client); discovery.unpublish(published.getRegistration(), v -> async.complete()); }); }); }); }); }
@Test public void testPublicationAndConsumptionWithConfiguration(TestContext context) { Async async = context.async(); // Publish the service Record record = HttpEndpoint.createRecord("hello-service", "localhost", 8080, "/foo"); discovery.publish(record, rec -> { Record published = rec.result(); HttpEndpoint.getClient(discovery, new JsonObject().put("name", "hello-service"), new JsonObject().put ("keepAlive", false), found -> { context.assertTrue(found.succeeded()); context.assertTrue(found.result() != null); HttpClient client = found.result(); client.getNow("/foo", context.asyncAssertSuccess(response -> { context.assertEquals(response.statusCode(), 200); context.assertEquals(response.getHeader("connection"), "close"); response.bodyHandler(body -> { context.assertEquals(body.toString(), "hello"); ServiceDiscovery.releaseServiceObject(discovery, client); discovery.unpublish(published.getRegistration(), v -> async.complete()); }); })); }); }); }
HttpClient client = ar.result(); result.put("client", client.toString()); ServiceDiscovery.releaseServiceObject(discovery, client); result.put("bindings", getBindings(discovery)); message.reply(result); WebClient client = ar.result(); result.put("client", client.toString()); ServiceDiscovery.releaseServiceObject(discovery, client); result.put("bindings", getBindings(discovery)); message.reply(result); HelloService client = ar.result(); result.put("client", client.toString()); ServiceDiscovery.releaseServiceObject(discovery, client); result.put("bindings", getBindings(discovery)); message.reply(result); JDBCClient client = ar.result(); result.put("client", client.toString()); ServiceDiscovery.releaseServiceObject(discovery, client); result.put("bindings", getBindings(discovery)); message.reply(result); RedisClient client = ar.result(); result.put("client", client.toString()); ServiceDiscovery.releaseServiceObject(discovery, client); result.put("bindings", getBindings(discovery)); message.reply(result);
private void authUaaHandler(RoutingContext context) { if (context.user() != null) { JsonObject principal = context.user().principal(); String username = null; // TODO: Only for demo. Complete this in next version. // String username = KeycloakHelper.preferredUsername(principal); if (username == null) { context.response() .putHeader("content-type", "application/json") .end(new Account().setId("TEST666").setUsername("Eric").toString()); // TODO: no username should be an error } else { Future<AccountService> future = Future.future(); EventBusService.getProxy(discovery, AccountService.class, future.completer()); future.compose(accountService -> { Future<Account> accountFuture = Future.future(); accountService.retrieveByUsername(username, accountFuture.completer()); return accountFuture.map(a -> { ServiceDiscovery.releaseServiceObject(discovery, accountService); return a; }); }) .setHandler(resultHandlerNonEmpty(context)); // if user does not exist, should return 404 } } else { context.fail(401); } }
HttpClient client = ar.result(); result.put("client", client.toString()); ServiceDiscovery.releaseServiceObject(discovery, client); result.put("bindings", getBindings(discovery)); message.reply(result); WebClient client = ar.result(); result.put("client", client.toString()); ServiceDiscovery.releaseServiceObject(discovery, client); result.put("bindings", getBindings(discovery)); message.reply(result); HelloService client = ar.result(); result.put("client", client.toString()); ServiceDiscovery.releaseServiceObject(discovery, client); result.put("bindings", getBindings(discovery)); message.reply(result); JDBCClient client = ar.result(); result.put("client", client.toString()); ServiceDiscovery.releaseServiceObject(discovery, client); result.put("bindings", getBindings(discovery)); message.reply(result); RedisClient client = ar.result(); result.put("client", client.toString()); ServiceDiscovery.releaseServiceObject(discovery, client); result.put("bindings", getBindings(discovery)); message.reply(result);