use of io.vertx.up.micro.follow.Invoker 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())));
}
}