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

io.vertx.up.uca.web.limit.HttpFactor Maven / Gradle / Ivy

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

import io.vertx.tp.error.RpcPreparingException;
import io.vertx.tp.plugin.etcd.center.EtcdData;
import io.vertx.up.eon.em.ServerType;
import io.vertx.up.fn.Fn;
import io.vertx.up.log.Annal;
import io.vertx.up.verticle.ZeroHttpAgent;
import io.vertx.up.verticle.ZeroRpcAgent;
import io.vertx.up.verticle.ZeroSockAgent;
import io.vertx.up.runtime.ZeroMotor;

import java.util.HashSet;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;

/**
 * This factor could begin following:
 * 1. Http Server,
 * 2. Rpc Server.
 */
public class HttpFactor implements Factor {

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

    private static final Class[] DEFAULT_AGENTS = new Class[]{
            ZeroHttpAgent.class, ZeroRpcAgent.class, ZeroSockAgent.class
    };

    private static final ConcurrentMap> INTERNALS
            = new ConcurrentHashMap>() {
        {
            put(ServerType.HTTP, ZeroHttpAgent.class);
            put(ServerType.IPC, ZeroRpcAgent.class);
            put(ServerType.SOCK, ZeroSockAgent.class);
        }
    };

    @Override
    public ConcurrentMap> agents() {
        /* 1.Find Agent for deploy **/
        final ConcurrentMap> agents
                = ZeroMotor.agents(ServerType.HTTP, DEFAULT_AGENTS, INTERNALS);
        if (agents.containsKey(ServerType.IPC)) {
            // 2. Check etcd server status, IPC Only
            Fn.outUp(!EtcdData.enabled(),
                    LOGGER, RpcPreparingException.class, getClass());
        }
        // 3. Filter invalid agents
        final Set scanned = new HashSet<>(agents.keySet());
        final Set keeped = INTERNALS.keySet();
        scanned.removeAll(keeped);
        scanned.forEach(agents::remove);
        return agents;
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy