View source | Discuss this page | Page history | Printable version   
Main Page
Upload file
What links here
Recent changes

PDF Books
Add page
Show collection (0 pages)
Collections help


How to Write Online Transition Handlers



This howto gives insight in how to write store status aware logic which handles requests. This is logic which allows you to write code that behaves differently depending on the status of the store or central server.

Before starting this howto make sure to read the howto setup a dev environment. It also makes sense to have a clear understanding of the states of an Openbravo Commerce server (offline, online, transitioning etc.).

Also the howto assumes that the reader is familiar with the main concepts/information provided by the retail developers guide.

Installing the how to module

The examples provided in this howto can be found in the Store Server Howto module. The howto module can be downloaded using the hg clone command in the modules directory:

 hg clone

After this execute the 'ant smartbuild -Dlocal=no' command in the main project directory.

Online Transition Handlers

The idea for online transition handlers is that they are called when the server transitions back to the online status. During offline status, transactions can be stored on the server. These transactions should potentially be send to the central server. The online transition handlers provide a hook to implement this type of logic.

An online transition handler only needs to extend the MobileServerTransitionToOnlineHandler class and implement 2 methods:

Example code 1

The code snippet below shows an example of an online transition handler. This example loops through non-processed import entries and sends them to a server.

public class HowToTransitionToOnlineExample extends MobileServerTransitionToOnlineHandler {
  private boolean isProcessing = false;
  public void processTransactions() {
    try {
      isProcessing = true;
      final OBQuery<ImportEntry> entries = OBDal.getInstance().createQuery(ImportEntry.class,
          ImportEntry.PROPERTY_IMPORTSTATUS + "='Initial'");
      for (ImportEntry entry : entries.list()) {
        // send to the central server
                + "org.openbravo.retail.storeserver.howto.central.ProcessEntry",
            new JSONObject(entry.getJsonInfo()));
    } catch (JSONException e) {
      throw new OBException(e);
    } finally {
      isProcessing = false;
  public boolean isReadyToGoOnline() {
    return !isProcessing;

Example code 2

Another example can be found in the store server synchronization module. This transition handler makes sure that all the transactions have been synced by Symmetric DS before allowing online transition.

Retrieved from ""

This page has been accessed 1,051 times. This page was last modified on 20 April 2016, at 17:44. Content is available under Creative Commons Attribution-ShareAlike 2.5 Spain License.