Search in sources :

Example 1 with Envelop

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));
    }
}
Also used : Envelop(io.vertx.up.atom.Envelop) Future(io.vertx.core.Future)

Example 2 with Envelop

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));
    }
}
Also used : TunnelClient(io.vertx.up.micro.ipc.client.TunnelClient) Vertx(io.vertx.core.Vertx) Annal(io.vertx.up.log.Annal) Message(io.vertx.core.eventbus.Message) Envelop(io.vertx.up.atom.Envelop) Ux(io.vertx.up.aiki.Ux) Future(io.vertx.core.Future) Method(java.lang.reflect.Method) Instance(io.vertx.up.tool.mirror.Instance) Envelop(io.vertx.up.atom.Envelop) Future(io.vertx.core.Future)

Example 3 with Envelop

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;
}
Also used : MultiMap(io.vertx.core.MultiMap) IpcEnvelop(io.vertx.tp.ipc.eon.IpcEnvelop) Envelop(io.vertx.up.atom.Envelop) VirtualUser(io.vertx.up.atom.hold.VirtualUser) JsonObject(io.vertx.core.json.JsonObject) JsonObject(io.vertx.core.json.JsonObject)

Example 4 with 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));
}
Also used : Envelop(io.vertx.up.atom.Envelop) JsonObject(io.vertx.core.json.JsonObject) Test(org.junit.Test)

Example 5 with Envelop

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));
}
Also used : ZeroSerializer(io.vertx.up.web.ZeroSerializer) TunnelClient(io.vertx.up.micro.ipc.client.TunnelClient) Values(io.vertx.zero.eon.Values) Vertx(io.vertx.core.Vertx) Annal(io.vertx.up.log.Annal) Message(io.vertx.core.eventbus.Message) Envelop(io.vertx.up.atom.Envelop) Ut(io.vertx.up.tool.Ut) Ux(io.vertx.up.aiki.Ux) Future(io.vertx.core.Future) Method(java.lang.reflect.Method) Instance(io.vertx.up.tool.mirror.Instance) Envelop(io.vertx.up.atom.Envelop)

Aggregations

Envelop (io.vertx.up.atom.Envelop)21 Future (io.vertx.core.Future)8 Method (java.lang.reflect.Method)6 Vertx (io.vertx.core.Vertx)4 Message (io.vertx.core.eventbus.Message)4 JsonObject (io.vertx.core.json.JsonObject)4 Ux (io.vertx.up.aiki.Ux)4 Annal (io.vertx.up.log.Annal)4 TunnelClient (io.vertx.up.micro.ipc.client.TunnelClient)4 Instance (io.vertx.up.tool.mirror.Instance)4 IpcRequest (io.vertx.tp.ipc.eon.IpcRequest)2 io.vertx.up.exception._500UnexpectedRpcException (io.vertx.up.exception._500UnexpectedRpcException)2 Ut (io.vertx.up.tool.Ut)2 Values (io.vertx.zero.eon.Values)2 ManagedChannel (io.grpc.ManagedChannel)1 MultiMap (io.vertx.core.MultiMap)1 EventBus (io.vertx.core.eventbus.EventBus)1 IpcEnvelop (io.vertx.tp.ipc.eon.IpcEnvelop)1 UnityServiceGrpc (io.vertx.tp.ipc.service.UnityServiceGrpc)1 IpcData (io.vertx.up.atom.flux.IpcData)1