Search in sources :

Example 1 with DefaultThreadPoolManager

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;
}
Also used : DefaultThreadPoolManager(org.apache.sling.commons.threads.impl.DefaultThreadPoolManager) Field(java.lang.reflect.Field) Hashtable(java.util.Hashtable)

Example 2 with DefaultThreadPoolManager

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;
}
Also used : DefaultThreadPoolManager(org.apache.sling.commons.threads.impl.DefaultThreadPoolManager) FailingScheduler(org.apache.sling.discovery.base.its.setup.mock.FailingScheduler) QuartzScheduler(org.apache.sling.commons.scheduler.impl.QuartzScheduler) Scheduler(org.apache.sling.commons.scheduler.Scheduler) QuartzScheduler(org.apache.sling.commons.scheduler.impl.QuartzScheduler) ThreadPoolManager(org.apache.sling.commons.threads.ThreadPoolManager) DefaultThreadPoolManager(org.apache.sling.commons.threads.impl.DefaultThreadPoolManager)

Aggregations

DefaultThreadPoolManager (org.apache.sling.commons.threads.impl.DefaultThreadPoolManager)2 Field (java.lang.reflect.Field)1 Hashtable (java.util.Hashtable)1 Scheduler (org.apache.sling.commons.scheduler.Scheduler)1 QuartzScheduler (org.apache.sling.commons.scheduler.impl.QuartzScheduler)1 ThreadPoolManager (org.apache.sling.commons.threads.ThreadPoolManager)1 FailingScheduler (org.apache.sling.discovery.base.its.setup.mock.FailingScheduler)1