4 Replies Latest reply on Mar 13, 2012 12:34 PM by jjakub

    osgi service without restart of projects referencing it

    jjakub

      I am a newbie at camel and service mix osgi and I have a simple question

       

      is it possible to configure

       

      osgi:service

      and

      osgi:reference

       

      so as when bundle with osgi:service is restarted bundles with osgi:reference with it's bean-name wouldn't be restarted?

       

      Now when bundle exposing service is restarted bundles using it are also automatically restarted, I would like to avoid it.

      I am using service mix with spring and camel.

       

      Maybe there is a way to prevent service mix from restarting?

       

       

      Thanks for Your help,

      Regards

        • 1. Re: osgi service without restart of projects referencing it
          ffang

          Hi,

           

          I don't think so.

          And why you need it?

           

          If the service exposing bundle restart, it means the old service it exposed is gone so if the service reference bundle not restart/refresh at the same time, it will cause the service reference bundle doesn't work correctly as it still hold the invalid service reference.

           

          However, I think you can just update the service exposing bundle, this by default will not cause any bundle refresh/restart.

           

          Freeman

          • 2. Re: osgi service without restart of projects referencing it
            jjakub

            We want to get rid of nmr, to be able to use camel standalone without servicemix, as far as I know nmr cannot be used without servicemix. If direct: would work across bundles It would be the best, but direct: doesn't work across bundles.

             

            I want to be able to communicate across bundles. Now we use nmr to communicate across bundles. We replace nmr with osgi service exposed by the target bundle:

             

                private Map<String, String> routeMap;

             

                @Produce

                protected ProducerTemplate producer;

             

                private CamelContext camelContext;

             

                @Override

                public void setCamelContext(CamelContext camelContext) {

                    this.camelContext = camelContext;

                }

             

                @Override

                public CamelContext getCamelContext() {

                    return camelContext;

                }

             

                @Override

                   public void process(Exchange exchange) throws Exception {

             

                    String serviceQName = extractServiceQName(exchange);

                    String uri = routeMap.get(serviceQName);

             

                    CamelContext callerContext = exchange.getContext();

             

                    setExchangeContext(exchange, camelContext);

             

                    producer.send(uri, exchange);

             

                    setExchangeContext(exchange, callerContext);

             

                }

             

            possibly  cardinality="0..1"->  http://static.springsource.org/osgi/docs/1.2.1/reference/html/service-registry.html#service-registry:refs:singular:cardinality    will solve my problem

            • 3. Re: osgi service without restart of projects referencing it
              davsclaus

              People have been using the Camel VM component to communicate across bundles. But note that the VM component was originally not designed for OSGi communication.

               

              OSGi bundles can also communicate directly using OSGi services, so you can export a bean into the OSGi service registry, and then reference that bean from another bundle, and then use that bean.

               

              Then you can use the  in Camel routes to access this bean, and communicate between bundles.

              • 4. Re: osgi service without restart of projects referencing it
                jjakub

                cardinality="0..1" was what I needed

                 

                Thans All for help,