[jboss-dev-forums] [Design of JBossCache] - Re: Common marshalling infrastructure
david.lloyd@jboss.com
do-not-reply at jboss.com
Wed Aug 6 11:54:20 EDT 2008
"manik.surtani at jboss.com" wrote : Re: ref counting, I understand about class data, but as long as instance data is also only written once then that is fine.
|
| Re: version headers, perhaps I could swap ObjectMarshallers midway?
|
| e.g.,
|
|
| | Map<Short, ObjectMarshaller> objectMarshallers = ... ;
| | ByteInput in = new ByteBufferByteInputAdapter(byteBuffer);
| | unmarshaller.start(in);
| | short versionId = (Short) unmarshaller.readObjectUnshared();
| | unmarshaller.setObjectMarshaller( objectMarshallers.get(versionId) );
| | // ...
| | // continue unmarshalling rest of my state
| | // ...
| |
| |
|
Doing a readObject just to get a number could be overkill, maybe something simpler:
| Map<Short, MarshallerFactory> marshallers = ...;
| ByteInput in = ...
| int magic = in.get() << 8 | in.get();
| Unmarshaller unmarshaller = marshallers.get(Short.valueOf(magic)).createUnmarshaller();
| // use unmarshaller to read your state
|
"manik.surtani at jboss.com" wrote : And when marshalling how would object marshallers be selected? I'm guessing a preference for anything that uses magic numbers (how would you denote that an internal class - which *may* implement Externalizable as well - should be marshalled based on a magic number? Another marker interface, perhaps? Or a sub-interface to Externalizable - Marshallable? And if this is not present then test for Externalizable, and then Serializable, etc., and finally falling back to an Externalizer?
The default (I guess) ObjectMarshaller would look for an Externalizer for that object, and if it's found, it would use that, otherwise it would follow the rules for object serialization as they are specified by the JDK. A subclass might add a "tag" byte that says "this is an already-known instance" and return a preset instance.
The default ClassMarshaller would work similarly - it would write a class descriptor per the JDK spec. Similarly a subclass might write a tag byte and magic number for preset classes.
If the object is not a pre-known instance, an ObjectMarshaller or ClassMarshaller could write an "unknown" tag byte and would delegate to the default instance of that interface to take the default action.
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4169089#4169089
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4169089
More information about the jboss-dev-forums
mailing list