This discussion is archived
1 2 Previous Next 17 Replies Latest reply: Sep 28, 2012 12:32 AM by EJP RSS

RMI registry creation issue

893921 Newbie
Currently Being Moderated
An attempt to create more than a single registry in the same VM isl failing.

createRegistry(portNumber) ;

getting
java.rmi.server.ExportException: internal error:
ObjID already in use

java version is 1.6.0_26
  • 1. Re: RMI registry creation issue
    EJP Guru
    Currently Being Moderated
    An attempt to create more than a single registry in the same VM is failing.
    Working as designed. You can't create more than one Registry per JVM. This is because of what it says in the Javadoc: the Registry instance is exported with a well-known object identifier, an ObjID instance constructed with the value ObjID.REGISTRY_ID.'

    You don't need more than one Registry per JVM either.
  • 2. Re: RMI registry creation issue
    893921 Newbie
    Currently Being Moderated
    How to stop the existing running RMI registry and re-start the RMI registry with same port number ? Can i do registry.unbind("xx") and registry.bind("xxx") again for starting the RMI registry on the same port number ?
  • 3. Re: RMI registry creation issue
    EJP Guru
    Currently Being Moderated
    How to stop the existing running RMI registry and re-start the RMI registry with same port number?
    You can do it with UnicastRemoteObject.unexportObject(), supplying the result you got from createRegistry(), but why? Why not just leave it running and bind/rebind/unbind things from it?
    Can i do registry.unbind("xx") and registry.bind("xxx") again for starting the RMI registry on the same port number ?
    That doesn't even make sense. 'registry' is the registry you are trying to stop.
  • 4. Re: RMI registry creation issue
    893921 Newbie
    Currently Being Moderated
    Registry registry = LocateRegistry.createRegistry(1234);
    boolean unexport = true;

    try {
              registry.unbind("jmxrmi");
              UnicastRemoteObject.unexportObject(registry, unexport);
         } catch (NotBoundException e) {
              e.printStackTrace();
         }

    I tried the above code, it gives below mentioned ExportException.

    Caused by: java.rmi.server.ExportException: internal error: ObjID already in use
    [testng] at sun.rmi.transport.ObjectTable.putTarget(ObjectTable.java:169)
    [testng] at sun.rmi.transport.Transport.exportObject(Transport.java:74)
    [testng] at sun.rmi.transport.tcp.TCPTransport.exportObject(TCPTransport.java:229)
    [testng] at sun.rmi.transport.tcp.TCPEndpoint.exportObject(TCPEndpoint.java:393)
    [testng] at sun.rmi.transport.LiveRef.exportObject(LiveRef.java:129)
    [testng] at sun.rmi.server.UnicastServerRef.exportObject(UnicastServerRef.java:190)
    [testng] at sun.rmi.registry.RegistryImpl.setup(RegistryImpl.java:92)
    [testng] at sun.rmi.registry.RegistryImpl.<init>(RegistryImpl.java:78)
    [testng] at java.rmi.registry.LocateRegistry.createRegistry(LocateRegistry.java:186)
  • 5. Re: RMI registry creation issue
    EJP Guru
    Currently Being Moderated
    I tried the above code, it gives below mentioned ExportException.
    So this was the 2nd Registry, so it failed. Of course. Trying to create two Registries in the same JVM isn't going to work, and trying to create a 2nd Registry and then immediately unexport it doesn't make any sense whatsoever. I don't understand any of this. I don't know why you think you need a 2nd Registry at all. You don't.
  • 6. Re: RMI registry creation issue
    893921 Newbie
    Currently Being Moderated
    It is type... not createRegistry(), it is getRegistry(5555)..

    Registry registry = LocateRegistry.getRegistry(5555);
    boolean unexport = true;

    try {
    registry.unbind("jmxrmi");
    UnicastRemoteObject.unexportObject(registry, unexport);
    } catch (NotBoundException e) {
    e.printStackTrace();
    }

    getting same issue.
  • 7. Re: RMI registry creation issue
    EJP Guru
    Currently Being Moderated
    No you aren't. There is nothing in that code that will cause an ExportException. It won't work, for another reason, because you didn't read what I wrote when I told you about unexportObject(). I didn't say a word about getRegistry(). And if it did work, which it can't, it would be 100% redundant to unbind before stopping the Registry.

    It is time for you to stop guessing and explain what this is all about. You just seem to be flailing about aimlessly frankly.
  • 8. Re: RMI registry creation issue
    956480 Newbie
    Currently Being Moderated
    It is in fact possible to create more than one registry in a JVM; just call LocateRegistry.createRegistry(port) with different port numbers. But EJP is right: it is very, very unusual ever to want to create more than one registry within a JVM.

    There is an important clue in your output listing, where each line is prefixed with "[testng]". You're trying to run a bunch of tests that use RMI under TEST-NG, right? If so (and I'm guessing a bit here) then what you should probably do is start up a single registry using a call to LocateRegistry.createRegistry() in your test suite's @BeforeSuite method. Save this reference somewhere. Then, in the @AfterSuite method, unexport the reference to the registry created in @BeforeSuite. Or, if the JVM is going to exit after running the suite, you probably don't need to unexport the registry, since it'll die with the JVM.

    Before each test, in the @BeforeMethod method, create the server object, export it, and bind it into the registry. In the @AfterMethod method, unbind it, unexport it, and (if necessary) destroy any state associated with the server object. Again, I'm guessing, but you probably want to create a fresh server object for each test, so that actions of earlier tests don't affect the results of subsequent tests.
  • 9. Re: RMI registry creation issue
    EJP Guru
    Currently Being Moderated
    It is in fact possible to create more than one registry in a JVM; just call LocateRegistry.createRegistry(port) with different port numbers.
    No it isn't. You get the ExportException that the OP is suffering from. Clearly you haven't actually tried it, nor read the thread properly.
  • 10. Re: RMI registry creation issue
    956480 Newbie
    Currently Being Moderated
    http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4267864

    This bug claims that it's fixed. The test programs work for me (Mac 6u31, Linux 7u6), and they apparently worked for someone named "ejp" (you?) on JDK 1.5 Windows.

    I think the OP is trying to create a second registry on the same port, which does give ExportException.
  • 11. Re: RMI registry creation issue
    EJP Guru
    Currently Being Moderated
    Fancy that. Completely forgot what I wrote five years ago. How unusual ;-)
  • 12. Re: RMI registry creation issue
    956480 Newbie
    Currently Being Moderated
    EJP wrote:
    Fancy that. Completely forgot what I wrote five years ago. How unusual ;-)
    Of course, that never happens to me. :-)

    Thinking further about this issue, it might be that the OP ("890918") doesn't need to start up a registry at all. If all of the tests are indeed running within the same JVM, they can call the stub directly instead of passing it through a registry. Of course, this is all a mystery until the OP tells us what is really going on.
  • 13. Re: RMI registry creation issue
    893921 Newbie
    Currently Being Moderated
    Yes, trying to run a bunch of tests that use RMI under TEST-NG. Still getting Caused by: java.rmi.server.ExportException: internal error: ObjID already in use. I tried UnicastRemoteObject.unexportObject(Registry, true) before binding. Seems still port is not released. It is not default rmi registry port number.


    can call the stub directly instead of passing it through a registry.
    How stub is called directly instead of passing it through a registry ?
  • 14. Re: RMI registry creation issue
    893921 Newbie
    Currently Being Moderated
    In addition to that, All the tests are running in the same JVM.
1 2 Previous Next

Legend

  • Correct Answers - 10 points
  • Helpful Answers - 5 points