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);
}
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));
});
}
}
};
}
Aggregations