use of io.vertx.up.atom.Envelop in project vertx-zero by silentbalanceyh.
the class UnityTunnel method init.
@Override
public BindableService init(final Vertx vertx) {
return new UnityServiceGrpc.UnityServiceVertxImplBase() {
@Override
public void unityCall(final IpcRequest request, final Future<IpcResponse> future) {
// IpcData building
final IpcData data = DataEncap.consume(request, IpcType.UNITY);
// Method called with message handler
final Envelop envelop = DataEncap.consume(data);
// Method handle
final Method method = IPCS.get(data.getAddress());
// Work mode
if (null == method) {
// No Rpc Handler here
final Envelop community = Envelop.failure(new _501RpcMethodMissingException(this.getClass(), data.getAddress()));
// Build IpcData
final IpcData responseData = UnityTunnel.this.build(community, envelop);
future.complete(DataEncap.out(responseData));
} else {
// Execute Transit
final Transit transit = UnityTunnel.this.getTransit(method, vertx);
// Execute Transit
final Future<Envelop> result = transit.async(envelop);
result.setHandler(res -> {
final IpcData responseData = UnityTunnel.this.build(res.result(), envelop);
future.complete(DataEncap.out(responseData));
});
}
}
};
}
use of io.vertx.up.atom.Envelop in project vertx-zero by silentbalanceyh.
the class DynamicInvoker method invoke.
@Override
public void invoke(final Object proxy, final Method method, final Message<Envelop> message) {
final Envelop envelop = message.body();
LOGGER.info(Info.MSG_FUTURE, this.getClass(), method.getReturnType(), false);
final Envelop returnValue = this.executeMethod(proxy, method, envelop);
message.reply(returnValue);
}
use of io.vertx.up.atom.Envelop in project vertx-zero by silentbalanceyh.
the class PingInvoker method invoke.
@Override
public void invoke(final Object proxy, final Method method, final Message<Envelop> message) {
// Invoke directly
final Envelop envelop = message.body();
Instance.invoke(proxy, method.getName(), envelop);
message.reply(Envelop.success(Boolean.TRUE));
}
use of io.vertx.up.atom.Envelop in project vertx-zero by silentbalanceyh.
the class ReturnTransit method build.
@SuppressWarnings("unchecked")
static Future<Envelop> build(final Object returnValue, final Method method) {
if (null == returnValue) {
// Empty Future
return Future.succeededFuture(Envelop.ok());
}
final Class<?> clazz = returnValue.getClass();
final Future<Envelop> result;
if (Future.class.isAssignableFrom(clazz)) {
// Fix Async Server Issue
final Class<?> tCls = clazz.getComponentType();
if (Envelop.class == tCls) {
// Future<Envelop>
LOGGER.info(Info.MSG_FLOW, "Future<Envelop>", clazz);
result = (Future<Envelop>) returnValue;
} else {
// Future<JsonObject> or Future<JsonArray>
LOGGER.info(Info.MSG_FLOW, "Future<T>", clazz);
final Future future = (Future) returnValue;
return future.compose(item -> Future.succeededFuture(Ux.to(item)));
}
} else {
if (Envelop.class == clazz) {
// Envelop got
LOGGER.info(Info.MSG_FLOW, "Envelop", clazz);
result = Future.succeededFuture((Envelop) returnValue);
} else {
LOGGER.info(Info.MSG_FLOW, "Other Type", clazz);
final Envelop envelop = Envelop.success(returnValue);
result = Future.succeededFuture(envelop);
}
}
return result;
}
use of io.vertx.up.atom.Envelop in project vertx-zero by silentbalanceyh.
the class BaseAim method success.
protected Envelop success(final String address, final AsyncResult<Message<Envelop>> handler) {
Envelop envelop;
try {
final Message<Envelop> message = handler.result();
envelop = message.body();
} catch (final Throwable ex) {
final WebException error = new _500EntityCastException(this.getClass(), address, ex.getMessage());
envelop = Envelop.failure(error);
}
return envelop;
}
Aggregations