Search in sources :

Example 1 with Instance

use of io.vertx.up.tool.mirror.Instance 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)

Example 2 with Instance

use of io.vertx.up.tool.mirror.Instance in project vertx-zero by silentbalanceyh.

the class RpcHelper method getRecord.

static Record getRecord(final JsonObject config) {
    /**
     * Config Verify *
     */
    Fn.flingUp(() -> Fn.shuntZero(() -> Ruler.verify(Key.RULE_KEY, config), config), LOGGER);
    // Connect remote etcd to check service
    final ConcurrentMap<String, Record> registryData = ORIGIN.getRegistryData();
    final String name = config.getString(Key.NAME);
    final String address = config.getString(Key.ADDR);
    LOGGER.debug(Info.RPC_SERVICE, name, address);
    // Empty Found
    Fn.flingWeb(registryData.values().isEmpty(), LOGGER, _424RpcServiceException.class, RpcHelper.class, name, address);
    // Service status checking
    final RxHod container = new RxHod();
    // Lookup Record instance
    Observable.fromIterable(registryData.values()).filter(Objects::nonNull).filter(item -> Ut.notNil(item.getName())).filter(item -> name.equals(item.getName()) && address.equals(item.getMetadata().getString(Key.PATH))).subscribe(container::add);
    // Service Not Found
    Fn.flingWeb(!container.successed(), LOGGER, _424RpcServiceException.class, RpcHelper.class, name, address);
    // Address Not Found
    Fn.flingWeb(!container.successed(), LOGGER, _424RpcServiceException.class, RpcHelper.class, name, address);
    final Record record = container.get();
    LOGGER.debug(Info.RPC_FOUND, record.toJson());
    return container.get();
}
Also used : io.vertx.up.exception._424RpcServiceException(io.vertx.up.exception._424RpcServiceException) Fn(io.vertx.up.func.Fn) Origin(io.vertx.up.micro.discovery.Origin) RxHod(io.vertx.up.tool.container.RxHod) Ut(io.vertx.up.tool.Ut) Ruler(io.vertx.zero.atom.Ruler) IpcType(io.vertx.up.eon.em.IpcType) Record(io.vertx.servicediscovery.Record) Instance(io.vertx.up.tool.mirror.Instance) ConcurrentMap(java.util.concurrent.ConcurrentMap) Objects(java.util.Objects) IpcOrigin(io.vertx.up.micro.discovery.IpcOrigin) Annal(io.vertx.up.log.Annal) Observable(io.reactivex.Observable) JsonObject(io.vertx.core.json.JsonObject) Record(io.vertx.servicediscovery.Record) RxHod(io.vertx.up.tool.container.RxHod)

Aggregations

Observable (io.reactivex.Observable)2 Fn (io.vertx.up.func.Fn)2 Annal (io.vertx.up.log.Annal)2 Ut (io.vertx.up.tool.Ut)2 Instance (io.vertx.up.tool.mirror.Instance)2 ConcurrentMap (java.util.concurrent.ConcurrentMap)2 Vertx (io.vertx.core.Vertx)1 JsonObject (io.vertx.core.json.JsonObject)1 Record (io.vertx.servicediscovery.Record)1 Plugin (io.vertx.up.annotations.Plugin)1 Runner (io.vertx.up.concurrent.Runner)1 Plugins (io.vertx.up.eon.Plugins)1 IpcType (io.vertx.up.eon.em.IpcType)1 io.vertx.up.exception._424RpcServiceException (io.vertx.up.exception._424RpcServiceException)1 IpcOrigin (io.vertx.up.micro.discovery.IpcOrigin)1 Origin (io.vertx.up.micro.discovery.Origin)1 RxHod (io.vertx.up.tool.container.RxHod)1 ZeroAmbient (io.vertx.up.web.ZeroAmbient)1 ZeroAnno (io.vertx.up.web.ZeroAnno)1 Ruler (io.vertx.zero.atom.Ruler)1