All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.vertx.up.uca.rs.dispatch.CommonDiffer Maven / Gradle / Ivy

There is a newer version: 0.9.0
Show newest version
package io.vertx.up.uca.rs.dispatch;

import io.vertx.ext.web.RoutingContext;
import io.vertx.up.atom.agent.Event;
import io.vertx.up.fn.Fn;
import io.vertx.up.uca.rs.Aim;
import io.vertx.up.uca.rs.hunt.PingAim;
import io.vertx.up.uca.rs.hunt.SyncAim;
import io.vertx.up.util.Ut;

import java.lang.reflect.Method;

/**
 * EventBus disabled for request
 * 1. SyncAim: Non-Event Bus: Request -> Response
 * 2. BlockAim: Non-Event Bus: Request -> (TRUE/FALSE)
 */
class CommonDiffer implements Differ {

    private CommonDiffer() {
    }

    public static Differ create() {
        return InstanceHolder.INSTANCE;
    }

    @Override
    public Aim build(final Event event) {
        final Method method = event.getAction();
        final Class returnType = method.getReturnType();
        Aim aim = null;
        if (Void.class == returnType || void.class == returnType) {
            // Mode 4: Non-Event Bus: One-Way
            aim = Fn.pool(Pool.AIMS, Thread.currentThread().getName() + "-mode-ping",
                () -> Ut.instance(PingAim.class));
        } else {
            // Mode 2: Non-Event Bus: Request-Response\
            aim = Fn.pool(Pool.AIMS, Thread.currentThread().getName() + "-mode-sync",
                () -> Ut.instance(SyncAim.class));
        }
        return aim;
    }

    private static final class InstanceHolder {
        private static final Differ INSTANCE = new CommonDiffer();
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy