protected void onBundleStarted()

in jbi/deployer/src/main/java/org/apache/servicemix/jbi/deployer/impl/Deployer.java [292:343]


    protected void onBundleStarted(Bundle bundle) {
        // If an installer has been registered, this means that we are using JMX or ant tasks to deploy the JBI artifact.
        // In such a case, let the installer do the work.
        // Else, the bundle has been deployed through the deploy folder or the command line or any other
        // non JBI way, which means we need to create an installer and install the artifact now.
        AbstractInstaller installer = getJmxManaged();
        if (installer != null) {
            installers.put(bundle, installer);
        } else {
            ClassLoader cl = Thread.currentThread().getContextClassLoader();
            try {
                Thread.currentThread().setContextClassLoader(getClass().getClassLoader());

                // Check if there is an already existing installer
                // This is certainly the case when a bundle has been stopped and is restarted.
                installer = installers.get(bundle);
                if (installer == null) {
                    URL url = bundle.getResource(DescriptorFactory.DESCRIPTOR_FILE);
                    Descriptor descriptor = DescriptorFactory.buildDescriptor(url);
                    DescriptorFactory.checkDescriptor(descriptor);
                    if (descriptor.getSharedLibrary() != null) {
                        logger.info("Deploying bundle '{}' as a JBI shared library", OsgiStringUtils.nullSafeNameAndSymName(bundle));
                        installer = new SharedLibraryInstaller(this, descriptor, null, true);
                    } else if (descriptor.getComponent() != null) {
                        logger.info("Deploying bundle '{}' as a JBI component", OsgiStringUtils.nullSafeNameAndSymName(bundle));
                        installer = new ComponentInstaller(this, descriptor, null, true);
                    } else if (descriptor.getServiceAssembly() != null) {
                        logger.info("Deploying bundle '{}' as a JBI service assembly", OsgiStringUtils.nullSafeNameAndSymName(bundle));
                        installer = new ServiceAssemblyInstaller(this, descriptor, (File) null, true);
                    } else {
                        throw new IllegalStateException("Unrecognized JBI descriptor: " + url);
                    }
                    installer.setBundle(bundle);
                }

                // TODO: handle the case where the bundle is restarted: i.e. the artifact is already installed
                try {
                    installer.init();
                    installer.install();
                    // only register installer if installation has been successfull
                    installers.put(bundle, installer);
                } catch (PendingException e) {
                    pendingInstallers.add(installer);
                    logger.warn("Requirements not met for JBI artifact in bundle {}. Installation pending. ", OsgiStringUtils.nullSafeNameAndSymName(bundle), e);
                }
            } catch (Exception e) {
                logger.error("Error handling bundle start event", e);
            } finally {
                Thread.currentThread().setContextClassLoader(cl);
            }
        }
    }