Search in sources :

Example 1 with RecursiveBundleTracker

use of org.apache.aries.util.tracker.RecursiveBundleTracker 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)

Example 2 with RecursiveBundleTracker

use of org.apache.aries.util.tracker.RecursiveBundleTracker in project aries by apache.

the class EJBExtender method start.

public void start(BundleContext context) throws Exception {
    //Internal setup
    OSGiTransactionManager.init(context);
    AriesProxyService.init(context);
    try {
        AriesPersistenceContextIntegration.init(context);
    } catch (NoClassDefFoundError ncdfe) {
    //TODO log that no JPA Context integration is available
    }
    //Setup OpenEJB with our own extensions
    setupOpenEJB();
    tracker = new RecursiveBundleTracker(context, Bundle.INSTALLED | Bundle.RESOLVED | Bundle.STARTING | Bundle.ACTIVE | Bundle.STOPPING, this);
    tracker.open();
}
Also used : RecursiveBundleTracker(org.apache.aries.util.tracker.RecursiveBundleTracker)

Example 3 with RecursiveBundleTracker

use of org.apache.aries.util.tracker.RecursiveBundleTracker in project aries by apache.

the class BlueprintExtender method stop.

public void stop(BundleContext context) {
    LOGGER.debug("Stopping blueprint extender...");
    stopping = true;
    ServiceUtil.safeUnregisterService(parserServiceReg);
    ServiceUtil.safeUnregisterService(blueprintServiceReg);
    ServiceUtil.safeUnregisterService(quiesceParticipantReg);
    // Orderly shutdown of containers
    while (!containers.isEmpty()) {
        for (Bundle bundle : getBundlesToDestroy()) {
            destroyContainer(bundle);
        }
    }
    if (bt instanceof BundleTracker) {
        ((BundleTracker) bt).close();
    } else if (bt instanceof RecursiveBundleTracker) {
        ((RecursiveBundleTracker) bt).close();
    }
    proxyManager.close();
    this.eventDispatcher.destroy();
    this.handlers.destroy();
    executors.shutdown();
    LOGGER.debug("Blueprint extender stopped");
}
Also used : Bundle(org.osgi.framework.Bundle) RecursiveBundleTracker(org.apache.aries.util.tracker.RecursiveBundleTracker) BundleTracker(org.osgi.util.tracker.BundleTracker) RecursiveBundleTracker(org.apache.aries.util.tracker.RecursiveBundleTracker)

Aggregations

RecursiveBundleTracker (org.apache.aries.util.tracker.RecursiveBundleTracker)3 Bundle (org.osgi.framework.Bundle)2 BundleTracker (org.osgi.util.tracker.BundleTracker)2 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 SingleServiceListener (org.apache.aries.util.tracker.SingleServiceTracker.SingleServiceListener)1 BundleContext (org.osgi.framework.BundleContext)1