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

io.vertx.up.uca.web.anima.AgentScatter Maven / Gradle / Ivy

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

import io.vertx.core.DeploymentOptions;
import io.vertx.core.Vertx;
import io.vertx.up.eon.em.ServerType;
import io.vertx.up.log.Annal;
import io.vertx.up.uca.rs.Extractor;
import io.vertx.up.uca.rs.config.AgentExtractor;
import io.vertx.up.uca.web.limit.Factor;
import io.vertx.up.uca.web.limit.HttpFactor;
import io.vertx.up.util.Ut;

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

/**
 * Agent scatter to deploy agents
 */

public class AgentScatter implements Scatter {

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

    private transient final Factor factor = Ut.singleton(HttpFactor.class);

    @Override
    public void connect(final Vertx vertx) {
        /* 1.Find Agent for deploy **/
        final ConcurrentMap> agents = this.factor.agents();
        final Extractor extractor =
            Ut.instance(AgentExtractor.class);
        /* 2.Record options**/
        final ConcurrentMap, DeploymentOptions> options =
            new ConcurrentHashMap<>();
        Ut.itMap(agents, (type, clazz) -> {
            // 3.1 Agent deployment options
            final DeploymentOptions option = extractor.extract(clazz);
            options.put(clazz, option);
            // 3.2 Agent deployment
            Verticles.deploy(vertx, clazz, option, LOGGER);
        });
        // Runtime hooker
        Runtime.getRuntime().addShutdownHook(new Thread(() ->
            Ut.itMap(agents, (type, clazz) -> {
                // 4. Undeploy Agent.
                final DeploymentOptions opt = options.get(clazz);
                Verticles.undeploy(vertx, clazz, opt, LOGGER);
            })));
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy