Package net.xeoh.plugins.base.util

Examples of net.xeoh.plugins.base.util.PluginConfigurationUtil


        // Appears to work(tm).
        ServiceResolver.ANNOUNCE_OVERRIDE = true;

        this.logger.fine("Staring background init");

        final PluginConfigurationUtil pcu = new PluginConfigurationUtil(this.pluginConfiguration);
        this.startupLock = pcu.getInt(RemoteDiscovery.class, "startup.locktime", 1000);
        this.lockMode = pcu.getString(RemoteDiscovery.class, "startup.lockmode", "onepass");

        try {
            this.logger.finer("Locking");

            this.jmdnsLock.lock();
View Full Code Here


    /**
     * Apply things from the config
     */
    @SuppressWarnings("boxing")
    private void applyConfig() {
        final PluginConfigurationUtil pcu = new PluginConfigurationUtil(this.configuration);

        this.jarCache.setEnabled(pcu.getBoolean(PluginManager.class, "cache.enabled", false));

        // Check if we should enable weak mode
        final String mode = pcu.getString(PluginManager.class, "cache.mode", "strong");
        if (mode.equals("weak")) {
            this.jarCache.setWeakMode(true);
        }

    }
View Full Code Here

        // Obtain some shared objects
        //final JARCache jarCache = this.pluginManager.getJARCache();
        final ClassPathManager classPathManager = this.pluginManager.getClassPathManager();
        final PluginRegistry pluginRegistry = this.pluginManager.getPluginRegistry();
        final PluginConfigurationUtil pcu = new PluginConfigurationUtil(this.pluginManager.getPluginConfiguration());
        final Spawner spawner = this.pluginManager.getSpawner();

        // Obtain information
        //final JARInformation jarInformation = jarCache.getJARInformation(name);
        //final String file = jarCache.classTofile(name);

        try {
            // Get class of the candidate
            final Class<?> possiblePlugin = classPathManager.loadClass(location, name);

            // Don't load plugins already spawned.
            if (name.startsWith("net.xeoh.plugins.base")) return;

            // Get the plugin's annotation
            final PluginImplementation annotation = possiblePlugin.getAnnotation(PluginImplementation.class);

            // Nothing to load here if no annotation is present
            if (annotation == null) { return; }

            // Don't load classes already loaded from this location
            final PluggableClassMetaInformation preexistingMeta = pluginRegistry.getMetaInformationFor((Class<? extends Plugin>) possiblePlugin);
            if (preexistingMeta != null) {
                System.err.println("SKIPPING BECAUSE DOUBLE");
                return;
            }

            // Register class at registry
            final PluggableClassMetaInformation metaInformation = new PluggableClassMetaInformation();
            metaInformation.pluginClassStatus = PluginClassStatus.ACCEPTED;
            if (location != null) {
                metaInformation.pluginOrigin = location.getLocation();
            } else {
                metaInformation.pluginOrigin = new URI("classpath://UNDEFINED");
            }
            pluginRegistry.registerPluginClass((Class<? extends Plugin>) possiblePlugin, metaInformation);

            // Update the class information of the corresponding cache entry
            this.logger.finer("Updating cache information");

            /*
            jarInformation.lastAccess = System.currentTimeMillis();
            jarInformation.usageCount++;
            if (!jarInformation.contents.contains(name)) {
                this.logger.finer("Adding " + name + " to cache of " + file);
                jarInformation.contents.add(name);
            }
            */

            // Avoid loading if annotation request it.
            if (pcu.getBoolean(possiblePlugin, "disabled", false) || possiblePlugin.getAnnotation(IsDisabled.class) != null) {
                metaInformation.pluginClassStatus = PluginClassStatus.DISABLED;
                this.logger.fine("Ignoring " + name + " due to request.");
                return;
            }

            // Up from here we know we will (eventually) use the plugin. So load
            // its configuration.           
            final String properties = (possiblePlugin.getAnnotation(ConfigurationFile.class) != null) ? possiblePlugin.getAnnotation(ConfigurationFile.class).configurationFile() : null;
            if (properties != null && properties.length() > 0) {
                final String resourcePath = name.replaceAll("\\.", "/").replaceAll(possiblePlugin.getSimpleName(), "") + properties;
                this.logger.fine("Adding configuration from " + resourcePath + " for plugin " + name);

                final Properties p = new Properties();

                // Try to load resource by special classloader
                try {
                    p.load(classPathManager.getResourceAsStream(location, resourcePath));
                    final Set<Object> keys = p.keySet();

                    // Add every string that is not already in the configuration.
                    for (final Object object : keys) {
                        if (pcu.getString(null, (String) object) == null) {
                            this.pluginManager.getPluginConfiguration().setConfiguration(null, (String) object, p.getProperty((String) object));
                        }
                    }
                } catch (final IOException e) {
                    this.logger.warning("Unable to load properties " + resourcePath + " although requested");
View Full Code Here

TOP

Related Classes of net.xeoh.plugins.base.util.PluginConfigurationUtil

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.