public static <X>java.lang.Object getAs(io.vertx.servicediscovery.ServiceReference j_receiver, java.lang.Class<java.lang.Object> x) { return io.vertx.core.impl.ConversionHelper.fromObject(j_receiver.getAs(x)); } public static <X>java.lang.Object cachedAs(io.vertx.servicediscovery.ServiceReference j_receiver, java.lang.Class<java.lang.Object> x) {
/** * Convenient method that looks for a HTTP endpoint and provides the configured {@linkWebClient}. The async result * is marked as failed is there are no matching services, or if the lookup fails. * * @param discovery The service discovery instance * @param filter The filter, optional * @param resultHandler The result handler */ static void getWebClient(ServiceDiscovery discovery, JsonObject filter, Handler<AsyncResult<WebClient>> resultHandler) { discovery.getRecord(filter, ar -> { if (ar.failed() || ar.result() == null) { resultHandler.handle(Future.failedFuture("No matching record")); } else { resultHandler.handle(Future.succeededFuture(discovery.<HttpClient>getReference(ar.result()).getAs(WebClient.class))); } }); }
/** * Convenient method that looks for a HTTP endpoint and provides the configured {@link WebClient}. The async result * is marked as failed is there are no matching services, or if the lookup fails. * * @param discovery The service discovery instance * @param filter The filter * @param resultHandler The result handler */ static void getWebClient(ServiceDiscovery discovery, Function<Record, Boolean> filter, Handler<AsyncResult<WebClient>> resultHandler) { discovery.getRecord(filter, ar -> { if (ar.failed() || ar.result() == null) { resultHandler.handle(Future.failedFuture("No matching record")); } else { resultHandler.handle(Future.succeededFuture(discovery.<HttpClient>getReference(ar.result()).getAs(WebClient.class))); } }); }
/** * Convenient method that looks for a HTTP endpoint and provides the configured {@link WebClient}. The async result * is marked as failed is there are no matching services, or if the lookup fails. * * @param discovery The service discovery instance * @param filter The filter * @param resultHandler The result handler */ static void getWebClient(ServiceDiscovery discovery, Function<Record, Boolean> filter, Handler<AsyncResult<WebClient>> resultHandler) { discovery.getRecord(filter, ar -> { if (ar.failed() || ar.result() == null) { resultHandler.handle(Future.failedFuture("No matching record")); } else { resultHandler.handle(Future.succeededFuture(discovery.<HttpClient>getReference(ar.result()).getAs(WebClient.class))); } }); }
/** * Convenient method that looks for a HTTP endpoint and provides the configured {@linkWebClient}. The async result * is marked as failed is there are no matching services, or if the lookup fails. * * @param discovery The service discovery instance * @param filter The filter, optional * @param resultHandler The result handler */ static void getWebClient(ServiceDiscovery discovery, JsonObject filter, Handler<AsyncResult<WebClient>> resultHandler) { discovery.getRecord(filter, ar -> { if (ar.failed() || ar.result() == null) { resultHandler.handle(Future.failedFuture("No matching record")); } else { resultHandler.handle(Future.succeededFuture(discovery.<HttpClient>getReference(ar.result()).getAs(WebClient.class))); } }); }
/** * Convenient method that looks for a HTTP endpoint and provides the configured {@link WebClient}. The async result * is marked as failed is there are no matching services, or if the lookup fails. This method accepts a * configuration for the HTTP client * * @param discovery The service discovery instance * @param filter The filter, optional * @param conf the configuration of the client * @param resultHandler The result handler */ static void getWebClient(ServiceDiscovery discovery, JsonObject filter, JsonObject conf, Handler<AsyncResult<WebClient>> resultHandler) { discovery.getRecord(filter, ar -> { if (ar.failed() || ar.result() == null) { resultHandler.handle(Future.failedFuture("No matching record")); } else { resultHandler.handle(Future.succeededFuture(discovery.<HttpClient>getReferenceWithConfiguration(ar.result(), conf) .getAs(WebClient.class))); } }); }
/** * Convenient method that looks for a HTTP endpoint and provides the configured {@link WebClient}. The async result * is marked as failed is there are no matching services, or if the lookup fails. This method accepts a * configuration for the HTTP client. * * @param discovery The service discovery instance * @param filter The filter * @param conf the configuration of the client * @param resultHandler The result handler */ static void getWebClient(ServiceDiscovery discovery, Function<Record, Boolean> filter, JsonObject conf, Handler<AsyncResult<WebClient>> resultHandler) { discovery.getRecord(filter, ar -> { if (ar.failed() || ar.result() == null) { resultHandler.handle(Future.failedFuture("No matching record")); } else { resultHandler.handle(Future.succeededFuture( discovery.<HttpClient>getReferenceWithConfiguration(ar.result(), conf).getAs(WebClient.class))); } }); } }
/** * Convenient method that looks for a HTTP endpoint and provides the configured {@link WebClient}. The async result * is marked as failed is there are no matching services, or if the lookup fails. This method accepts a * configuration for the HTTP client * * @param discovery The service discovery instance * @param filter The filter, optional * @param conf the configuration of the client * @param resultHandler The result handler */ static void getWebClient(ServiceDiscovery discovery, JsonObject filter, JsonObject conf, Handler<AsyncResult<WebClient>> resultHandler) { discovery.getRecord(filter, ar -> { if (ar.failed() || ar.result() == null) { resultHandler.handle(Future.failedFuture("No matching record")); } else { resultHandler.handle(Future.succeededFuture(discovery.<HttpClient>getReferenceWithConfiguration(ar.result(), conf) .getAs(WebClient.class))); } }); }
/** * Convenient method that looks for a HTTP endpoint and provides the configured {@link WebClient}. The async result * is marked as failed is there are no matching services, or if the lookup fails. This method accepts a * configuration for the HTTP client. * * @param discovery The service discovery instance * @param filter The filter * @param conf the configuration of the client * @param resultHandler The result handler */ static void getWebClient(ServiceDiscovery discovery, Function<Record, Boolean> filter, JsonObject conf, Handler<AsyncResult<WebClient>> resultHandler) { discovery.getRecord(filter, ar -> { if (ar.failed() || ar.result() == null) { resultHandler.handle(Future.failedFuture("No matching record")); } else { resultHandler.handle(Future.succeededFuture( discovery.<HttpClient>getReferenceWithConfiguration(ar.result(), conf).getAs(WebClient.class))); } }); } }
} else { ServiceReference service = discovery.getReference(ar.result()); resultHandler.handle(Future.succeededFuture(service.getAs(clientClass)));
} else { ServiceReference service = discovery.getReference(ar.result()); resultHandler.handle(Future.succeededFuture(service.getAs(clientClass)));
} else { ServiceReference service = discovery.getReference(ar.result()); resultHandler.handle(Future.succeededFuture(service.getAs(clientClass)));
} else { ServiceReference service = discovery.getReference(ar.result()); resultHandler.handle(Future.succeededFuture(service.getAs(clientClass)));
/** * Gets the object to access the service. It can be a proxy, a client or whatever object. The type depends on the * service type and the server itself. This method wraps the service object into the desired type. * @param x the type of object * @return the object to access the service wrapped to the given type */ public <X> X getAs(Class<X> x) { X ret = (X)io.vertx.lang.rx.TypeArg.of(x).wrap(delegate.getAs(io.vertx.lang.rxjava.Helper.unwrap(x))); return ret; }
/** * Gets the object to access the service. It can be a proxy, a client or whatever object. The type depends on the * service type and the server itself. This method wraps the service object into the desired type. * @param x the type of object * @return the object to access the service wrapped to the given type */ public <X> X getAs(Class<X> x) { X ret = (X)io.vertx.lang.rx.TypeArg.of(x).wrap(delegate.getAs(io.vertx.lang.rxjava.Helper.unwrap(x))); return ret; }
final String uri = InOut.normalizeUri(context); final WebClient client = reference.getAs(WebClient.class); final RequestOptions options = InOut.getOptions(record, uri);
@Test public void testAutoCloseable(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(); discovery.getRecord(new JsonObject().put("name", "hello-service"), found -> { context.assertTrue(found.succeeded()); context.assertTrue(found.result() != null); Record match = found.result(); try (ServiceReference reference = discovery.getReference(match)) { context.assertEquals(reference.record().getLocation().getString("endpoint"), "http://localhost:8080/foo"); context.assertFalse(reference.record().getLocation().getBoolean("ssl")); WebClient client = reference.getAs(WebClient.class); WebClient client2 = reference.cachedAs(WebClient.class); context.assertTrue(client == client2); } catch (Exception e) { context.fail(e); } discovery.unpublish(published.getRegistration(), v -> async.complete()); }); }); }
@Test public void testAutoCloseable(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(); discovery.getRecord(new JsonObject().put("name", "hello-service"), found -> { context.assertTrue(found.succeeded()); context.assertTrue(found.result() != null); Record match = found.result(); try (ServiceReference reference = discovery.getReference(match)) { context.assertEquals(reference.record().getLocation().getString("endpoint"), "http://localhost:8080/foo"); context.assertFalse(reference.record().getLocation().getBoolean("ssl")); WebClient client = reference.getAs(WebClient.class); WebClient client2 = reference.cachedAs(WebClient.class); context.assertTrue(client == client2); } catch (Exception e) { context.fail(e); } discovery.unpublish(published.getRegistration(), v -> async.complete()); }); }); }
context.assertEquals(reference.record().getLocation().getString("endpoint"), "http://localhost:8080/foo"); context.assertFalse(reference.record().getLocation().getBoolean("ssl")); WebClient client = reference.getAs(WebClient.class); WebClient client2 = reference.cachedAs(WebClient.class); context.assertTrue(client == client2);
context.assertEquals(reference.record().getLocation().getString("endpoint"), "http://localhost:8080/foo"); context.assertFalse(reference.record().getLocation().getBoolean("ssl")); WebClient client = reference.getAs(WebClient.class); WebClient client2 = reference.cachedAs(WebClient.class); context.assertTrue(client == client2);