Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [ice-dev] Enabling ConnectCoreAction

On 11/30/2016 5:12 PM, Jay Jay Billings wrote:
There's an interesting bug with the Eclipse Resources bundle: It doesn't work with DS-started bundles that require it to be started first. I personally spent weeks sorting this out, and found that the only way to fix it was to take the Core and Client service implementations back to the dark ages and manually register the service.

So, with that in mind, you can easily pull the service for the RSA using a service reference or a service tracker. You can pick which one you need depending on what you know about its lifecycle (i.e. - will you need it for the whole life of the program, etc.?). Lines 194-237 in Client.java show how to use service references:

https://github.com/eclipse/ice/blob/master/org.eclipse.ice.client/src/org/eclipse/ice/client/internal/Client.java

The RemoteServiceAdmin service is only needed when the remote service is actually imported...which is in RSCoreConnectAction line 117.

The main problem with the service reference approach is one of timing: it depends upon the RemoteServiceAdmin service being started before the org.eclipse.ice.client bundle. For that reason I prefer a ServiceTracker...e.g. here's a method that I added to Client class (because it's the BundleActivator for your bundle):


import org.osgi.service.remoteserviceadmin.RemoteServiceAdmin;
import org.osgi.util.tracker.ServiceTracker;

...

    public RemoteServiceAdmin getRSA() {
ServiceTracker<RemoteServiceAdmin,RemoteServiceAdmin> st = new ServiceTracker<RemoteServiceAdmin,RemoteServiceAdmin>(getContext(),RemoteServiceAdmin.class,null);
        st.open();
        RemoteServiceAdmin rsa = st.getService();
        st.close();
        return rsa;
    }

Then line 117 in RSCoreConnectAction can then use getRSA() like this:

reg = (ImportRegistration) Client.getDefault().getRSA().importService(new EndpointDescription(props));


Note too that using DS with classes that are registered or otherwise use static service references works just fine too.

The @Reference in RSCore is static (@Reference defaults to statis), and it works in my tests...i.e. the RemoteServiceAdmin gets injected right away...I think you should be able to use that in org.eclipse.ice.client if you wish.

Scott




Back to the top