package examples;
import io.vertx.core.eventbus.DeliveryOptions;
import io.vertx.core.Vertx;
import io.vertx.core.Future;
import io.vertx.core.json.JsonObject;
import io.vertx.core.json.JsonArray;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.stream.Collectors;
import java.util.function.Function;
import io.vertx.serviceproxy.ProxyHelper;
import io.vertx.serviceproxy.ServiceException;
import io.vertx.serviceproxy.ServiceExceptionMessageCodec;
import io.vertx.serviceproxy.ProxyUtils;
import examples.SomeDatabaseService;
import io.vertx.core.Vertx;
import io.vertx.core.json.JsonObject;
import io.vertx.core.AsyncResult;
import io.vertx.core.Handler;
@SuppressWarnings({"unchecked", "rawtypes"})
public class SomeDatabaseServiceVertxEBProxy implements SomeDatabaseService {
private Vertx _vertx;
private String _address;
private DeliveryOptions _options;
private boolean closed;
public SomeDatabaseServiceVertxEBProxy(Vertx vertx, String address) {
this(vertx, address, null);
}
public SomeDatabaseServiceVertxEBProxy(Vertx vertx, String address, DeliveryOptions options) {
this._vertx = vertx;
this._address = address;
this._options = options;
try{
this._vertx.eventBus().registerDefaultCodec(ServiceException.class, new ServiceExceptionMessageCodec());
} catch (IllegalStateException ex) {}
}
@Override
public void save(String collection, JsonObject document, Handler<AsyncResult<Void>> result){
if (closed) {
result.handle(Future.failedFuture(new IllegalStateException("Proxy is closed")));
return;
}
JsonObject _json = new JsonObject();
_json.put("collection", collection);
_json.put("document", document);
DeliveryOptions _deliveryOptions = (_options != null) ? new DeliveryOptions(_options) : new DeliveryOptions();
_deliveryOptions.addHeader("action", "save");
_vertx.eventBus().<Void>send(_address, _json, _deliveryOptions, res -> {
if (res.failed()) {
result.handle(Future.failedFuture(res.cause()));
} else {
result.handle(Future.succeededFuture(res.result().body()));
}
});
}
@Override
public SomeDatabaseService foo(String collection, JsonObject document, Handler<AsyncResult<Void>> result){
if (closed) {
result.handle(Future.failedFuture(new IllegalStateException("Proxy is closed")));
return this;
}
JsonObject _json = new JsonObject();
_json.put("collection", collection);
_json.put("document", document);
DeliveryOptions _deliveryOptions = (_options != null) ? new DeliveryOptions(_options) : new DeliveryOptions();
_deliveryOptions.addHeader("action", "foo");
_vertx.eventBus().<Void>send(_address, _json, _deliveryOptions, res -> {
if (res.failed()) {
result.handle(Future.failedFuture(res.cause()));
} else {
result.handle(Future.succeededFuture(res.result().body()));
}
});
return this;
}
}