Search in sources :

Example 1 with Transit

use of io.vertx.up.micro.ipc.tower.Transit in project vertx-zero by silentbalanceyh.

the class UnityTunnel method getTransit.

private Transit getTransit(final Method method, final Vertx vertx) {
    final Annotation annotation = method.getAnnotation(Ipc.class);
    // 1. Check only one is enough because of Error-40043
    // 2. to and from must not be null at the same time because of Error-40045
    final String to = Instance.invoke(annotation, "to");
    final Transit transit;
    if (Ut.isNil(to)) {
        // Node transit
        transit = Instance.singleton(FinalTransit.class);
        LOGGER.info(Info.NODE_FINAL, method, method.getDeclaringClass());
    } else {
        // Final transit
        transit = Instance.singleton(NodeTransit.class);
        LOGGER.info(Info.NODE_MIDDLE, method, method.getDeclaringClass());
    }
    return transit.connect(vertx).connect(method);
}
Also used : NodeTransit(io.vertx.up.micro.ipc.tower.NodeTransit) FinalTransit(io.vertx.up.micro.ipc.tower.FinalTransit) Transit(io.vertx.up.micro.ipc.tower.Transit) NodeTransit(io.vertx.up.micro.ipc.tower.NodeTransit) FinalTransit(io.vertx.up.micro.ipc.tower.FinalTransit) Annotation(java.lang.annotation.Annotation)

Example 2 with Transit

use of io.vertx.up.micro.ipc.tower.Transit 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)

Aggregations

FinalTransit (io.vertx.up.micro.ipc.tower.FinalTransit)2 NodeTransit (io.vertx.up.micro.ipc.tower.NodeTransit)2 Transit (io.vertx.up.micro.ipc.tower.Transit)2 Future (io.vertx.core.Future)1 IpcRequest (io.vertx.tp.ipc.eon.IpcRequest)1 Envelop (io.vertx.up.atom.Envelop)1 IpcData (io.vertx.up.atom.flux.IpcData)1 io.vertx.up.exception._501RpcMethodMissingException (io.vertx.up.exception._501RpcMethodMissingException)1 Annotation (java.lang.annotation.Annotation)1 Method (java.lang.reflect.Method)1