use of io.vertx.up.atom.Envelop in project vertx-zero by silentbalanceyh.
the class RpcRepdor method reply.
public void reply(final Future<Envelop> handler, final AsyncResult<IpcResponse> response) {
if (response.succeeded()) {
handler.complete(DataEncap.out(response.result()));
} else {
final Throwable ex = response.cause();
if (null != ex) {
final Envelop envelop = Envelop.failure(new _500UnexpectedRpcException(this.clazz, ex));
handler.complete(envelop);
// TODO: Debug Now, Remove In Future
ex.printStackTrace();
}
}
}
use of io.vertx.up.atom.Envelop in project vertx-zero by silentbalanceyh.
the class RpcRepdor method replyJson.
public void replyJson(final Future<JsonObject> handler, final AsyncResult<IpcResponse> response) {
if (response.succeeded()) {
final Envelop json = DataEncap.out(response.result());
final JsonObject data = json.data();
LOGGER.info(Info.CLIENT_RESPONSE, data);
handler.complete(data);
} else {
final Throwable ex = response.cause();
if (null != ex) {
final Envelop envelop = Envelop.failure(new _500UnexpectedRpcException(this.clazz, ex));
handler.complete(new JsonObject(envelop.response()));
// TODO: Debug Now, Remove In Future
ex.printStackTrace();
}
}
}
use of io.vertx.up.atom.Envelop in project vertx-zero by silentbalanceyh.
the class AsyncAim method invoke.
private Envelop invoke(final RoutingContext context, final Event event) {
final Object proxy = event.getProxy();
// 1. Build Arguments
final Object[] arguments = this.buildArgs(context, event);
// Interface direct
final Envelop invoked;
if (Virtual.is(proxy)) {
final JsonObject message = new JsonObject();
for (int idx = 0; idx < arguments.length; idx++) {
message.put(String.valueOf(idx), arguments[idx]);
}
// 2.1. Direct send arguments
invoked = Flower.continuous(context, message);
} else {
// 2.2. Method call
final Object returnValue = this.invoke(event, arguments);
invoked = Flower.continuous(context, returnValue);
}
// 3. Envelop injection for User/Headers
invoked.setHeaders(context.request().headers());
invoked.setUser(context.user());
invoked.setSession(context.session());
invoked.setContext(context.data());
return invoked;
}
use of io.vertx.up.atom.Envelop in project vertx-zero by silentbalanceyh.
the class Flower method replyError.
static void replyError(final RoutingContext context, final WebException error, final Event event) {
final Envelop envelop = Envelop.failure(error);
Answer.reply(context, envelop, event);
}
use of io.vertx.up.atom.Envelop in project vertx-zero by silentbalanceyh.
the class ZeroHttpWorker method start.
@Override
public void start() {
// 1. Get event bus
final EventBus bus = this.vertx.eventBus();
// 2. Consume address
for (final Receipt receipt : RECEIPTS) {
// 3. Deploy for each type
final String address = receipt.getAddress();
// 4. Get target reference and method
final Object reference = receipt.getProxy();
final Method method = receipt.getMethod();
this.verifyArgs(method, this.getClass());
// length = 1
final Class<?>[] params = method.getParameterTypes();
final Class<?> returnType = method.getReturnType();
final Class<?> paramCls = params[Values.IDX];
// 6. Invoker select
final Invoker invoker = JetSelector.select(returnType, paramCls);
invoker.ensure(returnType, paramCls);
// 7. Record for different invokers
INVOKER_MAP.put(receipt.hashCode(), invoker);
Fn.safeJvm(() -> Fn.safeNull(() -> bus.<Envelop>consumer(address, message -> {
if (method.isAnnotationPresent(Ipc.class)) {
// Rpc continue replying
invoker.next(reference, method, message, this.vertx);
} else {
// Direct replying
invoker.invoke(reference, method, message);
}
}), address, reference, method), LOGGER);
}
// Record all the information;
if (!LOGGED.getAndSet(Boolean.TRUE)) {
INVOKER_MAP.forEach((key, value) -> LOGGER.info(Info.MSG_INVOKER, value.getClass(), String.valueOf(key), String.valueOf(value.hashCode())));
}
}
Aggregations