Search in sources :

Example 6 with Envelop

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

Example 7 with Envelop

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

Example 8 with Envelop

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

Example 9 with Envelop

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

Example 10 with Envelop

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())));
    }
}
Also used : Receipt(io.vertx.up.atom.worker.Receipt) Invoker(io.vertx.up.micro.follow.Invoker) Envelop(io.vertx.up.atom.Envelop) EventBus(io.vertx.core.eventbus.EventBus) Method(java.lang.reflect.Method)

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