I have an RMI's remote interface:
public interface JMXManager extends Remote {
public MFSMBeanServerConnection getMBeanServerConnection(String className)
throws RemoteException;
}
}
MFSMBeanServerConnection
and MFSMBeanServerConnectionImpl
that I created in order to serialize MBeanServerConnection:
public interface MFSMBeanServerConnection extends Serializable {
public MBeanServerConnection getMBeanServerConnection();
}
public class MFSMBeanServerConnectionImpl implements MFSMBeanServerConnection {
private static final long serialVersionUID = 1006978249744538366L;
/**
* @serial
*/
private MBeanServerConnection mBeanServerConnection;
public MFSMBeanServerConnectionImpl() {}
public MFSMBeanServerConnectionImpl(MBeanServerConnection mBeanServerConnection) {
this.mBeanServerConnection = mBeanServerConnection;
}
public MBeanServerConnection getMBeanServerConnection() {
return mBeanServerConnection;
}
private void readObject(ObjectInputStream aInputStream) throws ClassNotFoundException,
IOException {
aInputStream.defaultReadObject();
mBeanServerConnection = (MBeanServerConnection) aInputStream.readObject();
}
private void writeObject(ObjectOutputStream aOutputStream) throws IOException {
aOutputStream.defaultWriteObject();
aOutputStream.writeObject(mBeanServerConnection);
}
private void readObjectNoData() throws ObjectStreamException {
}
}
On the client side I have
JMXManager jmxm= (JMXManager) registry.lookup("JMXManager");
MFSMBeanServerConnection mfsMbsc = jmxm.getMBeanServerConnection(className);
on the second line I get an Exception:
java.rmi.UnmarshalException: error unmarshalling return; nested exception is:
java.io.WriteAbortedException: writing aborted; java.io.NotSerializableException: javax.management.remote.rmi.RMIConnector$RemoteMBeanServerConnection
at sun.rmi.server.UnicastRef.invoke(UnicastRef.java:173)
at java.rmi.server.RemoteObjectInvocationHandler.invokeRemoteMethod(RemoteObjectInvocationHandler.java:178)
at java.rmi.server.RemoteObjectInvocationHandler.invoke(RemoteObjectInvocationHandler.java:132)
at $Proxy0.getMBeanServerConnection(Unknown Source)
My goal is to create an RMI Server that:
What I am doing wrong? How can I serialze javax.management.MBeanServerConnection so that I can use it with an remote interface?
I think its a bad idea to Serialize MBeanServerConnection because it is supposed to store a lot of Run Time Information/Some information which will not be available or valid when you deserialize it.
It think that is reason that all its known SubInterfaces ( MBeanServer, MBeanServerForwarder) also do not implement Serializable.