Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

B&S: How to get the actual RMI Port?

 
Bodenstab Oliver
Ranch Hand
Posts: 47
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hallo,

can somebody tell me how to get the actual RMI Port?

I know i can set it by


But how can i get it if its set?

Thanks for response
 
Darya Akbari
Ranch Hand
Posts: 1855
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Oliver,

you don't need to use the port number again. From here on use Naming.lookup(...) to get your RMI service.

Regards,
Darya
 
Bodenstab Oliver
Ranch Hand
Posts: 47
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Darya,

with Naming.lookup i can get my service.
But i want to know if the registry for rmi is running on an other Port than the user specified before. And of course which port it is.

Thanks for response
 
Darya Akbari
Ranch Hand
Posts: 1855
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Oliver,

I see, you want to know prior to the server start whether the port number specified by the user is already in use or not.

Couldn't you be a little more specific from the begin .

To answer your question, I don't know either

There is a way to get all port numbers in use through the javax.comm packacge but that does not belong to the Java Foundation Classes which we are only allowed to use. So I don't go further here.

On the other hand you can provoke a RemoteException with your createRegistry(1099) call and handle this exception.

Hope other can help :roll:

Regards,
Darya
 
Reza Rahman
author
Ranch Hand
Posts: 580
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Oliver:

Mind if I ask why you need to know this? I might be able to guide you in the right direction provided I know what the goal really is...or are you just curious?

Reza
 
Bodenstab Oliver
Ranch Hand
Posts: 47
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Reza,

the problem i focus is that the user can specify the RMI port for the server. So if the RMI port is still in use on the machine (PC) there is a problem. With the statement
i can set the RMI port if it is not in use. But if the RMI port was set for example on 1100 than i get an exception for the createRegistry statement.
If i get this exception i want to tell the user the RMI port that is in use.

Thanks for response
 
Darya Akbari
Ranch Hand
Posts: 1855
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Oliver,

seems you go with the exception. Is your problem solved ?

Regards,
Darya
 
Reza Rahman
author
Ranch Hand
Posts: 580
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Oliver,

I'm not quite sure if you need this additional info or not, but here goes:

If you notice, createRegistry method throws a RemoteException if the registry "cannot be exported." Take a look at the Javadoc.

The usual reason for this exception is that the RMI registry (or something else) is already running on that port. However, if you really want to make sure, you can use a java.net.ServerSocket to make sure nothing else is running on the user-specified port like this:



However, I honestly believe just catching the RemoteException and telling the user there was a problem starting the registry is more than enough for the assignment.

Also, you should check with a getRegistry call after createRegistry fails to see if the RMI registry is the one that is running on your specified port, or something else (if it is the RMI registry that was running, your job is already done, right?).

Hope this helps. Let me know if you need further clarification...

Reza
[ June 10, 2005: Message edited by: Reza Rahman ]
 
Bodenstab Oliver
Ranch Hand
Posts: 47
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Reza,

i think i do it your way
 
Reza Rahman
author
Ranch Hand
Posts: 580
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Oliver,

You are very welcome. Please re-post if you have any more problems, I'll try to do what I can to help...

Reza
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic