6 Replies Latest reply on Jun 4, 2010 3:22 AM by Chongkai Jiang

    How to make my own bundles start after all system bundles?

    Chongkai Jiang Newbie



      I'm using ESB, and having a problem regarding bundle start order.


      I have two bundles placed in the $SERVICEMIX_HOME/deploy directory, but I found both of them and other system bundles all have the same start level of 60, so sometimes my bundles are started up even before other system bundles, which makes my bundles fail to start actually, because they have dependency on the system bundles. (Actually my bundles have small bundle IDs, like 43 or 44, before most system bundles). Even for my own bundles, I wanted one to start after the other because one depends on the other, but the fact is just on the contrary,  and I don't know how to reverse the order!


      So, what configuration can I make to ensure my own bundles start after all system bundles, and ensure one of my bundles starts after the other?


      This is driving me crazy. Thanks for any help...



        • 1. Re: How to make my own bundles start after all system bundles?
          Freeman(Yue) Fang Master



          1.First of all,  you implementation asssume bundle start sequence isn't a good practice in OSGi world.


          2. I can't understand what the system bundle you mean here? Actually the system bundle in OSGi world means the bundle with bundle id 0, it's the OSGi framework core implementation, it's always started at first place. Also we specify other importance service(like log, blueprint, etc) bundles start level  in $SMX_HOME/etc/startup.properties, the start level are all below 60.


          3. For other bundles, the startlevel are all 60, but I don't think they are system bundle(nor important services need get start early)


          4. You mentioned your bundle actually depend on a "System bundle", can you explain how it depend? If it import package from other "System bundle", it won't started before that "system bundle" get started, so shouldn't be a problem at all. It's actually how OSGi works. If your bundle just assume(but no real dependency) some other bundles need start first, honestly it's wrong in OSGi world, you should avoid it.


          5. A work around I can come up with is if your bundle need assume some other "System bundle" start first, you can try to add other "System bundle" as Required-Bundle for your bundle, again, it's not good at all.



          • 2. Re: How to make my own bundles start after all system bundles?
            Chongkai Jiang Newbie

            First of all, to clarify, by "system bundles", I mean the bundles with start level 60 that are installed by default by ESB container, not that System Bundle with ID 0. sorry if this has caused confusion.


            From time to time, I can see the following Exception when Servicemix starts up, but it doesn't appear every time. I understand this may be because my bundle depends on some "system installed bundle" but it is started after mine. But I have found no way of identifying which bundle that should be, so I hoped my bundles can be started after all "system bundles" have been started up. If you can help me with what bundle I should specify as "Require-Bundle", it would be great.


            You can see from the Exception, I have a CXF WS client to send requests.


            Exception in thread "Thread-12" javax.xml.ws.spi.FactoryFinder$ConfigurationError: Provider org.apache.axis2.jaxws.spi.Provider not found

                    at javax.xml.ws.spi.FactoryFinder$2.run(FactoryFinder.java:135)

                    at javax.xml.ws.spi.FactoryFinder.doPrivileged(FactoryFinder.java:273)

                    at javax.xml.ws.spi.FactoryFinder.newInstance(FactoryFinder.java:122)

                    at javax.xml.ws.spi.FactoryFinder.access$200(FactoryFinder.java:42)

                    at javax.xml.ws.spi.FactoryFinder$3.run(FactoryFinder.java:264)

                    at javax.xml.ws.spi.FactoryFinder.doPrivileged(FactoryFinder.java:273)

                    at javax.xml.ws.spi.FactoryFinder.find(FactoryFinder.java:165)

                    at javax.xml.ws.spi.Provider.provider(Provider.java:39)

                    at javax.xml.ws.Service.(WebgwSoapService.java:44)

                    at com.abc.config.ws.Client.doQueries(Client.java:137)

                    at com.abc.config.ws.Client.access$000(Client.java:31)

                    at com.abc.config.ws.Client$1.run(Client.java:82)


            Anyway, I don't think ESB should treat preinstalled bundles and those bundles in deploy directory in the same way. I know bundles are started up in the order of start level, and the order is indeterminate for bundles on the same start level. So there should be some way to let my own bundles start after all system installed bundles, like giving my own bundles higher start levels (like 61, 62).


            Thanks for your time...


            • 3. Re: How to make my own bundles start after all system bundles?
              Freeman(Yue) Fang Master

              Well, about the org.apache.axis2.jaxws.spi.Provider not found, it's a known camel bug, and already get fixed.


              Copy the solution I metioned from previous discussion[2]




              I just provide patch for CAMEL-2528[1] which should fix this issue.


              The workaround currently is that you edit










              Again, in OSGi world, you shouldn't assume bundle start sequence, you can use Import-Package to explicitly add dependency between bundles, which guarantee the bundle start sequence. So I don't think we need provide a way to specify customer bundle start level(actually we have if you specify your bundle in startup.properties, but this is used for key services which really need start at very first place).



              • 4. Re: How to make my own bundles start after all system bundles?
                Chongkai Jiang Newbie

                I saw your post about this before, but, since I don't use camel at all, I don't understand why that would fix the issue.


                But I just now tried to add "META-INF.services" to Import-Package header, and seems it works!


                I now understand that Import-Package is the correct way to specify bundle dependencies, rather than Require-Bundle. I assume ESB thinks Require-Bundle is satisfied as long as the required bundle and the bundle that requires it are on the same start level. For example, one of my own bundles requires a system installed bundle but both of them have start level of 60, then, when ESB startup logic goes up to this start level, it says, OK, your required bundle is there! but it doesn't guarantee the required one will get started completely before the requiring one -- since they are on the same start level, the order is indeterminate. But what really matters is the Import-Package header. Only when the package containing the required package has started up, can the bundle importing the package start up.


                I'm not sure if my understanding is correct, but it's what I got up to now.




                • 5. Re: How to make my own bundles start after all system bundles?
                  Freeman(Yue) Fang Master



                  As we install some camel feature by default, so when you start smx, some camel feature already get involved, the problem is that camel feature introduce a invalid jaxws-api bundle. So even you are not explicitly use camel feature, actually they are there already.



                  • 6. Re: How to make my own bundles start after all system bundles?
                    Chongkai Jiang Newbie

                    I understand. but I'm using The file you mentioned is not there.