Tuesday, October 7, 2008

Mesh4X J2ME version with JavaRosa XForms

Welcome to Mesh4X !!!

Mesh4X is an open source FeedSync implementation mentored by InSTEDD and developed by Clarius.

InSTEDD is an innovation lab for technologies designed to improve community resilience and save lives through early disease detection and rapid disaster response.

Currently Mesh4x has Java and .Net versions and the Python implementation is coming soon (see waj blog).

There are excellent blogs related to FeedSync and Mesh4X, we can see that the pioneers said:

Currently, sms usage is crucial for humanitarian tasks in the field (see Ed links). Due to this concern, we are working in a mesh4x adapter for sms that allows two-way synchronization of arbitrary data over basic cell phone SMS. Following this direction, in collaboration with JavaRosa, an OpenRosa java implementation which supports XForms for J2ME, we have migrated Mesh4J to J2ME and an experimental version is available here: Mesh4j2me Demo.

The main idea is to provide multi-node XForms editing and sharing on mobile phones (a.k.a. mesh ;)). Imagine the following scenario:

  1. The server is receiving data from multiple mobile clients.
  2. The user enters data on his phone (using JavaRosa XForms).
  3. Upon synchronization, the mobile client updates its local data by merging the the latest changes from the server via an HTTP data connection, and the new local data is pushed to the server the same way.

The server is a FeedSync-standard compliant server we've created with ASP.NET & WCF exposing a RESTFull API (see http://sync.instedd.org/Service.svc/feeds)


Cool! You could share your information with other people in the world. Your data is stored in a centralized server (but which can also be just a node in another mesh!), so you can also view your data from a PC if you want.


Important: You don't need to develop special code for sync, just use the provided Mesh4J2me library.

But, what happens when you do not have an Internet connection but still need to synchronize information in a peer-to-peer fashion? Isn't that the whole point of "mesh"?

Now, we can imagine the following scenario:

  1. Mobile1 - User enters data
  2. Send data from Mobile1 to Mobile2 using sms (with a different adapter this time)
  3. Mobile2 – The data is merged locally executing the sync algorithm
  4. The magic is done! Mobile2 - User has the information available locally in his device.


Cool,... sounds great,  but...., Sms is not a reliable channel, messages can be lost and arrive not necessarily in the same sequence they have been sent.  FeedSync is an XML-based format and it can be very long. How does Mesh4X manage those issues?

The adapter we mentioned above, called the SmsAdapter, defines an asynchronous protocol that provides a reliable connection; the main goal is to ensure that all the messages will arrive, each data is expressed as XML, it is compressed and split in a batch of messages with sequence ordering, and only when all the messages have arrived the XML is regenerated and the next protocol step is executed. Retries are used for re sending lost messages.

The protocol is based on Rsync ideas to send only the differences in data between the mobile phones.

The protocol is a state machine divided in 3 phases:

Phase 1:  Differences negotiation

Phase 2: Data merging

Phase 3: Apply changes to the model


Feel free to take a look at our ideas in:

J2SE: https://mesh4x.googlecode.com/svn/Mesh4j/trunk

J2SE Spikes: https://mesh4x.googlecode.com/svn/Mesh4j/spikes/

J2me: http://code.dimagi.com/svn/JavaRosa/branches/dev-instedd/


In future posts I will explore deeper the Mesh4X project in its both synchronous and asynchronous modes.

What do you think about it?

JMT (Juan Marcelo Tondato)

1 comentarios:

JMT said...

In this blog Eduardo explains the origin of mesh4x: