-
1. Re: JBCACHE-604 - Use of AOPPRoxy class name into streaming
ben.wang May 2, 2006 10:09 PM (in response to clebert.suconic)Clebert,
Like i have mentioned in the email, from PojoCache side, I am not trying to serialize anInstanceOfTheProxy. Instead, I am trying to serializing the Class definition itself (so I can reconstruct the new instance from there). E.g., in terms of cache operation,
put(fqn, key, anInstanceOfAopPoxy.getClass())
Of course, we can argue that I may be able to get around this by simply passing the class name *String*. But that is a different story, IMO. -
2. Re: JBCACHE-604 - Use of AOPPRoxy class name into streaming
clebert.suconic May 2, 2006 10:56 PM (in response to clebert.suconic)I know you are not serializing an instance of the proxy, and that's my whole point.
How can you reconstruct the proxy by its class reference only?
When you serialize that, you are serializing a name, and you will be trusting on the classLoader to give you the correct reference back.
When you ask the classLoader the Proxy by its name, you can get a proxied class on a different class.
You should improve your logic somehow, in such way you never do this:
outObject.writeObject(anInstanceOfAProxy.getClass());
or
outObject.writeUTFanInstanceOfAProxy.getClass().getName());
The JDK don't know how to handle AOPProxies.
I don't know how you are going to fix this. I just know this is an invalid (semanticaly) operation, and I wanted to let you know that.
If you want to discuss options, this is what I think:
I - Serialize an instance of the proxy, since the instance can serialize itself correctly.
II - Put the proxy definition in a wrapper class that will know how to recreate the proxy.
III - Send proxy.getSuperClass() instead, and recreate the proxy from there.
Well.. I don't konw much about POJOCache, so I don't know what's the best approach for you.
But definetly:
put(fqn, key, anInstanceOfAopPoxy.getClass()) ;
can lead you in an error.
You just need to have one of the JVMs creating an AOP proxy before the other. specially now Hibernate is also using AOPProxies, this is not so difficult to happen. -
3. Re: JBCACHE-604 - Use of AOPPRoxy class name into streaming
clebert.suconic May 2, 2006 11:03 PM (in response to clebert.suconic)If you still think I'm wrong, let me translate to you what will happen on java.io.ObjectOUtputStream and INputSTream:
objectOutputStream.writeObject(aopProxy.getClass());
This is the same thing as:
output.writeUTF(theObjectClass.getName());
Class proxyClass = (Class)objectInputStream.readObject()
This is the same thing as:
String className = input.readUTF();
Class proxyClass = theClassLoader.loadClass(className);
So, this is why I'm picking up on the fact you are trusting the classLoader to give you the correct proxy reference. -
4. Re: JBCACHE-604 - Use of AOPPRoxy class name into streaming
clebert.suconic May 2, 2006 11:12 PM (in response to clebert.suconic)Just to complete my point:
if you were saving java.lang.Proxy.getClass(), the history would be completely different.
This is because the JDK (ObjectOUtputSTream) has a special persister:
if (Proxy.isProxy(theClass))
{
//// save the interfaces for later reconstructions
}
ont the read.
Class [] interfaces = readTheInterfaces.
Proxy.buildProxy(interfaces);
The JDK don't know how to save AOPPRoxy classes. -
5. Re: JBCACHE-604 - Use of AOPPRoxy class name into streaming
ben.wang May 2, 2006 11:34 PM (in response to clebert.suconic)Got it. Since I am only sending the Class object to the remote node (for it to reconstruct the no-arg isntance), I can do like your suggestion of proxy.getSuperClass() instead.
Thanks a lot! -
6. Re: JBCACHE-604 - Use of AOPPRoxy class name into streaming
galder.zamarreno May 5, 2006 10:29 PM (in response to clebert.suconic)Could this serialisation be part of the EnhancedTreeCacheMarshaller? We're already improving the way the MethodCalls and other objects are serialised using EnhancedTreeCacheMarshaller.
-
7. Re: JBCACHE-604 - Use of AOPPRoxy class name into streaming
ben.wang May 7, 2006 11:55 PM (in response to clebert.suconic)No, it should not since it is PojoCache specific. I have resolved this issue.