4 Replies Latest reply on Jun 25, 2010 5:33 AM by Thomas Diesler

    Deployer ordering question (JBoss OSGi)

    David Bosschaert Expert

      In the JBoss OSGi project I have a deployer that adds some metadata to the deployment unit.

       

      In the OSGiBundleState I want to read that metadata out again after the bundle is installed. Currently in the code it initialises that metadata at the beginning of the start() method but that's really too late because you also want to be able to read out the start level of bundles that are just installed.

       

      Is there a callback I can add to OSGiBundleState that gets called after my OSGiStartLevelMetaDataDeployer has run but still as part of the bundle install?

        • 1. Re: Deployer ordering question (JBoss OSGi)
          Ales Justin Master
          In the JBoss OSGi project I have a deployer that adds some metadata to the deployment unit.

          I only see you reading from deployment unit, but not writing.

          In the OSGiBundleState I want to read that metadata out again after the bundle is installed. Currently in the code it initialises that metadata at the beginning of the start() method but that's really too late because you also want to be able to read out the start level of bundles that are just installed.

           

          Is there a callback I can add to OSGiBundleState that gets called after my OSGiStartLevelMetaDataDeployer has run but still as part of the bundle install?

          I don't understand what exactly do you mean / need.

          • 2. Re: Deployer ordering question (JBoss OSGi)
            David Bosschaert Expert

            Ales Justin wrote:

             

            In the JBoss OSGi project I have a deployer that adds some metadata to the deployment unit.

            I only see you reading from deployment unit, but not writing.

             

            {code}   protected void internalDeploy(DeploymentUnit unit) throws DeploymentException

               {

                  StartLevelPlugin slp = bundleManager.getOptionalPlugin(StartLevelPlugin.class);

                  if (slp == null)

                     return;

             

                  OSGiMetaData md = unit.getAttachment(OSGiMetaData.class);

                  if (md instanceof AbstractOSGiMetaData)

                  {

                     AbstractOSGiMetaData amd = (AbstractOSGiMetaData)md;

                     int bsl = slp.getInitialBundleStartLevel(

                           md.getBundleSymbolicName(),

                           Version.parseVersion(md.getBundleVersion()));

             

                     if (bsl != StartLevelPlugin.INITIAL_BUNDLE_STARTLEVEL_UNSPECIFIED)

                     {

                        amd.setInitialStartLevel(bsl);

                     }

                  }

               }{code}

             

            In the very last line I'm writing to the deployment metadata that is already in the deployment unit.

             

            In the OSGiBundleState I want to read that metadata out again after the bundle is installed. Currently in the code it initialises that metadata at the beginning of the start() method but that's really too late because you also want to be able to read out the start level of bundles that are just installed.

             

            Is there a callback I can add to OSGiBundleState that gets called after my OSGiStartLevelMetaDataDeployer has run but still as part of the bundle install?

            I don't understand what exactly do you mean / need.

             

            I need to access this OSGiMetaData in the OSGiBundleState after the bundle was installed but before someone calls start(). I tried overriding changeState() with reacting to the Bundle.INSTALLED change state but that's always called back before my deployer was called (too early).

             

            So I need a callback in the OSGiBundleState that calls me back at the right time so I can initialize the state based on what's in the OSGiMetaData. I couldn't find the right callback for that. Maybe we need to somehow get the OSGiStartLevelMetaDataDeployer to run a bit earlier as well to achieve this, I'm not sure...

            • 3. Re: Deployer ordering question (JBoss OSGi)
              Ales Justin Master
              In the very last line I'm writing to the deployment metadata that is already in the deployment unit.

              Yeah, but deployment metadata != deployment unit. ;-)

              "adds some metadata to the deployment unit."

              ... anyway, never mind, just being picky. :-)

               

              So I need a callback in the OSGiBundleState that calls me back at the right time so I can initialize the state based on what's in the OSGiMetaData. I couldn't find the right callback for that. Maybe we need to somehow get the OSGiStartLevelMetaDataDeployer to run a bit earlier as well to achieve this, I'm not sure...

              I see bundle getting installed in OSGiBundleStateInstallDeployer.

              I guess your deployer just needs to be the next in line?

              • 4. Re: Deployer ordering question (JBoss OSGi)
                Thomas Diesler Master

                In

                 

                /**
                 * [Please add some meaningful javadoc here]
                 * 
                 * @author <a href="david@redhat.com">David Bosschaert</a>
                 */
                public class OSGiStartLevelMetaDataDeployer extends AbstractRealDeployer
                {
                   public OSGiBundleStateInstallDeployer()
                   {
                      super(AbstractBundleState.class);
                      addInput(ClassLoadingMetaData.class);
                      setStage(DeploymentStages.POST_PARSE);
                      setTopLevelOnly(true);
                   }

                 

                you can add some output type to the deployment unit, which you can add to the inputs of

                 

                public class OSGiBundleStateInstallDeployer extends AbstractSimpleRealDeployer<AbstractBundleState>
                {
                   public OSGiBundleStateInstallDeployer()
                   {
                      super(AbstractBundleState.class);
                      addInput(ClassLoadingMetaData.class);
                      setStage(DeploymentStages.POST_PARSE);
                      setTopLevelOnly(true);
                   }

                 

                This would ensure that the SLMDD gets executed before.