Search in sources :

Example 1 with ComponentExecutorFactory

use of org.apache.felix.dm.ComponentExecutorFactory in project felix by apache.

the class TestBase method setUp.

public void setUp() throws Exception {
    warn("Setting up test " + getClass().getName());
    context = FrameworkUtil.getBundle(this.getClass()).getBundleContext();
    Hashtable<String, Object> props = new Hashtable<>();
    props.put(Constants.SERVICE_RANKING, new Integer(Integer.MAX_VALUE));
    logService = context.registerService(LogService.class.getName(), this, props);
    context.addFrameworkListener(this);
    m_dm = new DependencyManager(context);
    if (m_parallel) {
        warn("Using threadpool ...");
        m_threadPool = new ForkJoinPool(Runtime.getRuntime().availableProcessors());
        m_componentExecutorFactoryReg = context.registerService(ComponentExecutorFactory.class.getName(), new ComponentExecutorFactory() {

            @Override
            public Executor getExecutorFor(Component component) {
                return m_threadPool;
            }
        }, null);
    }
}
Also used : Hashtable(java.util.Hashtable) ComponentExecutorFactory(org.apache.felix.dm.ComponentExecutorFactory) DependencyManager(org.apache.felix.dm.DependencyManager) Component(org.apache.felix.dm.Component) ForkJoinPool(java.util.concurrent.ForkJoinPool)

Example 2 with ComponentExecutorFactory

use of org.apache.felix.dm.ComponentExecutorFactory in project felix by apache.

the class TestBase method setUp.

public void setUp() throws Exception {
    warn("Setting up test " + getClass().getName());
    context = FrameworkUtil.getBundle(this.getClass()).getBundleContext();
    Hashtable<String, Object> props = new Hashtable<>();
    props.put(Constants.SERVICE_RANKING, new Integer(Integer.MAX_VALUE));
    logService = context.registerService(LogService.class, this, props);
    context.addFrameworkListener(this);
    m_dm = new DependencyManager(context);
    if (m_parallel) {
        warn("Using threadpool ...");
        m_threadPool = Executors.newFixedThreadPool(Runtime.getRuntime().availableProcessors());
        m_componentExecutorFactoryReg = context.registerService(ComponentExecutorFactory.class.getName(), new ComponentExecutorFactory() {

            @Override
            public Executor getExecutorFor(Component component) {
                return m_threadPool;
            }
        }, null);
    }
}
Also used : Hashtable(java.util.Hashtable) ComponentExecutorFactory(org.apache.felix.dm.ComponentExecutorFactory) DependencyManager(org.apache.felix.dm.DependencyManager) Component(org.apache.felix.dm.Component) LogService(org.osgi.service.log.LogService)

Example 3 with ComponentExecutorFactory

use of org.apache.felix.dm.ComponentExecutorFactory in project felix by apache.

the class TestBase method setUp.

public void setUp() throws Exception {
    warn("Setting up test " + getClass().getName());
    context = FrameworkUtil.getBundle(this.getClass()).getBundleContext();
    Hashtable<String, Object> props = new Hashtable<>();
    props.put(Constants.SERVICE_RANKING, new Integer(Integer.MAX_VALUE));
    logService = context.registerService(LogService.class.getName(), this, props);
    context.addFrameworkListener(this);
    m_dm = new DependencyManager(context);
    if (m_parallel) {
        warn("Using threadpool ...");
        m_threadPool = new ForkJoinPool(Runtime.getRuntime().availableProcessors());
        m_componentExecutorFactoryReg = context.registerService(ComponentExecutorFactory.class.getName(), new ComponentExecutorFactory() {

            @Override
            public Executor getExecutorFor(Component component) {
                return m_threadPool;
            }
        }, null);
    }
}
Also used : Hashtable(java.util.Hashtable) ComponentExecutorFactory(org.apache.felix.dm.ComponentExecutorFactory) DependencyManager(org.apache.felix.dm.DependencyManager) Component(org.apache.felix.dm.Component) ForkJoinPool(java.util.concurrent.ForkJoinPool)

Example 4 with ComponentExecutorFactory

use of org.apache.felix.dm.ComponentExecutorFactory in project felix by apache.

the class ParallelActivator method init.

public void init(BundleContext context, DependencyManager mgr) throws Exception {
    context.registerService(ComponentExecutorFactory.class.getName(), new ComponentExecutorFactory() {

        @Override
        public Executor getExecutorFor(Component component) {
            // Return our thread pool shared for all components
            return Helper.getThreadPool();
        }
    }, null);
    super.init(context, mgr);
}
Also used : Executor(java.util.concurrent.Executor) ComponentExecutorFactory(org.apache.felix.dm.ComponentExecutorFactory) Component(org.apache.felix.dm.Component)

Example 5 with ComponentExecutorFactory

use of org.apache.felix.dm.ComponentExecutorFactory in project felix by apache.

the class ComponentScheduler method mayStartNow.

private boolean mayStartNow(Component c) {
    ComponentExecutorFactory execFactory = m_componentExecutorFactory;
    BundleContext ctx = c.getDependencyManager().getBundleContext();
    String parallel = ctx.getProperty(PARALLEL);
    if (execFactory == null) {
        // prefixes specified in the "parallel" system property.
        if (parallel != null && requiresThreadPool(c, parallel)) {
            // wait for a threadpool
            return false;
        } else {
            // no threadpool required, start the component now, synchronously
            return true;
        }
    } else {
        // classname is starting with one of the prefixes specified in the property.
        if (parallel == null || requiresThreadPool(c, parallel)) {
            createComponentExecutor(execFactory, c);
        }
        // start the component now, possibly using the threadpool (see above).
        return true;
    }
}
Also used : ComponentExecutorFactory(org.apache.felix.dm.ComponentExecutorFactory) BundleContext(org.osgi.framework.BundleContext)

Aggregations

ComponentExecutorFactory (org.apache.felix.dm.ComponentExecutorFactory)5 Component (org.apache.felix.dm.Component)4 Hashtable (java.util.Hashtable)3 DependencyManager (org.apache.felix.dm.DependencyManager)3 ForkJoinPool (java.util.concurrent.ForkJoinPool)2 Executor (java.util.concurrent.Executor)1 BundleContext (org.osgi.framework.BundleContext)1 LogService (org.osgi.service.log.LogService)1