Package net.xeoh.plugins.diagnosis.local.options.status

Examples of net.xeoh.plugins.diagnosis.local.options.status.OptionInfo


    /**
     * @param spawnResult
     * @param methods
     */
    private void spawnThreads(final SpawnResult spawnResult, final Method[] methods) {
        log("spawnthreads/start", new OptionInfo("plugin", spawnResult.plugin.getClass().getCanonicalName()));               
       
        for (final Method method : methods) {
            // Init methods will be marked by the corresponding annotation. New:
            // also turn on extended accessibility, so elements don't have to be public
            // anymore.
            method.setAccessible(true);
            final net.xeoh.plugins.base.annotations.Thread annotation = method.getAnnotation(Thread.class);
            if (annotation != null) {

                final java.lang.Thread t = new java.lang.Thread(new Runnable() {

                    public void run() {
                        try {
                            // TODO: Pass kind of ThreadController as argument 1 (or any
                            // fitting argument)
                            method.invoke(spawnResult.plugin, new Object[0]);
                        } catch (final IllegalArgumentException e) {
                            log("spawnthreads/exception/illegalargument", new OptionInfo("method", method.getName()), new OptionInfo("message", e.getMessage()));       
                            e.printStackTrace();
                        } catch (final IllegalAccessException e) {
                            log("spawnthreads/exception/illegalaccess", new OptionInfo("method", method.getName()), new OptionInfo("message", e.getMessage()));       
                            e.printStackTrace();
                        } catch (final InvocationTargetException e) {
                            log("spawnthreads/exception/invocationtargetexception", new OptionInfo("method", method.getName()), new OptionInfo("message", e.getMessage()));       
                            e.printStackTrace();
                        }
                    }
                });

                final String name = spawnResult.plugin.getClass().getName() + "." + method.getName() + "()";
                log("spawnthreads/threadstart", new OptionInfo("plugin", spawnResult.plugin.getClass().getCanonicalName()), new OptionInfo("threadname", name));               
                t.setName(name);
                t.setDaemon(annotation.isDaemonic());
                t.start();

                // Add timer task to list
                spawnResult.metaInformation.threads.add(t);
            }
        }
       
        log("spawnthreads/end", new OptionInfo("plugin", spawnResult.plugin.getClass().getCanonicalName()));               
    }
View Full Code Here


            if (annotation != null) {
                final PluginLoadedInformation pli = new PluginLoadedInformation();
                final Class<?>[] parameterTypes = method.getParameterTypes();

                if (parameterTypes.length != 1) {
                    log("pluginloadedmethods/wrongnumberofparams", new OptionInfo("plugin", spawnResult.plugin.getClass().getCanonicalName())new OptionInfo("method", method.getName()));               
                    continue;
                }

                pli.method = method;
                pli.baseType = (Class<? extends Plugin>) parameterTypes[0];
View Full Code Here

    /**
     * @param spawnResult
     * @param methods
     */
    private void spawnTimer(final SpawnResult spawnResult, final Method[] methods) {
        log("spawntimers/start", new OptionInfo("plugin", spawnResult.plugin.getClass().getCanonicalName()));               

        for (final Method method : methods) {
            // Init methods will be marked by the corresponding annotation. New: also
            // turn on extended accessibility, so elements don't have to be public
            // anymore.
            method.setAccessible(true);
            final net.xeoh.plugins.base.annotations.Timer annotation = method.getAnnotation(Timer.class);
            if (annotation != null) {

                final java.util.Timer t = new java.util.Timer();

                final TimerTask tt = new TimerTask() {

                    @Override
                    public void run() {
                        try {
                            final Object invoke = method.invoke(spawnResult.plugin, new Object[0]);
                            if (invoke != null && invoke instanceof Boolean) {
                                if (((Boolean) invoke).booleanValue()) {
                                    t.cancel();
                                }
                            }
                        } catch (final IllegalArgumentException e) {
                            log("spawntimers/exception/illegalargument", new OptionInfo("method", method.getName()), new OptionInfo("message", e.getMessage()));       
                            e.printStackTrace();
                        } catch (final IllegalAccessException e) {
                            log("spawntimers/exception/illegalaccessexception", new OptionInfo("method", method.getName()), new OptionInfo("message", e.getMessage()));       
                            e.printStackTrace();
                        } catch (final InvocationTargetException e) {
                            log("spawntimers/exception/invocationtargetexception", new OptionInfo("method", method.getName()), new OptionInfo("message", e.getMessage()));       
                            e.printStackTrace();
                        }
                    }
                };

                if (annotation.timerType() == Timer.TimerType.RATE_BASED) {
                    t.scheduleAtFixedRate(tt, annotation.startupDelay(), annotation.period());
                }

                if (annotation.timerType() == Timer.TimerType.DELAY_BASED) {
                    t.schedule(tt, annotation.startupDelay(), annotation.period());
                }

                // Add timer task to list
                spawnResult.metaInformation.timerTasks.add(tt);
                spawnResult.metaInformation.timers.add(t);
            }

        }
       
        log("spawntimers/end", new OptionInfo("plugin", spawnResult.plugin.getClass().getCanonicalName()));               
    }
View Full Code Here

     * net.xeoh.plugins.base.options.AddPluginsFromOption[])
     */
    @Override
    public PluginManager addPluginsFrom(final URI url, final AddPluginsFromOption... options)
    {
        this.diagnosis.channel(PluginManagerTracer.class).status("add/start", new OptionInfo("url", url));
       
        if(url == null) return this;
       
        // Add from the given location
        if (!this.classPathManager.addFromLocation(url, options))
        {
            this.diagnosis.channel(PluginManagerTracer.class).status("add/nohandler", new OptionInfo("url", url));
        }

        // Check if we should print a report?
        if ($(options).get(OptionReportAfter.class, null) != null)
            this.pluginRegistry.report();

        this.diagnosis.channel(PluginManagerTracer.class).status("add/end", new OptionInfo("url", url));
        return this;
    }
View Full Code Here

    public <P extends Plugin> P getPlugin(final Class<P> requestedPlugin,
                                          GetPluginOption... options) {
        // Report our request.
        if (this.diagnosis != null) {
            String name = requestedPlugin == null ? "null" : requestedPlugin.getCanonicalName();
            this.diagnosis.channel(PluginManagerTracer.class).status("get/start", new OptionInfo("plugin", name));
        }

        // We don't handle null values.
        if (requestedPlugin == null) {
            this.diagnosis.channel(PluginManagerTracer.class).status("get/end", new OptionInfo("return", null));
            return null;
        }

        // Sanity check.
        if (!requestedPlugin.isInterface()) {
            this.diagnosis.channel(PluginManagerTracer.class).status("get/onlyinterface", new OptionInfo("plugin", requestedPlugin.getCanonicalName()));
            this.diagnosis.channel(PluginManagerTracer.class).status("get/end", new OptionInfo("return", null));

            System.err.println("YOU MUST NOT call getPlugin() with a concrete class; only interfaces are");
            System.err.println("supported for lookup. This means do not call getPlugin(MyPluginImpl.class),");
            System.err.println("but rather getPlugin(MyPlugin.class)!");
            return null;
        }

        // Used to process the options
        final OptionUtils<GetPluginOption> ou = new OptionUtils<GetPluginOption>(options);

        // We use this one to select the plugin
        PluginSelector<P> pluginSelector = null;

        // Check our options. In case we have a plugin selector, only use the selector
        if (ou.contains(OptionPluginSelector.class)) {
            pluginSelector = ou.get(OptionPluginSelector.class).getSelector();
        } else {
            // Capabilites we require
            final String capabilites[] = ou.get(OptionCapabilities.class, new OptionCapabilities()).getCapabilities();

            // Get caps as list
            final Collection<String> caps = Arrays.asList(capabilites);

            // Create our own selector
            pluginSelector = new PluginSelector<P>() {
                public boolean selectPlugin(final Plugin plugin) {

                    // In case we have caps do special handling and don't return the next
                    // best plugin
                    if (caps.size() > 0) {
                        Collection<String> pcaps = PluginManagerImpl.this.information.getInformation(Information.CAPABILITIES, plugin);

                        // Check the plugin has them all
                        if (pcaps.containsAll(caps)) return true;
                        return false;
                    }

                    return true;
                }
            };
        }

        // Check for each plugin if it matches
        for (final Plugin plugin : this.pluginRegistry.getAllPlugins()) {
            if (this.diagnosis != null)
                this.diagnosis.channel(PluginManagerTracer.class).status("get/considering", new OptionInfo("plugin", plugin.toString()));

            // Check the meta information for this plugin. We only want active classes
            final PluginMetaInformation metaInformation = this.pluginRegistry.getMetaInformationFor(plugin);

            // Plugins not active are not considered
            if (metaInformation.pluginStatus != PluginStatus.ACTIVE) continue;

            // Check if the plugin can be assigned to the requested class
            if (requestedPlugin.isAssignableFrom(plugin.getClass())) {
                if (pluginSelector.selectPlugin((P) plugin)) {
                    if (this.diagnosis != null)
                        this.diagnosis.channel(PluginManagerTracer.class).status("get/end", new OptionInfo("return", plugin.toString()));
                    return (P) plugin;
                }
            }
        }

        if (this.diagnosis != null)
            this.diagnosis.channel(PluginManagerTracer.class).status("get/end", new OptionInfo("return", null));
        return null;
    }
View Full Code Here

            return;
        }

        // Destroy plugins in a random order
        for (final Plugin p : this.pluginRegistry.getAllPlugins()) {
            this.diagnosis.channel(PluginManagerTracer.class).status("shutdown/destroy", new OptionInfo("plugin", p.getClass().getCanonicalName()));
            this.spawner.destroyPlugin(p, this.pluginRegistry.getMetaInformationFor(p));
        }

        // Curtains down, lights out.
        this.pluginRegistry.clear();
View Full Code Here

TOP

Related Classes of net.xeoh.plugins.diagnosis.local.options.status.OptionInfo

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.