File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Distributed Java and the fly likes Finding the running RMI Server object in the quickest way Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCM Java EE 6 Enterprise Architect Exam Guide this week in the OCMJEA forum!
JavaRanch » Java Forums » Java » Distributed Java
Bookmark "Finding the running RMI Server object in the quickest way" Watch "Finding the running RMI Server object in the quickest way" New topic
Author

Finding the running RMI Server object in the quickest way

Arun Subbu
Greenhorn

Joined: Aug 30, 2003
Posts: 25
Hi,
I have App A that has one remote object. When app A starts, it will regiser the remote object with RMI registry. App will also start multiple instances of another application (lets say App B).

App A is more like a server, but it also has GUI. So my actual problem here is, I should not allow the user to start more than one instance of App A.I have a logic where everytime the user starts app A, first I check the remote object exists, and if so, I bring the previous instance to foucs.(I know we can use file based or socket based mechanisms to control single instance of an application,but those options are ruled out in my case).

To add to the above issue, we can have our product installed on a network share and multiple users can start the app A. In this case I have to start App A for each user.(Meaning register remote object for every user, not just one copy exists in the registry).

On top of these things, we have to register the object to a unique port(not the well-known 1099 ). So I won't know to which port my object was registered when I started the app A for the first time.

Is there anyway(method available in Naming or InitialContext or Registry) where I can issue a single call and it returns(just the name of the object will be enough,not the actual object-looking for more like a object browser service) all the RMI objects registered with RMI registry at the moment and running.

I tried InitialContext.list(), but again it gives all the objects at one port. I want to get all the Remote objects in one call irrespective of the port to which they are bound.

Thanks in Advance
Arun.

PS:Also I am starting the RMI registry programatically using LocateRegistry method, whereas another collegue wants to start it externally by forking a process that will run the registry in separate JVM. What is the best method to start the registry. Also he argues that we should always use the well-known port(1099) but I want to use on a unique port. I read at the following link that starting the registry externally is not advisible.

http://www.javareference.com/jrexamples/viewexample.jsp?id=8
Jeroen Wenting
Ranch Hand

Joined: Oct 12, 2000
Posts: 5093
There isn't.
What you want is a portscanner, not something most people want on their networks.

Your application would have to query all 65 thousand or so ports and check if there's an RMI registry running at them, then get a list of every service running in that registry if there is.
That can take a very long time indeed, and take up a lot of network bandwidth.

Don't go that way, your network admins and your users won't like the results (2 hours startup time for the app, and it eating up the network for all that time are NOT nice).


42
Arun Subbu
Greenhorn

Joined: Aug 30, 2003
Posts: 25
Hi Jeroen,
Thanks for the reply. I am also incling more towards using one specific port be it well-known or the one I choose. I still have one question, how to start the RMI registry,whether programatically using LocateRegistry or in a separate JVM. If I use LocateRegistry, the registry is tied up with the JVM in which my remote object is running. Once I exit my server, the registry also terminates.The problem is, if another remote object has been using the same port(lets assume it was started after my remote object was registered first, it would be using the RMI registry I started programatically) then it becomes unfunctional. Is there anyway to shut down my remote object without affecting the registry so that the other remote objects would still be functional. Also if I have to start the registry in a separate JVM ,what would be the drawback of that.?

Thanks,
Arun.
Jeroen Wenting
Ranch Hand

Joined: Oct 12, 2000
Posts: 5093
You can use unbind to remove an object from a running registry.
There's of course no way to keep the registry alive if you created it programatically and exit the JVM your application is running in.
You might put it in a thread of its own but then your app would not stop until you kill the JVM process
James Carman
Ranch Hand

Joined: Feb 20, 2001
Posts: 580
You could use JINI!


James Carman, President<br />Carman Consulting, Inc.
Jeroen Wenting
Ranch Hand

Joined: Oct 12, 2000
Posts: 5093
The question sounds like something typical to an SCJD assignment. In those JINI isn't allowed
James Carman
Ranch Hand

Joined: Feb 20, 2001
Posts: 580
In that case, we shouldn't be answering anyway! :-)
Arun Subbu
Greenhorn

Joined: Aug 30, 2003
Posts: 25
Hi Guys,
Trust me, I have lot more of work to do than take certification exams .I was also looking into JINI, but I don't know whether my Manager will allow us to use JINI rather than RMI.
James Carman
Ranch Hand

Joined: Feb 20, 2001
Posts: 580
Just tell him that JINI is RMI-based! It really is!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Finding the running RMI Server object in the quickest way