Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Eclipse Communications Framework (ECF) » Getting the running r-OSGi port number before registering a service
Getting the running r-OSGi port number before registering a service [message #624036] Mon, 08 September 2008 08:20
Anders Forsell is currently offline Anders Forsell
Messages: 120
Registered: July 2009
Senior Member
I have a simple client-server application running where a remote service is
registered by a plug-in in one r-OSGi environment:

ID serverID =
IDFactory.getDefault().createStringID("r-osgi://localhost:9278");
server = ContainerFactory.getDefault().createContainer("ecf.r_osgi.peer ",
new Object[] {serverID});
IRemoteServiceContainerAdapter adapter = (IRemoteServiceContainerAdapter)
server.getAdapter(IRemoteServiceContainerAdapter.class);
adapter.registerRemoteService(new String[]
{IConcatService.class.getName()}, new IConcatService(){
public String concat(String string1, String string2) {
return string1 + string2;
};}, new HashTable());

.... and the client which is running in another r-OSGi environment (different
process same machine) uses the service like this:
ID serverId =
IDFactory.getDefault().createStringID("r-osgi://localhost:9278");
IContainer client =
ContainerFactory.getDefault().createContainer("ecf.r_osgi.peer ", new
Object[] {});
client.connect(serverId, null);
IRemoteServiceContainerAdapter remote = (IRemoteServiceContainerAdapter)
client.getAdapter(IRemoteServiceContainerAdapter.class);
IRemoteServiceReference[] refs = remote.getRemoteServiceReferences(null,
IConcatService.class.getName(),null);
Assert.isTrue(refs.length > 0, "The service has not been started");
IRemoteService service = remote.getRemoteService(refs[0]);
IConcatService serviceProxy =(IConcatService) service.getProxy();
String r = serviceProxy.concat("Anders", "Forsell");

My problem is that if the port 9278 is busy (for example when multiple
r-OSGi servers are running), the next available port will be used by r-OSGi
(ex. 9279).
Thus my "hardcoded" port will not be valid.

How can I determine which port that has been assigned to the running r-OSGi
environment before registering the service ?
I have tried removing the port from the createStringID call like this:
ID serverID =
IDFactory.getDefault().createStringID("r-osgi://localhost");
.... but then the default value of '9278' will be used even if the
environment is using another port.

Thanks,
---
Anders
Previous Topic:ECF conference call RESCHEDULED
Next Topic:How to publish remote services (r-osgi) automatically / discover peers ?
Goto Forum:
  


Current Time: Fri Apr 18 19:34:05 EDT 2014

Powered by FUDForum. Page generated in 0.02094 seconds