Search in sources :

Example 1 with ScheduledExecutorServiceFactory

use of org.apache.aries.blueprint.utils.threading.ScheduledExecutorServiceWrapper.ScheduledExecutorServiceFactory in project aries by apache.

the class BlueprintExtender method start.

public void start(BundleContext ctx) {
    LOGGER.debug("Starting blueprint extender...");
    this.context = ctx;
    boolean useSystemContext = Boolean.parseBoolean(ctx.getProperty("org.apache.aries.blueprint.use.system.context"));
    BundleContext trackingContext = useSystemContext ? ctx.getBundle(Constants.SYSTEM_BUNDLE_LOCATION).getBundleContext() : ctx;
    handlers = new NamespaceHandlerRegistryImpl(trackingContext);
    executors = new ScheduledExecutorServiceWrapper(ctx, "Blueprint Extender", new ScheduledExecutorServiceFactory() {

        public ScheduledExecutorService create(String name) {
            return Executors.newScheduledThreadPool(3, new BlueprintThreadFactory(name));
        }
    });
    eventDispatcher = new BlueprintEventDispatcher(ctx, executors);
    // Ideally we'd want to only track STARTING and ACTIVE bundle, but this is not supported
    // when using equinox composites.  This would ensure that no STOPPING event is lost while
    // tracking the initial bundles. To work around this issue, we need to register
    // a synchronous bundle listener that will ensure the stopping event will be correctly
    // handled.
    context.addBundleListener(this);
    int mask = Bundle.INSTALLED | Bundle.RESOLVED | Bundle.STARTING | Bundle.STOPPING | Bundle.ACTIVE;
    bt = useSystemContext ? new BundleTracker(trackingContext, mask, this) : new RecursiveBundleTracker(ctx, mask, this);
    proxyManager = new SingleServiceTracker<ProxyManager>(ctx, ProxyManager.class, new SingleServiceListener() {

        public void serviceFound() {
            LOGGER.debug("Found ProxyManager service, starting to process blueprint bundles");
            if (bt instanceof BundleTracker) {
                ((BundleTracker) bt).open();
            } else if (bt instanceof RecursiveBundleTracker) {
                ((RecursiveBundleTracker) bt).open();
            }
        }

        public void serviceLost() {
            while (!containers.isEmpty()) {
                for (Bundle bundle : getBundlesToDestroy()) {
                    destroyContainer(bundle);
                }
            }
            if (bt instanceof BundleTracker) {
                ((BundleTracker) bt).close();
            } else if (bt instanceof RecursiveBundleTracker) {
                ((RecursiveBundleTracker) bt).close();
            }
        }

        public void serviceReplaced() {
        }
    });
    proxyManager.open();
    // Determine if the ParserService should ignore unknown namespace handlers
    boolean ignoreUnknownNamespaceHandlers = Boolean.parseBoolean(ctx.getProperty("org.apache.aries.blueprint.parser.service.ignore.unknown.namespace.handlers"));
    // Create and publish a ParserService
    parserServiceReg = ctx.registerService(ParserService.class.getName(), new ParserServiceImpl(handlers, ignoreUnknownNamespaceHandlers), new Hashtable<String, Object>());
    // Create and publish a BlueprintContainerService
    blueprintServiceReg = ctx.registerService(BlueprintExtenderService.class.getName(), new BlueprintContainerServiceImpl(), new Hashtable<String, Object>());
    try {
        ctx.getBundle().loadClass(QUIESCE_PARTICIPANT_CLASS);
        //Class was loaded, register
        quiesceParticipantReg = ctx.registerService(QUIESCE_PARTICIPANT_CLASS, new BlueprintQuiesceParticipant(ctx, this), new Hashtable<String, Object>());
    } catch (ClassNotFoundException e) {
        LOGGER.info("No quiesce support is available, so blueprint components will not participate in quiesce operations");
    }
    LOGGER.debug("Blueprint extender started");
}
Also used : SingleServiceListener(org.apache.aries.util.tracker.SingleServiceTracker.SingleServiceListener) ScheduledExecutorServiceWrapper(org.apache.aries.blueprint.utils.threading.ScheduledExecutorServiceWrapper) Bundle(org.osgi.framework.Bundle) Hashtable(java.util.Hashtable) ProxyManager(org.apache.aries.proxy.ProxyManager) BundleTracker(org.osgi.util.tracker.BundleTracker) RecursiveBundleTracker(org.apache.aries.util.tracker.RecursiveBundleTracker) ScheduledExecutorServiceFactory(org.apache.aries.blueprint.utils.threading.ScheduledExecutorServiceWrapper.ScheduledExecutorServiceFactory) RecursiveBundleTracker(org.apache.aries.util.tracker.RecursiveBundleTracker) BundleContext(org.osgi.framework.BundleContext) NamespaceHandlerRegistryImpl(org.apache.aries.blueprint.namespace.NamespaceHandlerRegistryImpl)

Aggregations

Hashtable (java.util.Hashtable)1 NamespaceHandlerRegistryImpl (org.apache.aries.blueprint.namespace.NamespaceHandlerRegistryImpl)1 ScheduledExecutorServiceWrapper (org.apache.aries.blueprint.utils.threading.ScheduledExecutorServiceWrapper)1 ScheduledExecutorServiceFactory (org.apache.aries.blueprint.utils.threading.ScheduledExecutorServiceWrapper.ScheduledExecutorServiceFactory)1 ProxyManager (org.apache.aries.proxy.ProxyManager)1 RecursiveBundleTracker (org.apache.aries.util.tracker.RecursiveBundleTracker)1 SingleServiceListener (org.apache.aries.util.tracker.SingleServiceTracker.SingleServiceListener)1 Bundle (org.osgi.framework.Bundle)1 BundleContext (org.osgi.framework.BundleContext)1 BundleTracker (org.osgi.util.tracker.BundleTracker)1