> public class ProductImpl extends UnicastRemoteObject implements Product
You must either change this to 'extends Activatable implements Product',
in which case you should replace the following quoted line by super(id,
0); or else restore the following quoted line as it is:
> //Activatable.exportObject(this , id , 0);
There may be other problems.
Zheng Da - 31 May 2006 11:19 GMT
I change the class ProductImpl as you said.
public class ProductImpl extends Activatable implements Product {
private String name;
private static final long serialVersionUID = 6613571299445532659L;
public ProductImpl(ActivationID id , MarshalledObject object)throws
IOException, ClassNotFoundException{
super(id , 0);
name=(String)object.get();
System.out.println("marshalledobject");
}
public String getDescription() throws RemoteException {
return "I am a " + name + ". Buy me!";
}
}
But I get another exception:
java.rmi.UnmarshalException: Error unmarshaling return header; nested
exception is:
java.io.EOFException
at sun.rmi.transport.StreamRemoteCall.executeCall(Unknown Source)
at sun.rmi.server.UnicastRef.invoke(Unknown Source)
at sun.rmi.server.ActivatableRef.invoke(Unknown Source)
at ProductImpl_Stub.getDescription(Unknown Source)
at ProductClient.main(ProductClient.java:20)
Caused by: java.io.EOFException
at java.io.DataInputStream.readByte(Unknown Source)
... 5 more
> > public class ProductImpl extends UnicastRemoteObject implements Product
>
[quoted text clipped - 5 lines]
>
> There may be other problems.
Zheng Da - 31 May 2006 11:38 GMT
You're right.
But I find that running rmid should be as follow:
rmid -J-Dsun.rmi.activation.execPolicy=none
-J-Djava.security.policy=rmid.policy
And the program cannot run correctly when using
Activatable.exportObject(this , id , 0);
If the ProductImpl is:
public class ProductImpl extends UnicastRemoteObject implements Product
{
private String name;
private static final long serialVersionUID = 6613571299445532659L;
public ProductImpl(ActivationID id , MarshalledObject object)throws
IOException, ClassNotFoundException{
//super(id , 0);
Activatable.exportObject(this , id , 0);
name=(String)object.get();
System.out.println("marshalledobject");
}
public String getDescription() throws RemoteException {
return "I am a " + name + ". Buy me!";
}
}
I still get the exception when the client runs.
java.rmi.activation.ActivateFailedException: failed to activate object;
nested exception is:
java.rmi.activation.ActivationException: exception in object
constructor; nested exception is:
java.rmi.server.ExportException: object already exported
at sun.rmi.server.ActivatableRef.activate(Unknown Source)
at sun.rmi.server.ActivatableRef.invoke(Unknown Source)
at ProductImpl_Stub.getDescription(Unknown Source)
at ProductClient.main(ProductClient.java:20)
Caused by: java.rmi.activation.ActivationException: exception in object
constructor; nested exception is:
java.rmi.server.ExportException: object already exported
at
sun.rmi.server.ActivationGroupImpl.newInstance(ActivationGroupImpl.java:286)
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:324)
at sun.rmi.server.UnicastServerRef.dispatch(UnicastServerRef.java:261)
at sun.rmi.transport.Transport$1.run(Transport.java:148)
at java.security.AccessController.doPrivileged(Native Method)
at sun.rmi.transport.Transport.serviceCall(Transport.java:144)
at
sun.rmi.transport.tcp.TCPTransport.handleMessages(TCPTransport.java:460)
at
sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(TCPTransport.java:701)
at java.lang.Thread.run(Thread.java:534)
at
sun.rmi.transport.StreamRemoteCall.exceptionReceivedFromServer(StreamRemoteCall.java:247)
at
sun.rmi.transport.StreamRemoteCall.executeCall(StreamRemoteCall.java:223)
at sun.rmi.server.UnicastRef.invoke(UnicastRef.java:133)
at java.rmi.activation.ActivationGroup_Stub.newInstance(Unknown
Source)
at
sun.rmi.server.Activation$ObjectEntry.activate(Activation.java:1481)
at sun.rmi.server.Activation$GroupEntry.activate(Activation.java:1132)
at
sun.rmi.server.Activation$ActivatorImpl.activate(Activation.java:262)
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:324)
at sun.rmi.server.UnicastServerRef.dispatch(UnicastServerRef.java:261)
at sun.rmi.transport.Transport$1.run(Transport.java:148)
at java.security.AccessController.doPrivileged(Native Method)
at sun.rmi.transport.Transport.serviceCall(Transport.java:144)
at
sun.rmi.transport.tcp.TCPTransport.handleMessages(TCPTransport.java:460)
at
sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(TCPTransport.java:701)
at java.lang.Thread.run(Thread.java:534)
at
sun.rmi.transport.StreamRemoteCall.exceptionReceivedFromServer(Unknown
Source)
at sun.rmi.transport.StreamRemoteCall.executeCall(Unknown Source)
at sun.rmi.server.UnicastRef.invoke(Unknown Source)
at sun.rmi.server.Activation$ActivatorImpl_Stub.activate(Unknown
Source)
at java.rmi.activation.ActivationID.activate(Unknown Source)
... 4 more
Caused by: java.rmi.server.ExportException: object already exported
at sun.rmi.transport.ObjectTable.putTarget(ObjectTable.java:171)
at sun.rmi.transport.Transport.exportObject(Transport.java:69)
at
sun.rmi.transport.tcp.TCPTransport.exportObject(TCPTransport.java:190)
at
sun.rmi.transport.tcp.TCPEndpoint.exportObject(TCPEndpoint.java:382)
at sun.rmi.transport.LiveRef.exportObject(LiveRef.java:116)
at
sun.rmi.server.UnicastServerRef.exportObject(UnicastServerRef.java:145)
at
sun.rmi.server.UnicastServerRef.exportObject(UnicastServerRef.java:129)
at java.rmi.activation.Activatable.exportObject(Activatable.java:507)
at java.rmi.activation.Activatable.exportObject(Activatable.java:399)
at ProductImpl.<init>(ProductImpl.java:22)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native
Method)
at
sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
at
sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
at java.lang.reflect.Constructor.newInstance(Constructor.java:274)
at
sun.rmi.server.ActivationGroupImpl$1.run(ActivationGroupImpl.java:241)
at java.security.AccessController.doPrivileged(Native Method)
at
sun.rmi.server.ActivationGroupImpl.newInstance(ActivationGroupImpl.java:222)
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:324)
at sun.rmi.server.UnicastServerRef.dispatch(UnicastServerRef.java:261)
at sun.rmi.transport.Transport$1.run(Transport.java:148)
at java.security.AccessController.doPrivileged(Native Method)
at sun.rmi.transport.Transport.serviceCall(Transport.java:144)
at
sun.rmi.transport.tcp.TCPTransport.handleMessages(TCPTransport.java:460)
at
sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(TCPTransport.java:701)
at java.lang.Thread.run(Thread.java:534)
It seems that the server has exported the object, and the client cannot
export it again.
> > public class ProductImpl extends UnicastRemoteObject implements Product
>
[quoted text clipped - 5 lines]
>
> There may be other problems.
EJP - 01 Jun 2006 05:49 GMT
Sorry, my mistake it can't extend UnicastRemoteObject, because that will
automatically export it. Delete those two words, or extend Activatable
and use the super(id,0) in the constructor instead of Activatable.
exportObject(). These two forms are equivalent: the super(id,0) call
just calls Activatable.exportObject for you. There's nothing to choose
between them and certainly no reason to believe that one works better
than the other.
I don't know what's going on with your UnmarshalException. Can you turn
on java.rmi.server.logCalls and the transport logging at rmid and in the
system properties of the activation group, and have a look at what comes
out?
Zheng Da - 01 Jun 2006 08:03 GMT
Thank you.
> Sorry, my mistake it can't extend UnicastRemoteObject, because that will
> automatically export it. Delete those two words, or extend Activatable
[quoted text clipped - 5 lines]
>
> I don't know what's going on with your UnmarshalException. Can you turn
It's my mistake. I forget to specify a policy file when I run rmid.
> on java.rmi.server.logCalls and the transport logging at rmid and in the
> system properties of the activation group, and have a look at what comes
> out?
EJP - 02 Jun 2006 02:50 GMT
Well done. Activation is a pretty little mess and very tricky to conquer.