Skip to main content

How to pass a remote object as argument of a remote invokation method?

  1 post   Feedicon  
Replies: 0 - Last Post: April 10, 2012 15:48
by: a_mickael
showing 1 - 1 of 1
Posted: April 10, 2012 15:48 by a_mickael
Hi!

I'm just new on Cajo and Java RMI, and i'm now blocked on a simple problem.
I want to pass a remote object into a method of another remote object. And nothing behaves as I would like.

For instance, here a small testcase:


IRPMyInterface.java
public interface IRPMyInterface {
	String getName();
	boolean isSame(IRPMyInterface obj);
}



RPMyClass.java
public class RPMyClass implements IRPMyInterface {
	public String getName() {
		return "theName";
	}

	public boolean isSame(IRPMyInterface obj) {
		return this.equals(obj);
	}
}



Server.java
public class Server {
	public static void main(String[] args) throws Exception {
		IRPMyInterface obj = new RPMyClass();
		Cajo cajo = new Cajo();
		cajo.export(obj);
	}
}



Client.java
public class Client {
	public static void main(String[] args) throws Exception {
		Cajo cajo = new Cajo();
		Thread.sleep(200);
		Object[] list = cajo.lookup(IRPMyInterface.class);
		IRPMyInterface obj = (IRPMyInterface)cajo.proxy(list[0], IRPMyInterface.class);
		
		Object[] list2 = cajo.lookup(IRPMyInterface.class);
		IRPMyInterface obj2 = (IRPMyInterface)cajo.proxy(list2[0], IRPMyInterface.class);
		
		System.out.println(obj.getName());
		System.out.println(obj.equals(obj));
		System.out.println(obj.equals(obj2));
		System.out.println(obj.isSame(obj));
	}
}



Based on this, I was supposing the following output result:

>theName
>true
>true
>true

But finally I have the following one:
theName
true
false
Exception in thread "main" java.lang.reflect.UndeclaredThrowableException
at $Proxy1.isSame(Unknown Source)
at tst.Client.main(Client.java:19)
Caused by: java.rmi.MarshalException: error marshalling arguments; nested exception is:
java.io.NotSerializableException: gnu.cajo.Cajo
at sun.rmi.server.UnicastRef.invoke(UnicastRef.java:122)
at java.rmi.server.RemoteObjectInvocationHandler.invokeRemoteMethod(RemoteObjectInvocationHandler.java:179)
at java.rmi.server.RemoteObjectInvocationHandler.invoke(RemoteObjectInvocationHandler.java:132)
at $Proxy0.invoke(Unknown Source)
at gnu.cajo.invoke.Remote.invoke(Remote.java:565)
at gnu.cajo.Cajo$Purger.invoke(Cajo.java:119)
at gnu.cajo.invoke.Remote.invoke(Remote.java:565)
at gnu.cajo.utils.extra.TransparentItemProxy.invoke(TransparentItemProxy.java:222)
... 2 more
Caused by: java.io.NotSerializableException: gnu.cajo.Cajo
at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1081)
at java.io.ObjectOutputStream.defaultWriteFields(ObjectOutputStream.java:1375)
at java.io.ObjectOutputStream.writeSerialData(ObjectOutputStream.java:1347)
at java.io.ObjectOutputStream.writeOrdinaryObject(ObjectOutputStream.java:1290)
at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1079)
at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:302)
at java.rmi.MarshalledObject.<init>(MarshalledObject.java:92)
at gnu.cajo.utils.extra.TransparentItemProxy.writeObject(TransparentItemProxy.java:127)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:592)
at java.io.ObjectStreamClass.invokeWriteObject(ObjectStreamClass.java:917)
at java.io.ObjectOutputStream.writeSerialData(ObjectOutputStream.java:1339)
at java.io.ObjectOutputStream.writeOrdinaryObject(ObjectOutputStream.java:1290)
at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1079)
at java.io.ObjectOutputStream.defaultWriteFields(ObjectOutputStream.java:1375)
at java.io.ObjectOutputStream.writeSerialData(ObjectOutputStream.java:1347)
at java.io.ObjectOutputStream.writeOrdinaryObject(ObjectOutputStream.java:1290)
at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1079)
at java.io.ObjectOutputStream.writeArray(ObjectOutputStream.java:1251)
at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1075)
at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:302)
at sun.rmi.server.UnicastRef.marshalValue(UnicastRef.java:258)
at sun.rmi.server.UnicastRef.invoke(UnicastRef.java:117)
... 9 more

First difference seems weird, I would assume that obj2 is identical to obj1.
Second difference seems like a bug or did I make a mistake?

It seems that I missing something concerning the usage of references. Any thoughts concerning this situation?

Thanks!
Mickael
Replies: 0 - Last Post: April 10, 2012 15:48
by: a_mickael
 
 
Close
loading
Please Confirm
Close