Search in sources :

Example 1 with ThreadPoolConfig

use of org.apache.sling.commons.threads.ThreadPoolConfig in project sling by apache.

the class DefaultThreadPoolManager method updated.

/**
     * @see org.osgi.service.cm.ManagedServiceFactory#updated(java.lang.String, java.util.Dictionary)
     */
@SuppressWarnings({ "unchecked", "rawtypes" })
public void updated(String pid, Dictionary properties) throws ConfigurationException {
    final String name = (String) properties.get(ModifiableThreadPoolConfig.PROPERTY_NAME);
    if (name == null || name.length() == 0) {
        throw new ConfigurationException(ModifiableThreadPoolConfig.PROPERTY_NAME, "Property is missing or empty.");
    }
    this.logger.debug("Updating {} with {}", pid, properties);
    Entry createdEntry = null;
    synchronized (this.pools) {
        final ThreadPoolConfig config = this.createConfig(properties);
        Entry foundEntry = null;
        // we have to search the config by using the pid first!
        for (final Entry entry : this.pools.values()) {
            if (pid.equals(entry.getPid())) {
                foundEntry = entry;
                break;
            }
        }
        // if we haven't found it by pid we search by name
        if (foundEntry == null) {
            for (final Entry entry : this.pools.values()) {
                if (name.equals(entry.getName())) {
                    foundEntry = entry;
                    break;
                }
            }
        }
        if (foundEntry != null) {
            // if the name changed - we have to reregister(!)
            if (!name.equals(foundEntry.getName())) {
                this.pools.remove(foundEntry.getName());
                this.pools.put(name, foundEntry);
            }
            // update
            foundEntry.update(config, name, pid);
        } else {
            // create
            createdEntry = new Entry(pid, config, name, bundleContext);
            this.pools.put(name, createdEntry);
        }
    }
    if (createdEntry != null) {
        createdEntry.registerMBean();
    }
}
Also used : ConfigurationException(org.osgi.service.cm.ConfigurationException) ModifiableThreadPoolConfig(org.apache.sling.commons.threads.ModifiableThreadPoolConfig) ThreadPoolConfig(org.apache.sling.commons.threads.ThreadPoolConfig)

Example 2 with ThreadPoolConfig

use of org.apache.sling.commons.threads.ThreadPoolConfig in project sling by apache.

the class WebConsolePrinter method printConfiguration.

/**
     * Print out the servlet filter chains.
     * @see org.apache.felix.webconsole.ConfigurationPrinter#printConfiguration(java.io.PrintWriter)
     */
public void printConfiguration(PrintWriter pw) {
    pw.println(HEADLINE);
    pw.println();
    final DefaultThreadPoolManager.Entry[] configs = this.mgr.getConfigurations();
    if (configs.length > 0) {
        for (final DefaultThreadPoolManager.Entry entry : configs) {
            final ThreadPoolConfig config = entry.getConfig();
            pw.print("Pool ");
            pw.println(entry.getName());
            if (entry.getPid() != null) {
                pw.print("- from configuration : ");
                pw.println(entry.getPid());
            }
            pw.print("- used : ");
            pw.println(entry.isUsed());
            pw.print("- min pool size : ");
            pw.println(config.getMinPoolSize());
            pw.print("- max pool size : ");
            pw.println(config.getMaxPoolSize());
            pw.print("- queue size : ");
            pw.println(config.getQueueSize());
            pw.print("- keep alive time : ");
            pw.println(config.getKeepAliveTime());
            pw.print("- block policy : ");
            pw.println(config.getBlockPolicy());
            pw.print("- priority : ");
            pw.println(config.getPriority());
            pw.print("- shutdown graceful : ");
            pw.println(config.isShutdownGraceful());
            pw.print("- shutdown wait time : ");
            pw.println(config.getShutdownWaitTimeMs());
            pw.print("- daemon : ");
            pw.println(config.isDaemon());
            final ThreadPoolExecutor tpe = entry.getExecutor();
            if (tpe != null) {
                pw.print("- active count : ");
                pw.println(tpe.getActiveCount());
                pw.print("- completed task count : ");
                pw.println(tpe.getCompletedTaskCount());
                pw.print("- core pool size : ");
                pw.println(tpe.getCorePoolSize());
                pw.print("- largest pool size : ");
                pw.println(tpe.getLargestPoolSize());
                pw.print("- maximum pool size : ");
                pw.println(tpe.getMaximumPoolSize());
                pw.print("- pool size : ");
                pw.println(tpe.getPoolSize());
                pw.print("- task count : ");
                pw.println(tpe.getTaskCount());
            }
            pw.println();
        }
    } else {
        pw.println("No pools configured.");
    }
}
Also used : ThreadPoolConfig(org.apache.sling.commons.threads.ThreadPoolConfig) ThreadPoolExecutor(java.util.concurrent.ThreadPoolExecutor)

Aggregations

ThreadPoolConfig (org.apache.sling.commons.threads.ThreadPoolConfig)2 ThreadPoolExecutor (java.util.concurrent.ThreadPoolExecutor)1 ModifiableThreadPoolConfig (org.apache.sling.commons.threads.ModifiableThreadPoolConfig)1 ConfigurationException (org.osgi.service.cm.ConfigurationException)1