Search in sources :

Example 16 with Envelop

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));
                });
            }
        }
    };
}
Also used : Envelop(io.vertx.up.atom.Envelop) Future(io.vertx.core.Future) Method(java.lang.reflect.Method) io.vertx.up.exception._501RpcMethodMissingException(io.vertx.up.exception._501RpcMethodMissingException) Transit(io.vertx.up.micro.ipc.tower.Transit) NodeTransit(io.vertx.up.micro.ipc.tower.NodeTransit) FinalTransit(io.vertx.up.micro.ipc.tower.FinalTransit) IpcRequest(io.vertx.tp.ipc.eon.IpcRequest) IpcData(io.vertx.up.atom.flux.IpcData)

Example 17 with Envelop

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

Example 18 with Envelop

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

Example 19 with Envelop

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

Example 20 with Envelop

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;
}
Also used : io.vertx.up.exception._500EntityCastException(io.vertx.up.exception._500EntityCastException) WebException(io.vertx.up.exception.WebException) 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