Search in sources :

Example 1 with ModifiableThreadPoolConfig

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

the class DefaultThreadPoolManager method deleted.

/**
     * @see org.osgi.service.cm.ManagedServiceFactory#deleted(java.lang.String)
     */
public void deleted(String pid) {
    this.logger.debug("Deleting " + pid);
    // as an anonymous pool with default config(!) if it is used
    synchronized (this.pools) {
        Entry foundEntry = null;
        // we have to search the config by using the pid!
        for (final Entry entry : this.pools.values()) {
            if (pid.equals(entry.getPid())) {
                foundEntry = entry;
                break;
            }
        }
        if (foundEntry != null) {
            this.pools.remove(foundEntry.getName());
            if (foundEntry.isUsed()) {
                // we register this with a new name
                final String name = "ThreadPool-" + UUID.randomUUID().toString();
                foundEntry.update(new ModifiableThreadPoolConfig(), name, null);
                this.pools.put(name, foundEntry);
            }
        }
    }
}
Also used : ModifiableThreadPoolConfig(org.apache.sling.commons.threads.ModifiableThreadPoolConfig)

Example 2 with ModifiableThreadPoolConfig

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

the class HealthCheckExecutorImpl method activate.

@Activate
protected final void activate(final Map<String, Object> properties, final BundleContext bundleContext) {
    this.bundleContext = bundleContext;
    final ModifiableThreadPoolConfig hcThreadPoolConfig = new ModifiableThreadPoolConfig();
    hcThreadPoolConfig.setMaxPoolSize(25);
    hcThreadPool = threadPoolManager.create(hcThreadPoolConfig, "Health Check Thread Pool");
    this.modified(properties);
    try {
        this.bundleContext.addServiceListener(this, "(" + Constants.OBJECTCLASS + "=" + HealthCheck.class.getName() + ")");
    } catch (final InvalidSyntaxException ise) {
        // this should really never happen as the expression above is constant
        throw new RuntimeException("Unexpected exception occured.", ise);
    }
}
Also used : HealthCheck(org.apache.sling.hc.api.HealthCheck) ModifiableThreadPoolConfig(org.apache.sling.commons.threads.ModifiableThreadPoolConfig) InvalidSyntaxException(org.osgi.framework.InvalidSyntaxException) Activate(org.apache.felix.scr.annotations.Activate)

Example 3 with ModifiableThreadPoolConfig

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

the class VotingHandlerTest method setUp.

@Before
public void setUp() throws Exception {
    slingId1 = UUID.randomUUID().toString();
    slingId2 = UUID.randomUUID().toString();
    slingId3 = UUID.randomUUID().toString();
    slingId4 = UUID.randomUUID().toString();
    slingId5 = UUID.randomUUID().toString();
    factory = new DummyResourceResolverFactory();
    resetRepo();
    config = new TestConfig("/var/discovery/impltesting/");
    config.setHeartbeatInterval(999);
    config.setHeartbeatTimeout(60);
    votingHandler1 = VotingHandler.testConstructor(new DummySlingSettingsService(slingId1), factory, config);
    votingHandler2 = VotingHandler.testConstructor(new DummySlingSettingsService(slingId2), factory, config);
    votingHandler3 = VotingHandler.testConstructor(new DummySlingSettingsService(slingId3), factory, config);
    votingHandler4 = VotingHandler.testConstructor(new DummySlingSettingsService(slingId4), factory, config);
    votingHandler5 = VotingHandler.testConstructor(new DummySlingSettingsService(slingId5), factory, config);
    resourceResolver = factory.getServiceResourceResolver(null);
    ModifiableThreadPoolConfig tpConfig = new ModifiableThreadPoolConfig();
    tpConfig.setMinPoolSize(80);
    tpConfig.setMaxPoolSize(80);
    threadPool = new DefaultThreadPool("testing", tpConfig);
}
Also used : DummyResourceResolverFactory(org.apache.sling.discovery.base.its.setup.mock.DummyResourceResolverFactory) TestConfig(org.apache.sling.discovery.impl.setup.TestConfig) DefaultThreadPool(org.apache.sling.commons.threads.impl.DefaultThreadPool) ModifiableThreadPoolConfig(org.apache.sling.commons.threads.ModifiableThreadPoolConfig) DummySlingSettingsService(org.apache.sling.discovery.commons.providers.spi.base.DummySlingSettingsService) Before(org.junit.Before)

Example 4 with ModifiableThreadPoolConfig

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

the class EventingThreadPool method configure.

private void configure(final int maxPoolSize) {
    final ModifiableThreadPoolConfig config = new ModifiableThreadPoolConfig();
    config.setMinPoolSize(maxPoolSize);
    config.setMaxPoolSize(config.getMinPoolSize());
    // unlimited
    config.setQueueSize(-1);
    config.setShutdownGraceful(true);
    config.setPriority(ThreadPriority.NORM);
    config.setDaemon(true);
    this.threadPool = threadPoolManager.create(config, "Apache Sling Job Thread Pool");
}
Also used : ModifiableThreadPoolConfig(org.apache.sling.commons.threads.ModifiableThreadPoolConfig)

Example 5 with ModifiableThreadPoolConfig

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

the class DefaultThreadPoolManager method get.

/**
     * @see org.apache.sling.commons.threads.ThreadPoolManager#get(java.lang.String)
     */
public ThreadPool get(final String name) {
    final String poolName = (name == null ? DEFAULT_THREADPOOL_NAME : name);
    Entry entry = null;
    boolean created = false;
    ThreadPool threadPool = null;
    synchronized (this.pools) {
        entry = this.pools.get(poolName);
        if (entry == null) {
            this.logger.debug("Creating new pool with name {}", poolName);
            final ModifiableThreadPoolConfig config = new ModifiableThreadPoolConfig();
            entry = new Entry(null, config, poolName, bundleContext);
            created = true;
            this.pools.put(poolName, entry);
        }
        threadPool = entry.incUsage();
    }
    if (created) {
        entry.registerMBean();
    }
    return threadPool;
}
Also used : ThreadPool(org.apache.sling.commons.threads.ThreadPool) ModifiableThreadPoolConfig(org.apache.sling.commons.threads.ModifiableThreadPoolConfig)

Aggregations

ModifiableThreadPoolConfig (org.apache.sling.commons.threads.ModifiableThreadPoolConfig)5 Activate (org.apache.felix.scr.annotations.Activate)1 ThreadPool (org.apache.sling.commons.threads.ThreadPool)1 DefaultThreadPool (org.apache.sling.commons.threads.impl.DefaultThreadPool)1 DummyResourceResolverFactory (org.apache.sling.discovery.base.its.setup.mock.DummyResourceResolverFactory)1 DummySlingSettingsService (org.apache.sling.discovery.commons.providers.spi.base.DummySlingSettingsService)1 TestConfig (org.apache.sling.discovery.impl.setup.TestConfig)1 HealthCheck (org.apache.sling.hc.api.HealthCheck)1 Before (org.junit.Before)1 InvalidSyntaxException (org.osgi.framework.InvalidSyntaxException)1