-1

I am developing a distributed system using a following JAVA RMI setup.

public interface NodeOperations {
 /* RMI methods */
 public FingerTable getFingerTable() throws RMIException;
}

public class Node implements NodeOperations {
 /* Implements all RMI methods */
 /* Also holds a object of FingerTable */
 FingerTable ft;

}

public class FingerTable {
 /* Holds a reference to Node class which has object of 'this' FingerTable */
 Node self;
}

All RMI communication is done via methods present in NodeOperations interface. There is one method which returns FingerTable object for a particular node. However I am getting below exception when I call that method from the client. How do I solve this issue?

java.lang.ClassCastException: cannot assign instance of com.sun.proxy.$Proxy5 to field chord.FingerTable.self of type chord.Node in instance of chord.FingerTable
    at java.io.ObjectStreamClass$FieldReflector.setObjFieldValues(ObjectStreamClass.java:2133)
    at java.io.ObjectStreamClass.setObjFieldValues(ObjectStreamClass.java:1305)
    at java.io.ObjectInputStream.defaultReadFields(ObjectInputStream.java:2237)
    at java.io.ObjectInputStream.readSerialData(ObjectInputStream.java:2155)
    at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:2013)
    at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1535)
    at java.io.ObjectInputStream.defaultReadFields(ObjectInputStream.java:2231)
    at java.io.ObjectInputStream.readSerialData(ObjectInputStream.java:2155)
    at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:2013)
    at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1535)
    at java.io.ObjectInputStream.readObject(ObjectInputStream.java:422)
    at sun.rmi.server.UnicastRef.unmarshalValue(UnicastRef.java:326)
    at sun.rmi.server.UnicastRef.invoke(UnicastRef.java:175)
    at java.rmi.server.RemoteObjectInvocationHandler.invokeRemoteMethod(RemoteObjectInvocationHandler.java:227)
    at java.rmi.server.RemoteObjectInvocationHandler.invoke(RemoteObjectInvocationHandler.java:179)
    at com.sun.proxy.$Proxy5.getNodeInfo(Unknown Source)
    at chord.NodeTest.testTopology(NodeTest.java:108)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
Nullpointer
  • 1,086
  • 7
  • 20

1 Answers1

1
  1. If Node is intended to be a remote object:

    • NodeOperations should extend Remote.
    • Node should extend UnicastRemoteObject or be exported via UnicastRemoteObject.exportObject().
    • NodeOperations.getFingerTable() should be declared to throw RemoteException.
    • You should not have a field of type Node: it should be of type NodeOperations.

    According to the exception, Node already is an exported remote object. So this isn't the real code.

  2. Otherwise, i.e. if you don't want Node to be a remote object, Node should implement Serializable, declare a serialVersionUID member, etc.

  3. Your class definitions seem rather circular. Review them.

user207421
  • 305,947
  • 44
  • 307
  • 483