Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [ecf-dev] in ECF service client, how to get the ID of a service being added?

Hi David,

David Donohue wrote:
Hello,
My ECF client is using ServiceTracker to be notified of services from
remote servers.  Using generic service.  My method
addingService(ServiceReference reference)
gets called whenever a new service starts up.  In that method, how can
I identify what is the ID/URI of a server that hosts the service?

The OSGi remote services specification does not require/guarantee that the ID/URI of the service host be available via the proxy's service reference.

Having said that, you can/could add the ID as custom service property on registration...e.g. on service host registration:

Properties props = new Properties();
props.put("myHostContainerName",containerID.getName());
context.registerService(svcInterfaces,svcImpl,props);

And then on the receiver side you can/could lookup and use the value of the "myHostContainerName" property e.g.

remoteHostContainerName = reference.getProperty("myHostContainerName");

If you wish, another way with ECF's remote services, you can/could also use the RemoteServiceTracker (class=org.eclipse.ecf.remoteservice.util.tracker.RemoteServiceTracker). The advantage of this is that then you will get the IRemoteServiceReference in the addingService call and be able to access the remote host containerID directly...e.g.

public IRemoteService addingService(IRemoteServiceReference rref) {

ID remoteContainerID = rref.getID().getContainerID();
...Do what you wish with it.


Thanks,

Scott


Thanks,
David Donohue
_______________________________________________
ecf-dev mailing list
ecf-dev@xxxxxxxxxxx
https://dev.eclipse.org/mailman/listinfo/ecf-dev



Back to the top