Hello Shailendra,

2. As you are trying to get the service reference in your RCP application, eclipse provides you this in the run configuration. You can specify the start level as well as the auto start there. Like in your case (as much I could understand) your RCP application say "com.test.rcp" is dependent on some OSGI bundle say "com.test.osgi", so in the run configuration of "com.test.rcp" you can define the start level of "com.test.osgi" to say 1 and of "com.test.rcp" to 2. By this way equinox will make sure that bundle "com.test.osgi" will start before "com.test.rcp" bundle.

Damn, that's exactly what I needed. I thought that start level configuration is not possible for Eclipse run configurations but Eclipse Galileo does offer this option now! (or was this also possible in Eclipse 3.4?). Great Shailendra, thank you and all the others for your help! I really appreciate it.

Kind regards,
Eugen


Am Apr 30, 2009 um 16:46  schrieb Shailendra:

Hello Eugen,

I have done something same you are trying to do. I will try to explain what you can do, may be it is helpful.

1. Don't try to start your OSGI bundle within another bundle, framework will do this for you. 2. As you are trying to get the service reference in your RCP application, eclipse provides you this in the run configuration. You can specify the start level as well as the auto start there. Like in your case (as much I could understand) your RCP application say "com.test.rcp" is dependent on some OSGI bundle say "com.test.osgi", so in the run configuration of "com.test.rcp" you can define the start level of "com.test.osgi" to say 1 and of "com.test.rcp" to 2. By this way equinox will make sure that bundle "com.test.osgi" will start before "com.test.rcp" bundle. 3. Also use ServiceTracker to get the service instance. In my case I used to do the following to get the service reference in my activator.

        ServiceTracker tracker = new ServiceTracker(context,
                ServiceInterface.class.getName(), null);
        tracker.open();
        this.service = (ServiceInterface) tracker.getService();
this would definately return you the service implementation reference. If it is not returning you the desired reference that means framework is not able to start the service.
Hope this helps you.

Thanks,
Shailendra


On Thu, Apr 30, 2009 at 7:12 PM, <[email protected]> wrote:
Send osgi-dev mailing list submissions to
        OSGi Users' Forum Belgium
        OSGi Users' Forum China
        OSGi Users' Group France
        OSGi Users' Forum Germany
        OSGi Users' Forum Japan
        OSGi Users' Forum Korea
        OSGi Users' Group Spain
        OSGi Users' Forum Sweden
        OSGi Users' Forum UK
       [email protected]

To subscribe or unsubscribe via the World Wide Web, visit
       https://mail.osgi.org/mailman/listinfo/osgi-dev
or, via email, send a message with subject or body 'help' to
       [email protected]

You can reach the person managing the list at
       [email protected]

When replying, please edit your Subject line so it is more specific
than "Re: Contents of osgi-dev digest..."


Today's Topics:

  1. Certain service registration (Eugen Reiswich)
  2. Re: Certain service registration (Peter Kriens)
  3. Re: Certain service registration (Hal Hildebrand)


----------------------------------------------------------------------

Message: 1
Date: Thu, 30 Apr 2009 09:46:35 +0200
From: Eugen Reiswich <[email protected]>
Subject: [osgi-dev] Certain service registration
To: OSGi Developer Mail List <[email protected]>
Message-ID:
<[email protected] hamburg.de>
Content-Type: text/plain; charset="us-ascii"

Hi OSGi-devs,

I have the following problem with osgi services. We develop basically
applications where dynamic is not an issue. So what I would like to
make sure in my application is that all services are registred
properly at start up - if not, the application will be shut down. In
addition to that I want to reuse my bundles in RCP applications so any
concept must also be applicable for RCP applications.

Say I have two bundles:
1. org.mycompany.service (contains a service interface)
2. org.mycompany.serviceimpl (contains the service implementation and
registers withing his activator an osgi-service)

What we do within the service bundle is this:

public void start(BundleContext context) throws Exception {

       Bundle[] bundles = context.getBundles();
       // find the implementation for the service bundle
       for (Bundle bundle : bundles) {
if ("org.mycompany.serviceimpl".equals(bundle.getSymbolicName())) {
                       // service impl found
                       if (bundle.getState() != Bundle.ACTIVE) {
                               bundle.start();
                       }
               }
       }

       // check if servicimpl has registred service properly
       ServiceReference serviceReference = context
.getServiceReference (IMyService.class.getName());

       if (serviceReference == null) {
               // shut down application

       }
       ...


 From my point of view this is pretty error prone and difficult to
maintain. Is there a best practice approach how I can make sure that
all services are registered properly at start up of my application?
How can I start my serviceimpl bundles in RCP application as no one
depends on this bundle which is why the are never started?

We have spend now a lot of time to find solutions for this problem but
they all seem to be improvable.

Regards,
Eugen
-------------- next part --------------
An HTML attachment was scrubbed...
URL: 
http://mail.osgi.org/pipermail/osgi-dev/attachments/20090430/6d95a9e2/attachment-0001.html

------------------------------

Message: 2
Date: Thu, 30 Apr 2009 15:01:04 +0200
From: Peter Kriens <[email protected]>
Subject: Re: [osgi-dev] Certain service registration
To: OSGi Developer Mail List <[email protected]>
Message-ID: <[email protected]>
Content-Type: text/plain; charset=US-ASCII; format=flowed; delsp=yes

Dynamics are not optional, evert application is dynamic at start up.
The optionally part is reacting to real world events and cleaning up
when you stop.

You create a lot of software for a function that is handled fully
invisible by DS, iPOJO, Spring, dep. manager etc. You're fighting
OSGi, you do not leverage it ... OSGi allows you to work with well
defined dependencies, following the flow it does not cost any user
code. What you're attempting to do is fighting the flow. The dynamic
behavior that OSGi allows is not a primary requirement, it was a
logical consequence of the strong modularity and the service model.

Kind regards,

       Peter Kriens






On 30 apr 2009, at 09:46, Eugen Reiswich wrote:

> Hi OSGi-devs,
>
> I have the following problem with osgi services. We develop
> basically applications where dynamic is not an issue. So what I
> would like to make sure in my application is that all services are
> registred properly at start up - if not, the application will be
> shut down. In addition to that I want to reuse my bundles in RCP
> applications so any concept must also be applicable for RCP
> applications.
>
> Say I have two bundles:
> 1. org.mycompany.service (contains a service interface)
> 2. org.mycompany.serviceimpl (contains the service implementation
> and registers withing his activator an osgi-service)
>
> What we do within the service bundle is this:
>
> public void start(BundleContext context) throws Exception {
>
>       Bundle[] bundles = context.getBundles();
>       // find the implementation for the service bundle
>       for (Bundle bundle : bundles) {
> if ("org.mycompany.serviceimpl".equals(bundle.getSymbolicName())) {
>                       // service impl found
>                       if (bundle.getState() != Bundle.ACTIVE) {
>                               bundle.start();
>                       }
>               }
>       }
>
>       // check if servicimpl has registred service properly
>       ServiceReference serviceReference = context
> .getServiceReference (IMyService.class.getName());
>
>       if (serviceReference == null) {
>               // shut down application
>
>       }
>       ...
>
>
> From my point of view this is pretty error prone and difficult to
> maintain. Is there a best practice approach how I can make sure that
> all services are registered properly at start up of my application?
> How can I start my serviceimpl bundles in RCP application as no one
> depends on this bundle which is why the are never started?
>
> We have spend now a lot of time to find solutions for this problem
> but they all seem to be improvable.
>
> Regards,
> Eugen_______________________________________________
> OSGi Developer Mail List
> [email protected]
> https://mail.osgi.org/mailman/listinfo/osgi-dev



------------------------------

Message: 3
Date: Thu, 30 Apr 2009 06:41:12 -0700
From: Hal Hildebrand <[email protected]>
Subject: Re: [osgi-dev] Certain service registration
To: OSGi Developer Mail List <[email protected]>
Message-ID: <[email protected]>
Content-Type: text/plain; charset="us-ascii"

First, why are you starting the bundles in one of the bundles?  For
one, the frameworks are usually persistent - Equinox certainly is.
So, what you'll find is that the second time you start up the process
- assuming you don't clean the installation- the bundles will already
be started.  So, this is a bad thing to do right off the bat.

Second, as Peter points out, OSGi is a dynamic environment.  So, to
make this robust, not error prone and not difficult to maintain, you
should be using service trackers to get your services.  e.g.


protected void ensureServices(BundleContext context) {
       ServiceTracker tracker = new ServiceTracker(context,
IMyService.class.getCannonicalName(), null);
       tracker.open();
Object myService = tracker.waitForService(60 * 1000); // wait 60
seconds for the service to initialize
       if (myService == null) {
               //  shutdown
       }
}

My third point is that you shouldn't block the Activator.start()
method, so you'd do:

public void start(final BundleContext context) {
       new Thread(new Runnable() {
               public void run() {
                       ensureServices(context);
               }
       }).start();
}


There are more sophisticated things you can do as well, but they all
ground out to much the same thing as above - i.e. looking in the
registry for a service, timing out.

On Apr 30, 2009, at 12:46 AM, Eugen Reiswich wrote:

> Hi OSGi-devs,
>
> I have the following problem with osgi services. We develop
> basically applications where dynamic is not an issue. So what I
> would like to make sure in my application is that all services are
> registred properly at start up - if not, the application will be
> shut down. In addition to that I want to reuse my bundles in RCP
> applications so any concept must also be applicable for RCP
> applications.
>
> Say I have two bundles:
> 1. org.mycompany.service (contains a service interface)
> 2. org.mycompany.serviceimpl (contains the service implementation
> and registers withing his activator an osgi-service)
>
> What we do within the service bundle is this:
>
> public void start(BundleContext context) throws Exception {
>
>       Bundle[] bundles = context.getBundles();
>       // find the implementation for the service bundle
>       for (Bundle bundle : bundles) {
> if ("org.mycompany.serviceimpl".equals(bundle.getSymbolicName())) {
>                       // service impl found
>                       if (bundle.getState() != Bundle.ACTIVE) {
>                               bundle.start();
>                       }
>               }
>       }
>
>       // check if servicimpl has registred service properly
>       ServiceReference serviceReference = context
> .getServiceReference (IMyService.class.getName());
>
>       if (serviceReference == null) {
>               // shut down application
>
>       }
>       ...
>
>
> From my point of view this is pretty error prone and difficult to
> maintain. Is there a best practice approach how I can make sure that
> all services are registered properly at start up of my application?
> How can I start my serviceimpl bundles in RCP application as no one
> depends on this bundle which is why the are never started?
>
> We have spend now a lot of time to find solutions for this problem
> but they all seem to be improvable.
>
> Regards,
> Eugen
> _______________________________________________
> OSGi Developer Mail List
> [email protected]
> https://mail.osgi.org/mailman/listinfo/osgi-dev

-------------- next part --------------
An HTML attachment was scrubbed...
URL: 
http://mail.osgi.org/pipermail/osgi-dev/attachments/20090430/8a48cb8a/attachment.html

------------------------------

_______________________________________________
OSGi Developer Mail List
[email protected]
https://mail.osgi.org/mailman/listinfo/osgi-dev

End of osgi-dev Digest, Vol 30, Issue 28
****************************************



--
Thanks& Regards.
- Shailendra
_______________________________________________
OSGi Developer Mail List
[email protected]
https://mail.osgi.org/mailman/listinfo/osgi-dev

_______________________________________________
OSGi Developer Mail List
[email protected]
https://mail.osgi.org/mailman/listinfo/osgi-dev

Reply via email to