public static <X>java.lang.Object cachedAs(io.vertx.servicediscovery.ServiceReference j_receiver, java.lang.Class<java.lang.Object> x) { return io.vertx.core.impl.ConversionHelper.fromObject(j_receiver.cachedAs(x)); } public static <T>java.lang.Object cached(io.vertx.servicediscovery.ServiceReference j_receiver) {
/** * Gets the service object if already retrieved. It won't try to acquire the service object if not retrieved yet. * Unlike {@link io.vertx.rxjava.servicediscovery.ServiceReference#cached}, this method return the warpped object to the desired (given) type. * @param x the type of object * @return the object, <code>null</code> if not yet retrieved */ public <X> X cachedAs(Class<X> x) { X ret = (X)io.vertx.lang.rx.TypeArg.of(x).wrap(delegate.cachedAs(io.vertx.lang.rxjava.Helper.unwrap(x))); return ret; }
/** * Gets the service object if already retrieved. It won't try to acquire the service object if not retrieved yet. * Unlike {@link io.vertx.rxjava.servicediscovery.ServiceReference#cached}, this method return the warpped object to the desired (given) type. * @param x the type of object * @return the object, <code>null</code> if not yet retrieved */ public <X> X cachedAs(Class<X> x) { X ret = (X)io.vertx.lang.rx.TypeArg.of(x).wrap(delegate.cachedAs(io.vertx.lang.rxjava.Helper.unwrap(x))); return ret; }
@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.assertFalse(reference.record().getLocation().getBoolean("ssl")); WebClient client = reference.getAs(WebClient.class); WebClient client2 = reference.cachedAs(WebClient.class); context.assertTrue(client == client2);
context.assertFalse(reference.record().getLocation().getBoolean("ssl")); WebClient client = reference.getAs(WebClient.class); WebClient client2 = reference.cachedAs(WebClient.class); context.assertTrue(client == client2);