/** * Creates a record based on the parameters. * @param name the service name * @param address the address * @param classname the payload class * @return the record */ public static Record createRecord(String name, String address, String classname) { Record ret = io.vertx.servicediscovery.types.EventBusService.createRecord(name, address, classname); return ret; }
public <T> void getServiceProxy(Function<Record, Boolean> filter, Class<T> serviceClass, Handler<AsyncResult<T>> handler) { EventBusService.getServiceProxy(serviceDiscovery, filter, serviceClass, handler); }
public <T> void getProxy(Class<T> serviceClass, Handler<AsyncResult<T>> handler) { EventBusService.getProxy(serviceDiscovery, serviceClass, handler); }
@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); }
public <T> void getServiceProxy(JsonObject jsonFilter, Class<T> serviceClass, Handler<AsyncResult<T>> handler) { EventBusService.getServiceProxyWithJsonFilter(serviceDiscovery, jsonFilter, serviceClass, handler); } }
@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); }
public static <T>java.lang.Object getServiceProxyWithJsonFilter(io.vertx.servicediscovery.types.EventBusService j_receiver, io.vertx.servicediscovery.ServiceDiscovery discovery, java.util.Map<String, Object> filter, java.lang.Class<java.lang.Object> clientClass, io.vertx.core.Handler<io.vertx.core.AsyncResult<java.lang.Object>> resultHandler) { return io.vertx.core.impl.ConversionHelper.fromObject(io.vertx.servicediscovery.types.EventBusService.getServiceProxyWithJsonFilter(discovery, filter != null ? io.vertx.core.impl.ConversionHelper.toJsonObject(filter) : null, clientClass, resultHandler != null ? new io.vertx.core.Handler<io.vertx.core.AsyncResult<java.lang.Object>>() { public void handle(io.vertx.core.AsyncResult<java.lang.Object> ar) { resultHandler.handle(ar.map(event -> io.vertx.core.impl.ConversionHelper.fromObject(event))); } } : null)); } public static java.util.Map<String, Object> createRecord(io.vertx.servicediscovery.types.EventBusService j_receiver, java.lang.String name, java.lang.String address, java.lang.String classname) {
/** * Creates a record based on the parameters. * @param name the service name * @param address the address * @param classname the payload class * @return the record */ public static Record createRecord(String name, String address, String classname) { Record ret = io.vertx.servicediscovery.types.EventBusService.createRecord(name, address, classname); return ret; }
public static <T>java.lang.Object getServiceProxy(io.vertx.servicediscovery.types.EventBusService j_receiver, io.vertx.servicediscovery.ServiceDiscovery discovery, java.util.function.Function<java.util.Map<String, Object>, java.lang.Boolean> filter, java.lang.Class<java.lang.Object> clientClass, io.vertx.core.Handler<io.vertx.core.AsyncResult<java.lang.Object>> resultHandler) { return io.vertx.core.impl.ConversionHelper.fromObject(io.vertx.servicediscovery.types.EventBusService.getServiceProxy(discovery, filter != null ? new java.util.function.Function<io.vertx.servicediscovery.Record, java.lang.Boolean>() { public java.lang.Boolean apply(io.vertx.servicediscovery.Record t) { java.util.Map<String, Object> o = t != null ? io.vertx.core.impl.ConversionHelper.fromJsonObject(t.toJson()) : null; java.lang.Boolean p = filter.apply(o); return p; } } : null, clientClass, resultHandler != null ? new io.vertx.core.Handler<io.vertx.core.AsyncResult<java.lang.Object>>() { public void handle(io.vertx.core.AsyncResult<java.lang.Object> ar) { resultHandler.handle(ar.map(event -> io.vertx.core.impl.ConversionHelper.fromObject(event))); } } : null)); } public static <T>java.lang.Object getServiceProxyWithJsonFilter(io.vertx.servicediscovery.types.EventBusService j_receiver, io.vertx.servicediscovery.ServiceDiscovery discovery, java.util.Map<String, Object> filter, java.lang.Class<java.lang.Object> clientClass, io.vertx.core.Handler<io.vertx.core.AsyncResult<java.lang.Object>> resultHandler) {
/** * Get product service from the service discovery infrastructure. * * @return async result of the service. */ private Future<ProductService> getProductService() { Future<ProductService> future = Future.future(); EventBusService.getProxy(discovery, ProductService.class, future.completer()); return future; } }
/** * Lookup for a service record and if found, retrieve it and return the service object (used to consume the service). * This is a convenient method to avoid explicit lookup and then retrieval of the service. This method requires to * have the <code>clientClass</code> set with the expected set of client. This is important for usages not using Java so * you can pass the expected type. * @param discovery the service discovery * @param filter the filter as json object * @param clientClass the client class * @param resultHandler the result handler * @return <code>null</code> - do not use */ public static <T> T getServiceProxyWithJsonFilter(io.vertx.rxjava.servicediscovery.ServiceDiscovery discovery, JsonObject filter, Class<T> clientClass, Handler<AsyncResult<T>> resultHandler) { T ret = (T)io.vertx.lang.rx.TypeArg.of(clientClass).wrap(io.vertx.servicediscovery.types.EventBusService.getServiceProxyWithJsonFilter(discovery.getDelegate(), filter, io.vertx.lang.rxjava.Helper.unwrap(clientClass), new Handler<AsyncResult<T>>() { public void handle(AsyncResult<T> ar) { if (ar.succeeded()) { resultHandler.handle(io.vertx.core.Future.succeededFuture((T)io.vertx.lang.rx.TypeArg.of(clientClass).wrap(ar.result()))); } else { resultHandler.handle(io.vertx.core.Future.failedFuture(ar.cause())); } } })); return ret; }
/** * Creates a record based on the parameters. * * @param name the service name * @param address the address * @param classname the payload class * @return the record */ static Record createRecord(String name, String address, String classname) { return createRecord(name, address, classname, null); } }
private Future<PortfolioService> getPortfolioService(ServiceDiscovery discovery) { Future<PortfolioService> future = Future.future(); EventBusService.getServiceProxy(discovery, rec -> rec.getName().equalsIgnoreCase("portfolio"), PortfolioService.class, future); return future; }
/** * Fetch global counter of order from the cache infrastructure. * * @param key counter key (type) * @return async result of the counter */ private Future<Long> retrieveCounter(String key) { Future<Long> future = Future.future(); EventBusService.getProxy(discovery, CounterService.class, ar -> { if (ar.succeeded()) { CounterService service = ar.result(); service.addThenRetrieve(key, future.completer()); } else { future.fail(ar.cause()); } }); return future; }
/** * Lookup for a service record and if found, retrieve it and return the service object (used to consume the service). * This is a convenient method to avoid explicit lookup and then retrieval of the service. This method requires to * have the <code>clientClass</code> set with the expected set of client. This is important for usages not using Java so * you can pass the expected type. * @param discovery the service discovery * @param filter the filter as json object * @param clientClass the client class * @param resultHandler the result handler * @return <code>null</code> - do not use */ public static <T> T getServiceProxyWithJsonFilter(io.vertx.rxjava.servicediscovery.ServiceDiscovery discovery, JsonObject filter, Class<T> clientClass, Handler<AsyncResult<T>> resultHandler) { T ret = (T)io.vertx.lang.rx.TypeArg.of(clientClass).wrap(io.vertx.servicediscovery.types.EventBusService.getServiceProxyWithJsonFilter(discovery.getDelegate(), filter, io.vertx.lang.rxjava.Helper.unwrap(clientClass), new Handler<AsyncResult<T>>() { public void handle(AsyncResult<T> ar) { if (ar.succeeded()) { resultHandler.handle(io.vertx.core.Future.succeededFuture((T)io.vertx.lang.rx.TypeArg.of(clientClass).wrap(ar.result()))); } else { resultHandler.handle(io.vertx.core.Future.failedFuture(ar.cause())); } } })); return ret; }
/** * Creates a record based on the parameters. * * @param name the service name * @param address the address * @param classname the payload class * @return the record */ static Record createRecord(String name, String address, String classname) { return createRecord(name, address, classname, null); } }
/** * Lookup for a service record and if found, retrieve it and return the service object (used to consume the service). * This is a convenient method to avoid explicit lookup and then retrieval of the service. This method requires to * have the <code>clientClass</code> set with the expected set of client. This is important for usages not using Java so * you can pass the expected type. * @param discovery the service discovery * @param filter the filter * @param clientClass the client class * @param resultHandler the result handler * @return <code>null</code> - do not use */ public static <T> T getServiceProxy(io.vertx.rxjava.servicediscovery.ServiceDiscovery discovery, Function<Record, Boolean> filter, Class<T> clientClass, Handler<AsyncResult<T>> resultHandler) { T ret = (T)io.vertx.lang.rx.TypeArg.of(clientClass).wrap(io.vertx.servicediscovery.types.EventBusService.getServiceProxy(discovery.getDelegate(), filter, io.vertx.lang.rxjava.Helper.unwrap(clientClass), new Handler<AsyncResult<T>>() { public void handle(AsyncResult<T> ar) { if (ar.succeeded()) { resultHandler.handle(io.vertx.core.Future.succeededFuture((T)io.vertx.lang.rx.TypeArg.of(clientClass).wrap(ar.result()))); } else { resultHandler.handle(io.vertx.core.Future.failedFuture(ar.cause())); } } })); return ret; }
private Future<ShoppingCart> getCurrentCart(String userId) { Future<ShoppingCartService> future = Future.future(); EventBusService.getProxy(discovery, ShoppingCartService.class, future.completer()); return future.compose(service -> { Future<ShoppingCart> cartFuture = Future.future(); service.getShoppingCart(userId, cartFuture.completer()); return cartFuture.compose(c -> { if (c == null || c.isEmpty()) return Future.failedFuture(new IllegalStateException("Invalid shopping cart")); else return Future.succeededFuture(c); }); }); }
/** * Sugar method to creates a record for this type. * <p> * The java interface is added to the metadata in the `service.interface` key. * @param name the name of the service. * @param address the event bus address on which the service available * @param itf the Java interface (name) * @param metadata the metadata * @return the created record */ public static Record createRecord(String name, String address, String itf, JsonObject metadata) { Record ret = io.vertx.servicediscovery.types.EventBusService.createRecord(name, address, itf, metadata); return ret; }
/** * Lookup for a service record and if found, retrieve it and return the service object (used to consume the service). * This is a convenient method to avoid explicit lookup and then retrieval of the service. This method requires to * have the <code>clientClass</code> set with the expected set of client. This is important for usages not using Java so * you can pass the expected type. * @param discovery the service discovery * @param filter the filter * @param clientClass the client class * @param resultHandler the result handler * @return <code>null</code> - do not use */ public static <T> T getServiceProxy(io.vertx.rxjava.servicediscovery.ServiceDiscovery discovery, Function<Record, Boolean> filter, Class<T> clientClass, Handler<AsyncResult<T>> resultHandler) { T ret = (T)io.vertx.lang.rx.TypeArg.of(clientClass).wrap(io.vertx.servicediscovery.types.EventBusService.getServiceProxy(discovery.getDelegate(), filter, io.vertx.lang.rxjava.Helper.unwrap(clientClass), new Handler<AsyncResult<T>>() { public void handle(AsyncResult<T> ar) { if (ar.succeeded()) { resultHandler.handle(io.vertx.core.Future.succeededFuture((T)io.vertx.lang.rx.TypeArg.of(clientClass).wrap(ar.result()))); } else { resultHandler.handle(io.vertx.core.Future.failedFuture(ar.cause())); } } })); return ret; }