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.
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).
posted 14 years ago
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.?
posted 14 years ago
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