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);
}
}
}
}
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);
}
}
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);
}
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");
}
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;
}
Aggregations