1 Reply Latest reply on Dec 8, 2011 4:13 AM by Claus Ibsen

    Singleton in OSGI container

    Eric Bender Newbie

      Is there a standard in regards to deploying a singleton as a JAR within OSGI that can be referenced by deployed camel routes?  Should I just code a singleton, create a jar and deploy it an include it in the camel's osgi bundle imports?  Are singletons a good idea for stateful information within servicemix or should I try to find a stateless method of accomplishing the same thing?

       

      For example I have a route that runs every hour, and I want a singleton to manage and contain the last run time, status, etc that can be leveraged when the route runs again in the future.

        • 1. Re: Singleton in OSGI container
          Claus Ibsen Master

          You want to deploy the singleton bean in another bundle? And refer to this bean from another bundle that has a Camel route?

           

          Instead you could just use a bean in the same bundle as the Camel route, and just define it as a  in the XML file. The scope is by default singleton AFAIR.

           

          You may also want to check out RoutePolicy in Camel

          http://camel.apache.org/routepolicy.html

           

          In Camel 2.9 onwards, we are adding many more lifecycle callbacks to the RoutePolicy such as

          - onStart

          - onStop

          etc.