use of io.vertx.up.atom.Envelop in project vertx-zero by silentbalanceyh.
the class AsyncInvoker method invoke.
@Override
@SuppressWarnings("unchecked")
public void invoke(final Object proxy, final Method method, final Message<Envelop> message) {
final Envelop envelop = message.body();
// Get type of parameter first element
final Class<?> argType = method.getParameterTypes()[Values.IDX];
// Deserialization from message bus.
final Class<?> returnType = method.getReturnType();
LOGGER.info(Info.MSG_FUTURE, this.getClass(), returnType, false);
// Get T
final Class<?> tCls = returnType.getComponentType();
if (Envelop.class == tCls) {
// Input type is Envelop, input directly
final Future<Envelop> result = Instance.invoke(proxy, method.getName(), envelop);
result.setHandler(item -> message.reply(item.result()));
} else {
final Object reference = envelop.data();
final Object arguments = Ut.deserialize(Ut.toString(reference), argType);
final Future tResult = Instance.invoke(proxy, method.getName(), arguments);
tResult.setHandler(Ux.toHandler(message));
}
}
use of io.vertx.up.atom.Envelop in project vertx-zero by silentbalanceyh.
the class FutureInvoker method next.
@Override
@SuppressWarnings("unchecked")
public void next(final Object proxy, final Method method, final Message<Envelop> message, final Vertx vertx) {
// Invoke directly
final Envelop envelop = message.body();
// Future<T>
final Class<?> returnType = method.getReturnType();
// Get T
final Class<?> tCls = returnType.getComponentType();
LOGGER.info(Info.MSG_FUTURE, this.getClass(), returnType, true);
if (Envelop.class == tCls) {
// Execute Future<Envelop>
final Future<Envelop> future = Instance.invoke(proxy, method.getName(), envelop);
future.compose(item -> TunnelClient.create(this.getClass()).connect(vertx).connect(method).send(item)).setHandler(Ux.toHandler(message));
} else {
final Future future = Instance.invoke(proxy, method.getName(), envelop);
future.compose(item -> TunnelClient.create(this.getClass()).connect(vertx).connect(method).send(Ux.to(item))).compose(item -> Future.succeededFuture(Ux.to(item))).setHandler(Ux.toHandler(message));
}
}
use of io.vertx.up.atom.Envelop in project vertx-zero by silentbalanceyh.
the class DataEncap method build.
private static Envelop build(final JsonObject json) {
Envelop envelop = Envelop.ok();
// 1. Headers
if (null != json) {
// 2.Rebuild
if (json.containsKey("data")) {
envelop = Envelop.success(json.getValue("data"));
}
// 3.Header
if (null != json.getValue("header")) {
final MultiMap headers = MultiMap.caseInsensitiveMultiMap();
final JsonObject headerData = json.getJsonObject("header");
for (final String key : headerData.fieldNames()) {
final Object value = headerData.getValue(key);
if (null != value) {
headers.set(key, value.toString());
}
}
envelop.setHeaders(headers);
}
// 4.User
if (null != json.getValue("user")) {
envelop.setUser(new VirtualUser(json.getJsonObject("user")));
}
}
return envelop;
}
use of io.vertx.up.atom.Envelop in project vertx-zero by silentbalanceyh.
the class D10046FirstTc method testUx.
@Test
public void testUx() {
final JsonObject input = this.getJson("d10046.json");
final Envelop envelop = Ux.to(input);
Assert.assertNotNull(envelop.data());
System.err.println(envelop.data(JsonObject.class));
}
use of io.vertx.up.atom.Envelop in project vertx-zero by silentbalanceyh.
the class DynamicInvoker method next.
@Override
public void next(final Object proxy, final Method method, final Message<Envelop> message, final Vertx vertx) {
final Envelop envelop = message.body();
LOGGER.info(Info.MSG_FUTURE, this.getClass(), method.getReturnType(), true);
final Envelop returnValue = this.executeMethod(proxy, method, envelop);
TunnelClient.create(this.getClass()).connect(vertx).connect(method).send(returnValue).compose(item -> Future.succeededFuture(Ux.to(item))).setHandler(Ux.toHandler(message));
}
Aggregations