Search in sources :

Example 1 with Plugins

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

the class InfixScatter method connect.

@Override
public void connect(final Vertx vertx) {
    final ConcurrentMap<String, Class<?>> wholeInjections = ZeroAmbient.getInjections();
    /**
     * Enabled *
     */
    final ConcurrentMap<String, Class<?>> enabled = Ut.reduce(node.read().keySet(), wholeInjections);
    /**
     * Scan all Infix *
     */
    final ConcurrentMap<Class<? extends Annotation>, Class<?>> injections = Ut.reduce(Plugins.INFIX_MAP, enabled);
    injections.values().stream().forEach(item -> {
        if (null != item && item.isAnnotationPresent(Plugin.class)) {
            final Method method = this.findInit(item);
            Fn.flingUp(null == method, LOGGER, PluginSpecificationException.class, this.getClass(), item.getName());
            Fn.safeJvm(() -> method.invoke(null, vertx), LOGGER);
        }
    });
    /**
     * Scan all extension Infix *
     */
    Observable.fromIterable(wholeInjections.keySet()).filter(key -> !Plugins.Infix.STANDAND.contains(key)).map(wholeInjections::get).filter(item -> null != item && item.isAnnotationPresent(Plugin.class)).subscribe(item -> {
        final Method method = this.findInit(item);
        Fn.flingUp(null == method, LOGGER, PluginSpecificationException.class, this.getClass(), item.getName());
        Fn.safeJvm(() -> method.invoke(null, vertx), LOGGER);
    });
    /**
     * After infix inject plugins *
     */
    Fn.itSet(PLUGINS, (clazz, index) -> Runner.run(() -> {
        /**
         * Instance reference *
         */
        final Object reference = Instance.singleton(clazz);
        /**
         * Injects scanner *
         */
        PLUGIN.inject(reference);
    }, "injects-plugin-scannner"));
}
Also used : Fn(io.vertx.up.func.Fn) Arrays(java.util.Arrays) ZeroAmbient(io.vertx.up.web.ZeroAmbient) ZeroLime(io.vertx.zero.marshal.node.ZeroLime) Vertx(io.vertx.core.Vertx) Ut(io.vertx.up.tool.Ut) Set(java.util.Set) Plugin(io.vertx.up.annotations.Plugin) PluginSpecificationException(io.vertx.zero.exception.PluginSpecificationException) Collectors(java.util.stream.Collectors) Runner(io.vertx.up.concurrent.Runner) Instance(io.vertx.up.tool.mirror.Instance) ConcurrentMap(java.util.concurrent.ConcurrentMap) List(java.util.List) Values(io.vertx.zero.eon.Values) Modifier(java.lang.reflect.Modifier) Annal(io.vertx.up.log.Annal) ZeroAnno(io.vertx.up.web.ZeroAnno) Annotation(java.lang.annotation.Annotation) Observable(io.reactivex.Observable) Plugins(io.vertx.up.eon.Plugins) Node(io.vertx.zero.marshal.node.Node) Method(java.lang.reflect.Method) Method(java.lang.reflect.Method) Annotation(java.lang.annotation.Annotation) Plugin(io.vertx.up.annotations.Plugin)

Aggregations

Observable (io.reactivex.Observable)1 Vertx (io.vertx.core.Vertx)1 Plugin (io.vertx.up.annotations.Plugin)1 Runner (io.vertx.up.concurrent.Runner)1 Plugins (io.vertx.up.eon.Plugins)1 Fn (io.vertx.up.func.Fn)1 Annal (io.vertx.up.log.Annal)1 Ut (io.vertx.up.tool.Ut)1 Instance (io.vertx.up.tool.mirror.Instance)1 ZeroAmbient (io.vertx.up.web.ZeroAmbient)1 ZeroAnno (io.vertx.up.web.ZeroAnno)1 Values (io.vertx.zero.eon.Values)1 PluginSpecificationException (io.vertx.zero.exception.PluginSpecificationException)1 Node (io.vertx.zero.marshal.node.Node)1 ZeroLime (io.vertx.zero.marshal.node.ZeroLime)1 Annotation (java.lang.annotation.Annotation)1 Method (java.lang.reflect.Method)1 Modifier (java.lang.reflect.Modifier)1 Arrays (java.util.Arrays)1 List (java.util.List)1