Monday, March 29, 2010

Version 1.3 - GWT+GAE - RPC Optimizations

AuDAO allows you to generate Data Transfer Objects (DTOs), which are actuallly POJOs. Also from the beginning of AuDAO these DTO's could be used in Google Web Toolkit (GWT) enabled projects or transfering data between server's and client's code.

Since AuDAO 1.2 we fully support Google App Engine (GAE) types like GeoPt or Key. But it is not enough to support transfering such DTO's - containing these types - between the server and the client.

Fortunately AuDAO 1.3 comes with two features which enable to transfer DTO's containing GAE types - GeoPt, Key, User and others - between the server and the client:

  • generating custom field serializers for GWT

  • basic emulation of the GAE types for GWT (client side code)

GWT Custom Field Serializers

If you use GWT RPC mechanism to transfer data between server and client parts, then GWT serializes and deserializes the Java and JavaScript objects for you automatically. It is similar as standard Java object serialization works.

But it is also possible to write your own (de)serializers. If your DTO class name is, then the (de)serializer class name will be The (de)serializer has several static methods for serializing and deserializing which GWT uses on both the server and the client sides.

The question is why or when to write your own (de)serializer class ? The answer is simple: by writing you own (de)serializer you can compress the data sent between the server and the client. You can save more data if your DTO class contains nested non primitive non-standard fields - like GAE's types: GeoPt or Key. If you know which data you want to send/receive, then you do not need to send also the meta-information like the fully qualified class names or the field names.

Now AuDAO comes with feature of generating these custom (de)serializer classes. Just check the checkbox in the online web generator or enable it by the audao-dto-gwt-serializer option in the standalone version.

My test DTO which contained one long type, one int type, one String type (up to 10 chars length) and one GeoPt had size 270 bytes and after using (de)serializer generated by AuDAO it was only 153 bytes - which means saving of about 44% of network data !

Basic Emulation of the GAE Types

The custom field serializer would not work for GAE types if did not show the source to GWT. GWT needs source to translate it to the JavaScript. GAE itself does not provide sources and even if it do so, we could not use them for GWT due to their complexity and GWT/JavaScript unsupported features.

So as a part of the AuDAO project, we created a basic emulation of these GAE types which you may be interested in - e.g. GeoPt, Key, User and others.

Please be aware of the purpose of these source files - they were created only to support serialization of the GAE types between server and the client. They cannot be used on the server side in any manner - please do not put the compiled classes into your server's classpath - they could conflict with the classes contained in the GAE SDK's jars.

The emulation source files you can find on the AuDAO download page.