use of org.apache.sling.commons.threads.impl.DefaultThreadPoolManager in project sling by apache.
the class ActivatedQuartzSchedulerFactory method create.
public static QuartzScheduler create(BundleContext context, String poolName) throws Exception {
QuartzScheduler quartzScheduler = null;
if (context != null) {
quartzScheduler = new QuartzScheduler();
Dictionary<String, Object> props = new Hashtable<String, Object>();
props.put(Constants.SERVICE_DESCRIPTION, "org.apache.sling.commons.threads.impl.DefaultThreadPoolManager");
props.put(Constants.SERVICE_PID, "org.apache.sling.commons.threads.impl.DefaultThreadPoolManager");
Field f = QuartzScheduler.class.getDeclaredField("threadPoolManager");
f.setAccessible(true);
f.set(quartzScheduler, new DefaultThreadPoolManager(context, props));
final QuartzSchedulerConfiguration configuration = mock(QuartzSchedulerConfiguration.class);
if (poolName == null) {
when(configuration.poolName()).thenReturn("testName");
} else {
final String[] allowedPoolNames = new String[] { "testName", "allowed" };
when(configuration.poolName()).thenReturn(poolName);
when(configuration.allowedPoolNames()).thenReturn(allowedPoolNames);
}
quartzScheduler.activate(context, configuration);
context.registerService("scheduler", quartzScheduler, props);
}
return quartzScheduler;
}
use of org.apache.sling.commons.threads.impl.DefaultThreadPoolManager in project sling by apache.
the class VirtualInstanceBuilder method getSingletonScheduler.
public static Scheduler getSingletonScheduler() throws Exception {
if (singletonScheduler != null) {
return singletonScheduler;
}
final Scheduler newscheduler = new QuartzScheduler();
final ThreadPoolManager tpm = new DefaultThreadPoolManager(null, null);
try {
PrivateAccessor.invoke(newscheduler, "bindThreadPoolManager", new Class[] { ThreadPoolManager.class }, new Object[] { tpm });
} catch (Throwable e1) {
org.junit.Assert.fail(e1.toString());
}
OSGiMock.activate(newscheduler);
singletonScheduler = newscheduler;
return singletonScheduler;
}
Aggregations