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

io.vertx.up.runtime.ZeroAnno Maven / Gradle / Ivy

There is a newer version: 0.9.0
Show newest version
package io.vertx.up.runtime;

import io.vertx.core.http.HttpMethod;
import io.vertx.up.atom.agent.Event;
import io.vertx.up.atom.secure.Cliff;
import io.vertx.up.atom.worker.Mission;
import io.vertx.up.atom.worker.Receipt;
import io.vertx.up.eon.em.ServerType;
import io.vertx.up.log.Annal;
import io.vertx.up.uca.web.origin.*;
import io.vertx.up.util.Ut;
import io.vertx.up.fn.Fn;

import java.lang.reflect.Method;
import java.util.*;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;

/**
 * Transfer Class set to difference mapping.
 */
public class ZeroAnno {

    private static final Annal LOGGER = Annal.get(ZeroAnno.class);

    private final static Set>
            ENDPOINTS = new HashSet<>();
    private final static ConcurrentMap, ConcurrentMap>>
            PLUGINS = new ConcurrentHashMap<>();
    private final static Set
            RECEIPTS = new HashSet<>();
    private final static Set
            EVENTS = new HashSet<>();
    private final static ConcurrentMap>
            FILTERS = new ConcurrentHashMap<>();
    private final static ConcurrentMap>>
            AGENTS = new ConcurrentHashMap<>();
    private final static Set>
            WORKERS = new HashSet<>();
    private final static Set
            WALLS = new TreeSet<>();
    private final static ConcurrentMap
            IPCS = new ConcurrentHashMap<>();
    private final static Set>
            POINTER = new HashSet<>();
    private final static Set>
            TPS = new HashSet<>();
    private final static Set
            JOBS = new HashSet<>();

    /*
     * Move to main thread to do init instead of static block initialization
     */
    public static void prepare() {
        /* 1.Scan the packages **/
        final Set> clazzes = ZeroPack.getClasses();
        /* EndPoint **/
        Inquirer>> inquirer =
                Ut.singleton(EndPointInquirer.class);
        ENDPOINTS.addAll(inquirer.scan(clazzes));

        /* EndPoint -> Event **/
        Fn.safeSemi(!ENDPOINTS.isEmpty(),
                LOGGER,
                () -> {
                    final Inquirer> event = Ut.singleton(EventInquirer.class);
                    EVENTS.addAll(event.scan(ENDPOINTS));
                });
        /* 1.1. Put Path Uri into Set */
        EVENTS.stream()
                .filter(Objects::nonNull)
                /* Only Uri Pattern will be extracted to URI_PATHS */
                .filter(item -> 0 < item.getPath().indexOf(":"))
                .forEach(ZeroUri::resolve);
        ZeroUri.report();

        /* Wall -> Authenticate, Authorize **/
        final Inquirer> walls =
                Ut.singleton(WallInquirer.class);
        WALLS.addAll(walls.scan(clazzes));

        /* Filter -> WebFilter **/
        final Inquirer>> filters =
                Ut.singleton(FilterInquirer.class);
        FILTERS.putAll(filters.scan(clazzes));

        /* Queue **/
        inquirer = Ut.singleton(QueueInquirer.class);
        final Set> queues = inquirer.scan(clazzes);

        /* Queue -> Receipt **/
        Fn.safeSemi(!queues.isEmpty(),
                LOGGER,
                () -> {
                    final Inquirer> receipt = Ut.singleton(ReceiptInquirer.class);
                    RECEIPTS.addAll(receipt.scan(queues));
                });

        /* Ipc Only **/
        final Inquirer> ipc = Ut.singleton(IpcInquirer.class);
        IPCS.putAll(ipc.scan(clazzes));
        /* Agent **/
        final Inquirer>>> agent = Ut.singleton(AgentInquirer.class);
        AGENTS.putAll(agent.scan(clazzes));

        /* JSR330 Fix **/
        final Inquirer>> pointer = Ut.singleton(PointerInquirer.class);
        POINTER.addAll(pointer.scan(clazzes));

        /* Tp Clients **/
        final Inquirer>> tps = Ut.singleton(PluginInquirer.class);
        TPS.addAll(tps.scan(clazzes));

        /* Worker **/
        final Inquirer>> worker = Ut.singleton(WorkerInquirer.class);
        WORKERS.addAll(worker.scan(clazzes));

        /* Jobs with description in zero */
        final Inquirer> jobs = Ut.singleton(JobInquirer.class);
        JOBS.addAll(jobs.scan(clazzes));

        /* Injections **/
        final Inquirer, ConcurrentMap>>> afflux = Ut.singleton(AffluxInquirer.class);
        PLUGINS.putAll(afflux.scan(clazzes));
    }

    /**
     * Get all plugins
     *
     * @return plugin map
     */
    public static ConcurrentMap, ConcurrentMap>> getPlugins() {
        return PLUGINS;
    }

    /**
     * Get all agents.
     *
     * @return agent map
     */
    public static ConcurrentMap>> getAgents() {
        return AGENTS;
    }

    /**
     * Injects
     *
     * @return pointer set
     */
    public static Set> getInjects() {
        return POINTER;
    }

    /**
     * Tp Clients
     *
     * @return client set
     */
    public static Set> getTps() {
        return TPS;
    }

    /**
     * Get Jobs for current
     */
    public static Set getJobs() {
        return JOBS;
    }

    /**
     * Get all workers
     *
     * @return worker set
     */
    public static Set> getWorkers() {
        return WORKERS;
    }

    /**
     * Get all receipts
     *
     * @return receipts set
     */
    public static Set getReceipts() {
        return RECEIPTS;
    }

    /**
     * Get all endpoints
     *
     * @return endpoint set
     */
    public static Set> getEndpoints() {
        return ENDPOINTS;
    }

    public static ConcurrentMap getIpcs() {
        return IPCS;
    }

    /**
     * Get all envents
     *
     * @return event set
     */
    public static Set getEvents() {
        return EVENTS;
    }

    /**
     * Get all filters
     *
     * @return filter map JSR340
     */
    public static ConcurrentMap> getFilters() {
        return FILTERS;
    }

    /**
     * Get all guards
     *
     * @return guard set
     */
    public static Set getWalls() {
        return WALLS;
    }

    public static String recoveryUri(final String uri, final HttpMethod method) {
        return ZeroUri.recovery(uri, method);
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy