Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[ecf-dev] [Fwd: Getting the running r-OSGi port number before registering a service]

Jan and/or Markus,

Could you please take a look at the newsgroup posting below (on eclipse.technology.ecf)?

It seems to me that it should be possible to force r-osgi to use a specific listener port (given in serverContainer's ID)...and fail upon server container creation and/or server container connect(serverID,null) when the given host/port (e.g. r-osgi://localhost:9278) cannot be opened for listening. Does this make sense?

Thanksinadvance,

Scott



-------- Original Message --------
Path: build.eclipse.org!not-for-mail
From: Anders Forsell <aforsell1971@xxxxxxxxx>
Newsgroups: eclipse.technology.ecf
Subject: Getting the running r-OSGi port number before registering a service
Date: Mon, 8 Sep 2008 14:20:53 +0200
Organization: EclipseCorner
Lines: 53
Message-ID: <ga35b8$sp2$1@xxxxxxxxxxxxxxxxx>
Reply-To: Anders Forsell <aforsell1971@xxxxxxxxx>
NNTP-Posting-Host: nic-se.comsol.se
Mime-Version: 1.0
Content-Type: text/plain; format=flowed; charset="iso-8859-1"; reply-type=original
Content-Transfer-Encoding: 7bit
X-Trace: build.eclipse.org 1220876456 29474 195.242.63.34 (8 Sep 2008 12:20:56 GMT)
X-Complaints-To: news@xxxxxxxxxxxxxxxxx
NNTP-Posting-Date: Mon, 8 Sep 2008 12:20:56 +0000 (UTC)
X-Priority: 3
X-MSMail-Priority: Normal
Importance: Normal
X-Newsreader: Microsoft Windows Live Mail 12.0.1606
X-MimeOLE: Produced By Microsoft MimeOLE V12.0.1606
Xref: build.eclipse.org eclipse.technology.ecf:1220

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







Back to the top