Can't start RMI server after stopping it
Asked Answered
T

1

14

I'm having a problem restarting my RMI registry after it has been stopped:

import java.rmi.*;
import java.rmi.registry.*;
import java.rmi.server.UnicastRemoteObject;
import javax.swing.JOptionPane;

public class CinemaServer
{
    private Registry registry;
    ClientImpl clientImple; //remote interface implemented class
    private static String title="Cinema Pvt Ltd";

    public CinemaServer() {
        try {
            clientImple = new ClientImpl();
            registry=LocateRegistry.createRegistry(3311);
            registry.rebind("RMI_INSTANCE", clientImple);
    } catch (RemoteException e) {
            JOptionPane.showMessageDialog(null, "Can't Start RMI Server",title,JOptionPane.ERROR_MESSAGE);
        }
    }

    public void stopServer()
    {
        try {
            registry.unbind("RMI_INSTANCE");
            UnicastRemoteObject.unexportObject(clientImple, true);
        } catch (NotBoundException e) {
            JOptionPane.showMessageDialog(null, "Can't Stop Server",title,JOptionPane.ERROR_MESSAGE);
        }
    }
}
  1. I start the server with: CinemaServer ser=new CinemaServer();

  2. And when I call ser.stopServer(); it stops.

  3. But I cannot restart it

I'm getting:

java.rmi.server.ExportException: internal error: ObjID already in use
at sun.rmi.transport.ObjectTable.putTarget(Unknown Source)
at sun.rmi.transport.Transport.exportObject(Unknown Source)
at sun.rmi.transport.tcp.TCPTransport.exportObject(Unknown Source)
at sun.rmi.transport.tcp.TCPEndpoint.exportObject(Unknown Source)
at sun.rmi.transport.LiveRef.exportObject(Unknown Source)
...
Trichroism answered 13/6, 2011 at 14:57 Comment(7)
Can you paste the error message that you receive? What happens when you try to restart?Aquiline
i am getting "java.rmi.server.ExportException: internal error: ObjID already in use" errorTrichroism
Can you post the stack trace?Ximenez
@mikaveli, sorry but what is "stack trace"?Trichroism
Very basically, it's the full error output of the exception you've encountered.Ximenez
i am only getting "java.rmi.server.ExportException: internal error: ObjID already in use" errorTrichroism
Please replace all your JOptionPane.show... calls with e.printStackTrace(), and copy what you get on the console.Audreyaudri
H
18

the call is failing on createRegistry(), not on re-exporting your object. don't create the registry twice.

Humanism answered 14/6, 2011 at 15:46 Comment(1)
ohhh how did i forget it?thank you @Humanism i solve with your help thanks once againTrichroism

© 2022 - 2024 — McMap. All rights reserved.