Re: Does unexport() on UnicaseRemoteObject release the port?

Rob Worsnop <[email protected]>
Newsgroups gmane.comp.java.sun.rmi
Message-ID <[email protected]>
Peter,
I'm a colleague of Charlie's. He was posting on my behalf, but I have
now joined the list. Thanks for your help so far.
You asked for some code. I have recreated the problem in a simple MBean.
When I redeploy the MBean, RMI calls createSocket even though the
ServerSocket from the original deployment is still in memory and bound
to port 1000. This call throws an exception, of course, because the
port is in use.
When I don't use a custom RMIServerSocketFactory, everything works OK.

Thanks,
Rob.

public class Example implements ExampleMBean{
    private ExampleService svc;

    public void start() throws Exception {
        try {
            LocateRegistry.createRegistry(999);
        } catch (ExportException e) {
            // happens when redeployed
        }
        svc = new ExampleServiceImpl();
        UnicastRemoteObject.exportObject(svc, 1000, null, new ssf());
        Naming.bind("//localhost:999/example", svc);
    }

    public void stop() throws Exception {
        Naming.unbind("//localhost:999/example");
        UnicastRemoteObject.unexportObject(svc, true);
    }

    private static class ssf implements RMIServerSocketFactory, Serializable{

        public ServerSocket createServerSocket(int port) throws IOException {
            return new ServerSocket(port);
        }
        @Override
        public boolean equals(Object other){
            return true;
        }

        @Override
        public int hashCode(){
            return 1;
        }
    }
}

===========================================================================
To unsubscribe, send email to [email protected] and include in the body
of the message "signoff RMI-USERS".  For general help, send email to
[email protected] and include in the body of the message "help".

For a list of frequently asked RMI questions please refer to:
http://java.sun.com/j2se/1.3/docs/guide/rmi/faq.html

To view past RMI-USERS postings, please see:
http://archives.java.sun.com/archives/rmi-users.html
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.