Search in sources :

Example 11 with Envelop

use of io.vertx.up.atom.Envelop in project vertx-zero by silentbalanceyh.

the class AsyncInvoker method next.

@Override
@SuppressWarnings("unchecked")
public void next(final Object proxy, final Method method, final Message<Envelop> message, final Vertx vertx) {
    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, true);
    // 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.compose(item -> TunnelClient.create(this.getClass()).connect(vertx).connect(method).send(item)).setHandler(Ux.toHandler(message));
    } else {
        final Object reference = envelop.data();
        final Object arguments = Ut.deserialize(Ut.toString(reference), argType);
        final Future future = Instance.invoke(proxy, method.getName(), arguments);
        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) 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) Future(io.vertx.core.Future)

Example 12 with Envelop

use of io.vertx.up.atom.Envelop in project vertx-zero by silentbalanceyh.

the class FutureInvoker method invoke.

@Override
@SuppressWarnings("unchecked")
public void invoke(final Object proxy, final Method method, final Message<Envelop> message) {
    // 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, false);
    if (Envelop.class == tCls) {
        final Future<Envelop> result = Instance.invoke(proxy, method.getName(), envelop);
        result.setHandler(item -> message.reply(item.result()));
    } else {
        final Future tResult = Instance.invoke(proxy, method.getName(), envelop);
        tResult.setHandler(Ux.toHandler(message));
    }
}
Also used : Envelop(io.vertx.up.atom.Envelop) Future(io.vertx.core.Future)

Example 13 with Envelop

use of io.vertx.up.atom.Envelop in project vertx-zero by silentbalanceyh.

the class SyncInvoker method invoke.

@Override
public void invoke(final Object proxy, final Method method, final Message<Envelop> message) {
    // Invoke directly
    final Envelop envelop = message.body();
    LOGGER.info(Info.MSG_FUTURE, this.getClass(), method.getReturnType(), false);
    message.reply(Instance.invoke(proxy, method.getName(), envelop));
}
Also used : Envelop(io.vertx.up.atom.Envelop)

Example 14 with Envelop

use of io.vertx.up.atom.Envelop in project vertx-zero by silentbalanceyh.

the class SyncInvoker 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 result = Instance.invoke(proxy, method.getName(), envelop);
    TunnelClient.create(this.getClass()).connect(vertx).connect(method).send(result).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)

Example 15 with Envelop

use of io.vertx.up.atom.Envelop in project vertx-zero by silentbalanceyh.

the class UnitySpear method send.

@Override
public Future<Envelop> send(final Vertx vertx, final IpcData data) {
    // Channel
    final ManagedChannel channel = RpcSslTool.getChannel(vertx, data);
    final UnityServiceGrpc.UnityServiceVertxStub stub = UnityServiceGrpc.newVertxStub(channel);
    // Request
    final IpcRequest request = DataEncap.in(data);
    // Call and return to future
    final Future<Envelop> handler = Future.future();
    stub.unityCall(request, response -> RpcRepdor.create(getClass()).reply(handler, response));
    return handler;
}
Also used : Envelop(io.vertx.up.atom.Envelop) ManagedChannel(io.grpc.ManagedChannel) UnityServiceGrpc(io.vertx.tp.ipc.service.UnityServiceGrpc) IpcRequest(io.vertx.tp.ipc.eon.IpcRequest)

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