SafeToClone operations and SafeToCache operations
clebert.suconic Nov 1, 2005 4:52 PM*SafeToClone:* http://jira.jboss.org/jira/browse/JBSER-33
I just implemented a feature on JBossSerialization useful for cloning operations.
Say if you are cloning a Proxy, to guarantee classLoading operations you need to find the interfaces on the new ClassLoader and reuse the ClientContainer used inside the proxy.
The way I was doing that cloning operation before, I was introspecting every single final field on ClientContainer and reusing then. Now, through an interface that I?m calling SafeToClone, we will be able to simply reuse the entire ClientContainer:
org.jboss.invocation.InvokerInterceptor will be then like this:
mv = new LocalMarshalledValue(rtnValue,new SafeCloningRepository(new SafeClone(){
public boolean isSafeToReuse(Object obj) {
if (obj==null)
{
return false;
}
if (obj instanceof ClientContainer)
{
return true;
}
else
{
return false;
}
}
}));
LocalMarshalledValue is a MarshalledValue for JbossSerialization, and a SafeClone interface responsible for intercepting if an object is safe to reuse or not.
*SafeToCache:*
And that gave an idea.
If we could guarantee that ClientContainer was always unique by some primary-key, some UUID, some InvocationContext, whatever, we could cache the interception of ClientContainer somehow and save a lot of CPU for transferring objects.
I have talked to Scott and Adrian during JBoss World Barcelona and I wasn?t sure about how to implement that feature. But now I think we could actually send the streaming and have the parsing cached on both sides, and only necessarily read it for the first time using some sort of UUID.
For taking advantage of that feature, we would need ClientContainer in some kind of caching based on the parameters used, instead of create it every time.
I would create an interface like that, where objects like ClientContainer would be able to implement it:
public interface SafeToCache
{
public String getUUID();
}
Of course we will need to find a UUID routine to use here, but I think that will be the easiest part.
Actually, that idea (caching parsed state) could be used to any reflection like framework, maybe on XML processing as well. (just wondering)
*SafeToClone* is already implemented (http://jira.jboss.org/jira/browse/JBSER-33) while *SafeToCache* for now is just an idea I wanted to brain storm.