Search in sources :

Example 1 with Invoker

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

EventBus (io.vertx.core.eventbus.EventBus)1 Envelop (io.vertx.up.atom.Envelop)1 Receipt (io.vertx.up.atom.worker.Receipt)1 Invoker (io.vertx.up.micro.follow.Invoker)1 Method (java.lang.reflect.Method)1