public void start()

in blueprint/blueprint-core/src/main/java/org/apache/aries/blueprint/container/BlueprintExtender.java [97:184]


    public void start(BundleContext ctx) {
        LOGGER.debug("Starting blueprint extender...");

        this.context = ctx;
        boolean useSystemContext = Boolean.parseBoolean(ctx.getProperty(BlueprintConstants.USE_SYSTEM_CONTEXT_PROPERTY));
        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) {
                int extenderThreads = DEFAULT_NUMBER_OF_THREADS;
                try {
                    extenderThreads = Integer.getInteger(EXTENDER_THREADS_PROPERTY, DEFAULT_NUMBER_OF_THREADS);
                    if (extenderThreads != DEFAULT_NUMBER_OF_THREADS) {
                        LOGGER.debug(EXTENDER_THREADS_PROPERTY + " is set to " + extenderThreads + ".");
                    }
                }
                catch (Exception e) {
                    LOGGER.error(EXTENDER_THREADS_PROPERTY + " is not a number. Using default value " + DEFAULT_NUMBER_OF_THREADS + ".");
                }
                return Executors.newScheduledThreadPool(extenderThreads, new BlueprintThreadFactory(name));
            }
        });
        eventDispatcher = new BlueprintEventDispatcher(ctx);

        // 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(BlueprintConstants.IGNORE_UNKNOWN_NAMESPACE_HANDLERS_PROPERTY));
        // 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");
    }