tisdag 22 januari 2013

An alternative to java serialization

Googling gives you an abundance of suggestions. However you will probably either run into frameworks that require you to make some sort of manual message description files (e.g. protobuffers, which kick ass btw when you don't mind the extra work).

Whether you go the GSON/Jackson JSON route, JBOSS serialization, protobuffers or some xml serialization tool, at least I was never satisfied.

Many tools have issues with generics or just simply issues with a message class declaring a member of typ A and then actually sending that member when it's of type B (which inherits from A).

Buf if you're like me you want to do lots of experiments and not worry about formalities and writing cross communication message description files. Where are the tools for this!? (If you know of any fulfulling my requirements let me know, and I can throw away my own hacks at this ^^)

Here are my requirements:

1. You just want to write your Java classes and be done with it - you know there is enough metadata in Java to serialize the stuff to decent messages - Even when class members are arrays, generics, etc - Java Serialization can do it, you can too!

2. Do not allow cross message referencing, as this puts requirements on nodes remembering previous messages for some time span. Allow references between objects within a single message, but - again - not cross messages.

3. Send no more information with each message than what is absolutely necessary to deserialize it, but DO assume that both end points know the class - If someone wants to send a message of a type only known to one end point, force the user to send the class first.

4. Allow mid point nodes/servers/routers to pass the messages along in any order along any paths, without any repacking/parsing/deserializing! - do not require any guarantees when it comes to ordering or packet loss.

5. Do not enforce a stupid object stream architecture. Let us have a pure Object<->byte[] so that we can use any transport layer.

6. This really is covered by #2, but to make absolutely clear. Maintain ZERO node states between messages. No hidden type or object caches. It's fine between objects that are all within a single message, but NEVER cross messages.

----------------------------------

I wrote such a tool which has about the same serialization times performance as Java's serialization, and about the same message sizes (it's only when you add an extra zip compression layer that the mathematically less information with java serialization becomes apparent - it maintains node states after all, see my previous post).

Though this tool was written in Scala, it can of course be used from java as well. It's a hack, just a quick setup, but it works well enough for me. (https://www.gigurra.se/svn/GEAR/YodaUtils/scala/yodautils/scala/serialization/BinSerializer.scala public/public)

Inga kommentarer:

Skicka en kommentar