OpenAjaxHub and InfoBus in EGL Rich UI
ChrisLaffra 060000KCEQ Visits (2757)
When writing applications that have more than one "screen", "window", or "panel", it can be cumbersome to keep track which one is showing at a given time and which one to show next. The following picture shows a web diagram for a very simple struts based application with the various forms and screens, and the transitions between them:
The sample shows a struts application, but defining control flow in an EGL Rich UI application can be just as hard. If you are not careful, it is easy to create panels that hard-code what other panels they can link to. To facilitate the switching of screens, extra API needs to be provided to allow one panel to let another know to show. Similarly, handing off information between panels becomes a challenge. Because the links are hard-coded inside each component, control flow is fragmented all over the application and becomes hard to manage.
Now, let's take a step back, and try and remove the hard-coded links from one panel to another. This means that panel one needs a mechanism to inform it wants panel two to show. Similarly, panel 2 should listen for some kind of event that it needs to show. This problem is a generic computer science problem, and the solution is a so-called publish and subscribe architecture. The most prominent version for web browsers is the one being standardized by the OpenAjax alliance. It is predominantly used for connecting components in mashup tools, but it works surprisingly well inside applications also.
The solution offered by EGL Rich UI is based on this OpenAjax specification, but, if you want, also allows for alternative implementations. The simplified EGL Rich UI InfoBus API represents a subset of the OpenAjax API and was named InfoBus, in honor of Lotus eSuite. The basic API allow you to publish events and to listen for them:
You publish events by providing a key identifying the type of event and the data specific to the event. Subscription happens with a patterns matching specific event keys, and a callback function that will be invoked whenever a compatible event is published by any provider.
It identifies the event that was triggered, and the data object that was provided by the publisher.
To use the InfoBus to switch between panels, check out the Tech Sample that comes with RBD 7.5.1:
The infobus is used in various places in this tech sample, and one place is how the "previous" and "next" buttons drive what is shown in the area in the middle of the application. The handler that manages the table of contents (see TOC.egl) subscribes to navigation events as follows:
The buttons generate an event as follows:
The parameter that is passed with the publish call is either 1 or -1, and is interpreted as such by the subscriber.
Most publishers have one listener, but the infobus can be easily used for one-to-many communication patterns also. By adding a subscription to "com
For more information, press F1 inside RBD, and search for "InfoBus".