Hi there,
I'm writing a RMI application where I need to clean up the RMI registry as soon as the ip address of the server machine changes.
Let's say that I want to make an object (class Obj) accessible from a RMI client through the following code:
Obj obj = new Obj();
UnicastRemoteObject.exportObject(obj,RMIPort); //export the new object
registry = LocateRegistry.createRegistry(RMIPort); //Create a new registry
registry.rebind("myObject", obj); //Bind the object to the registry
Once I detect an ip change I need to clean up the register and I need to publish a new Obj object on it. The new object has to accessible from a RMI client instead of the previous. I tried something like:
UnicastRemoteObject.unexportObject(obj,RMIPort); //unexport the old object
Obj obj2 = new Obj(); //Create a new object
UnicastRemoteObject.exportObject(obj2,RMIPort); //export the new object
registry = LocateRegistry.getRegistry(RMI_PORT);
registry.rebind("myObject", obj2); //Bind the new object to the registry with the same name "myObject"
But when the last line of code is executed, an exception "java.rmi.UnmarshalException: Error Unmarshaling return header" is thrown.
Do you guys have any suggestions?