Search in sources :

Example 1 with ServerType

use of io.vertx.up.eon.em.ServerType in project vertx-zero by silentbalanceyh.

the class AgentScatter method connect.

@Override
public void connect(final Vertx vertx) {
    /**
     * 1.Find Agent for deploy *
     */
    final ConcurrentMap<ServerType, Class<?>> agents = this.factor.agents();
    final Extractor<DeploymentOptions> extractor = Instance.instance(AgentExtractor.class);
    /**
     * 2.Record options*
     */
    final ConcurrentMap<Class<?>, DeploymentOptions> options = new ConcurrentHashMap<>();
    Fn.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(() -> Fn.itMap(agents, (type, clazz) -> {
        // 4. Undeploy Agent.
        final DeploymentOptions opt = options.get(clazz);
        Verticles.undeploy(vertx, clazz, opt, LOGGER);
    })));
}
Also used : ServerType(io.vertx.up.eon.em.ServerType) DeploymentOptions(io.vertx.core.DeploymentOptions) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap)

Example 2 with ServerType

use of io.vertx.up.eon.em.ServerType in project vertx-zero by silentbalanceyh.

the class ZeroHelper method isAgentDefined.

/**
 */
public static ConcurrentMap<ServerType, Boolean> isAgentDefined(final ConcurrentMap<ServerType, List<Class<?>>> agents, final Class<?>... exclude) {
    final Set<Class<?>> excludes = new HashSet<>(Arrays.asList(exclude));
    final ConcurrentMap<ServerType, Boolean> defined = new ConcurrentHashMap<>();
    for (final ServerType server : agents.keySet()) {
        final List<Class<?>> item = agents.get(server);
        // Filter to result.
        final List<Class<?>> filtered = item.stream().filter(each -> !excludes.contains(each)).collect(Collectors.toList());
        // > 1 means duplicated defined
        final int size = filtered.size();
        Fn.flingUp(1 < size, LOGGER, AgentDuplicatedException.class, ZeroHelper.class, server, size, filtered.stream().map(Class::getName).collect(Collectors.toSet()));
        // == 0 means undefined
        // == 1 means correct defined
        defined.put(server, Values.ONE == size);
    }
    return defined;
}
Also used : Fn(io.vertx.up.func.Fn) Arrays(java.util.Arrays) ServerType(io.vertx.up.eon.em.ServerType) Path(javax.ws.rs.Path) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) Set(java.util.Set) Collectors(java.util.stream.Collectors) AgentDuplicatedException(io.vertx.zero.exception.AgentDuplicatedException) Instance(io.vertx.up.tool.mirror.Instance) ConcurrentMap(java.util.concurrent.ConcurrentMap) HashSet(java.util.HashSet) List(java.util.List) Values(io.vertx.zero.eon.Values) Annal(io.vertx.up.log.Annal) Annotation(java.lang.annotation.Annotation) Agent(io.vertx.up.annotations.Agent) Method(java.lang.reflect.Method) ServerType(io.vertx.up.eon.em.ServerType) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashSet(java.util.HashSet)

Example 3 with ServerType

use of io.vertx.up.eon.em.ServerType in project vertx-zero by silentbalanceyh.

the class PointScatter method connect.

@Override
public void connect(final Vertx vertx) {
    /**
     * 1.Find Agent for deploy *
     */
    final ConcurrentMap<ServerType, Class<?>> agents = this.factor.agents();
    final Extractor<DeploymentOptions> extractor = Instance.instance(AgentExtractor.class);
    Fn.itMap(agents, (type, clazz) -> {
        // 3.1 Agent deployment options
        final DeploymentOptions option = extractor.extract(clazz);
        // 3.2 Agent deployment
        Verticles.deploy(vertx, clazz, option, LOGGER);
    });
}
Also used : ServerType(io.vertx.up.eon.em.ServerType) DeploymentOptions(io.vertx.core.DeploymentOptions)

Example 4 with ServerType

use of io.vertx.up.eon.em.ServerType in project vertx-zero by silentbalanceyh.

the class AgentScatter method connect.

@Override
public void connect(final Vertx vertx) {
    /**
     * 1.Find Agent for deploy *
     */
    final ConcurrentMap<ServerType, Class<?>> agents = this.factor.agents();
    final Extractor<DeploymentOptions> extractor = Instance.instance(AgentExtractor.class);
    Fn.itMap(agents, (type, clazz) -> {
        // 2.1. Agent deployment options
        final DeploymentOptions option = extractor.extract(clazz);
        // 2.2. Agent deployment
        Verticles.deploy(vertx, clazz, option, LOGGER);
    });
}
Also used : ServerType(io.vertx.up.eon.em.ServerType) DeploymentOptions(io.vertx.core.DeploymentOptions)

Aggregations

ServerType (io.vertx.up.eon.em.ServerType)4 DeploymentOptions (io.vertx.core.DeploymentOptions)3 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)2 Agent (io.vertx.up.annotations.Agent)1 Fn (io.vertx.up.func.Fn)1 Annal (io.vertx.up.log.Annal)1 Instance (io.vertx.up.tool.mirror.Instance)1 Values (io.vertx.zero.eon.Values)1 AgentDuplicatedException (io.vertx.zero.exception.AgentDuplicatedException)1 Annotation (java.lang.annotation.Annotation)1 Method (java.lang.reflect.Method)1 Arrays (java.util.Arrays)1 HashSet (java.util.HashSet)1 List (java.util.List)1 Set (java.util.Set)1 ConcurrentMap (java.util.concurrent.ConcurrentMap)1 Collectors (java.util.stream.Collectors)1 Path (javax.ws.rs.Path)1