Archive

Archive for the ‘Programming’ Category

On the protocol adopted by Dycapo

March 17th, 2010 bodom_lx 3 comments

It took us more than two months of discussions in order to decide which protocol to adopt for procedure calls in Dycapo.

As we are trying to extend an existing XML-based protocol, the first solution we took in consideration was to implement a remote procedure call protocol based on OpenTrip. That is, directly passing OpenTrip objects over HTTP methods.

Unfortunately, the most elegant solution immediately appeared as unsuitable for those reasons:

  1. It is against the DRY principle, as there exist many other RPC protocols out there
  2. A new RPC protocol implies the creation of new parsers and utilities for (Un)Marshalling data: nobody would write a client for Dycapo if he/she has to implement everything else from scratch
  3. OpenTrip is at a “0.1 draft” status. It may change very often in the future. I would not have the time to create and update parsers and utilities while developing Dycapo.

Therefore, we took the decision to adopt OpenTrip entities and propose OpenTrip Dynamic over some existing protocol. We looked at REST, XML-RPC and SOAP.

REST was seriously taken into consideration, as it is successfully used by Flickr, Delicious, Yahoo and Twitter (and many others). Even if it is not a protocol, it permits to define coincise locations for resources and imposes some rules on the vocabulary used, creating self-descriptive messages. Moreover, there are many Django extensions that support REST.
Unfortunately, I could find more reasons against the adoption of REST than in favor:

  1. It is NOT a protocol but an architecture, or a set of conventions. Therefore, it does not define a format for data exchange. There exist SON, YAML 1.0, YAML 2.0, arbitrary XML formats. Every successful REST-ful WS either defines its own XML format or provides support for all these formats. We would like to be completely architecture independent. Therefore we need a strong data exchange format in order to handle our quite complex objects sent and received by and from clients.
  2. REST is a Resource-Oriented Architecture. Everything is thought around representation of resources. Dycapo implementation would fit with difficulty in this way of thinking. A Service-Oriented Architecture fits our needs and way of thinking.
  3. It may still require a lot of work on the client side caller of the library to make use of data (custom serialization and so forth)

We are not aware of any successful application using REST that needs to pass around complex objects. For example Flickr specifies which parameters must be passed to methods and their format. See an example on this API page.
Our goal in adopting OpenTrip objects was to don’t worry about parameter passing but to just have OpenTrip objects defined in the client, in the server and also inside the databases they keep. Therefore, to have universal objects that can be passed around as parameters.

Regarding XML-RPC and Soap, we know that they are very similar (first drafts of Soap were about XML-RPC with namespaces). After analyzing both of them, we agreed on the adoption of XML-RPC because

  1. It is lighter than SOAP: you just put objects/method calls encoded in XML in HTTP methods. SOAP adds overheads by using namespaces, envelopes, a header, body and fault sections.
  2. It exists since 1998.It is supported by all modern mobile devices, from iPhone to Android to Symbian. Moreover, its data exchange and message formats are very simple. It would be easy even to write a library from scratch. As an example, look at how tiny and simple is android-xmlrpc. SOAP is not widespread on mobile devices as XML-RPC is. Its complexity is also a barrier to write libraries and parsers.
  3. XML-RPC permits us to exchange quite complex objects regardless the implementation of server and clients. It has many data types already available. In particular our OpenTrip objects passed as parameters surely contain arrays and structs. An example could be an array of 4 Locations as part of a Trip object. In Rest we would have needed to decide how to marshall arrays into parameters, and developers would have needed to create their own parsers and serializers.
    Marshalling of data is often possible with XML-RPC. Developers just have to look at our method signature and object structure and forget about the RPC structure and formats. Everything should be automatically handled by existing libraries

We did some tests with available XML-RPC libraries for Java (also Android) and Python (Django). We found that marshalling and unmarshalling of OpenTrip objects is possible, i.e. objects can be serialized and passed via XML-RPC by django and received and deserialized by Java with none or little adjustements.

As a tiny example, look at the following code. It is a snippet of the current method call when searching for a ride. I just included the generated XML-RPC for the second parameter, as the first one is an object of the same type.

dycapo.search_trip ( Location source , Location destination )

< ?xml version=‘1.0′?>
<methodcall>
  <methodname>dycapo.search_trip</methodname>
    <params>
      [..]
      <param>
        <value>
          <struct>
            <member>
              <name>georss_point</name>
              <value><string>1.0,1.0</string></value>
            </member>
            <member>
               <name>point</name>
               <value><string>dest</string></value>
            </member>
            <member>
                <name>leaves</name>
                <value><string>2010-03-12 14:36:54.772156</string></value>
            </member>
            <member>
                <name>label</name>
                <value><string>office</string></value>
            </member>
          </struct>
        </value>
      </param>
    </params>
 </methodcall>
 

See how simple and elegant it is? We are simply passing an object, represented as a struct, with 4 attributes:

  • georss_point: “1.0,1.0″
  • point: “dest”
  • leaves: “2010-03-12 14:36:54.772156″
  • label: “office”

Don’t try to reason about types, names and quality: we are still experimenting.

Related posts

Announcing Pomodroid 0.4.3, some big changes

February 24th, 2010 bodom_lx No comments

The fourth public release of Pomodroid brings some new features and corrections:

  • Fixed bug when rotating the device under a running Pomodoro. Pomodoro Activity is forced to stay in portrait mode
  • Bigger Pomodoro Timer
  • Pomodoro.java completely rewritten. Makes use of Handler and Runnable instead extending CountDownTimer
  • Notification system completely rewritten: user is notified through real Notifications, vibrations and Toasts.
  • The new notification system is also used in PomodroidException.java

The apk is already in the Market.
Everything else can be found in the official project page.

Related posts

Announcing Pomodroid 0.3.0

February 23rd, 2010 bodom_lx No comments

Being encouraged by the 130 downloads nine days after its official release, I’m going to work further on Pomodroid.
This release has a new feature: it permits XML-RPC calls on Trac as anonymous user. This is useful if you have XmlRpcPlugin installed on your trac but don’t have the permissions to use XML-RPC for your user. Pomodroid will work anyway, as it will perform remote calls as anonymous user, but it will query for your user anyway.
Moreover, this release improves the layout of the Pomodoro activity.
I’m always looking for volunteers to cooperate on the project!
Release 0.3.0 is on the market. Sources are on GitHub.

Related posts

Announcing Pomodroid 0.2.1

February 18th, 2010 bodom_lx No comments

A tiny update for the (still) alpha project Pomodroid.
I added some new Power Management features:

  • When running a Pomodoro, the Android phone is prevented from going stand-by. That is, it will never block the screen and go to sleep. The block is released when Pomodoro Activity looses focus.
  • When running a Pomodoro, screen brightness is set at a minimum level to save battery. When Pomodoro either finishes or is broken, screen brightness is restored to its original value

From this version, I am also going to use Semantic Versioning rules.
The APK has already been uploaded to the Market.

Related posts

Improve Pomodroid!

February 18th, 2010 bodom_lx No comments

I am looking for help in improving Pomodroid, the Android Agile Activity manager for the Pomodoro Technique.
It has just been released. The idea behind it is great but there are infinite possible improvements! As example, the possibility to add more sources besides Trac. The user interface can further be improved by a designer. Documentation is scarce. Any kind of help would really appreciated!
See http://wiki.github.com/BodomLx/Pomodroid/project-status for a (tiny) list of help needed.
Contact me if you would like to apply!

Cheers

Related posts

On the automation of API writing and XML-RPC serving for Python Django

November 10th, 2009 bodom_lx No comments

While searching for solutions on adopting Django for the server side of our Dynamic Car Pooling system, I found two very interesting projects:

  • WAPI – a framework which abstracts the details involved in publishing an API and translates class methods to API methods, serializing the objects returned when possible. WAPI handles authentication, too, and other advanced functions. It’s an amazing, fully Django compatible system that currently works over ReST (JSON, XML, YAML) but not with XML-RPC. Therefore, I contacted the author to have some information about the status of the project. It would be very interesting in our system, to provide API and XML-RPC services just by using his layer
  • RPC4Django – provides XML-RPC and JSON-RPC support to an existing Django project. It promises a XML-RPC interface by just adding the decorator @rpcmethod to an existing python function. It also fully integrates with Django authentication framework

I’m going to experiment with these two tools. Obviously the first one is the most interesting because of its ability to “export” services in more formats. But the most important protocol for us is missing. Let’s hope it will be added soon!

Related posts