Rich UI Infobus

The Rich UI Infobus is a library that makes available a publish-and-subscribe mechanism, which works as follows:
  • A handler subscribes to an event of a specified name. At the time of subscription, the handler also references a function that will receive data when the event occurs. The Infobus then registers the function so that it can be invoked at the appropriate time.
    For example, the following Rich UI handler part subscribes to an event named sample.test and provides a label (a presentation area) that an embedding handler can use:
    Handler embeddedHandler Type RUIHandler {onConstructionFunction=start}
    
       feedback TextLabel;
    
       function start()
          InfoBus.subscribe("com.mycompany.sample.test", showPublish);
       end
    
       function showPublish(eventName STRING in, data ANY in)
          feedback.text = "The " + eventName + " event occurred and passed " + data;
       end
    end  

    In a more realistic case, the showPublish function might receive a record with several fields and then transmit the data to a remote service.

  • The same or a different handler in the same Rich UI application publishes the event, specifying the event name and some event-specific data. At the time of publication, the Infobus invokes the function that was specified at the time of subscription, passing the event-specific data to the function.

    For example, the following handler embeds the previous one, publishes the event, and causes display of the following statement: The sample.text event occurred and passed input data for a service:

    Handler InfoBusTest Type RUIHandler
       { initialUI = [myButton, myDiv] }
    
       myButton Button{text = "Publish the event", onClick ::= clickHandler};
       myDiv Div { children = [new embeddedHandler{}.feedback] };
    
       function clickHandler(e Event in)
          InfoBus.publish("com.mycompany.sample.test", "input data for a service");
       end
    end	

    Note that the function InfoBus.publish does not include the name of the showPublish function. Instead, the Infobus acts as a mediator, ensuring that the appropriate function is invoked.

Infobus functions

The following Infobus functions are in use:
  • Infobus.subscribe accepts two arguments: an event name and a reference to the function that the Infobus invokes when the event is published. The event name may include wildcard characters, as described later.
    You must code the function to be invoked. That function is based on the following Delegate part, which indicates that the function can accept whatever type of data you provide when you publish the event:
    InfoBusCallback(eventName String in, data any in) 

    Infobus.subscribe also returns a subscription value (type ANY), which you can use to unsubscribe from the event.

  • Infobus.unsubscribe accepts a single parameter; the value of type ANY returned from Infobus.subscribe. This function has no return value.
  • Infobus.publish accepts two arguments: an event name and the data that you provide. This function has no return value.

If a Rich UI handler subscribes to the Infobus, that handler cannot be removed from memory. For example, if the user's button click creates a handler in a function, and if the handler subscribes to the Infobus, the handler and its widgets cannot be removed from memory until the handler unsubscribes from the Infobus.

In most cases, memory is freed by the EGL runtime code. However, the following topic describes how to be in greater control of memory management: Rich UI memory management.

Event names and wild cards

An event name is composed of one or more tokens, which are character symbols such as sample and test (in our example). each of which is separated from the next by a dot.

You can use Infobus.subscribe to subscribe to more than one event. Two wildcard characters are available, and you can use both in the same Infobus.subscribe invocation:
  • If an asterisk (*) is used in place of a token, the function registered by Infobus.subscribe is invoked when your code publishes any event whose name matches the event name regardless of the token that you specify in place of the asterisk. For example, if Infobus.subscribe identifies the event name as com.mycompany.update.*.new.employee, the function registered by Infobus.subscribe is invoked in response to any of the following invocations:
    InfoBus.publish("com.mycompany.update.sales.new.employee", "some data");
    
    InfoBus.publish("com.mycompany.update.marketing.new.employee", "some data");
    
    InfoBus.publish("com.mycompany.update.outreach.new.employee", "some data");
  • If a double asterisk (**) is used in place of the last token, the function registered by Infobus.subscribe is invoked when your code publishes any event whose name matches the event name regardless of the series of tokens (and intervening dots) that you specify in place of the asterisk. For example, if Infobus.subscribe identifies the event name as com.mycompany.update.sales.**, the function registered by Infobus.subscribe is invoked in response to any of the following invocations:
    InfoBus.publish("com.mycompany.update.sales.new.employee", "some data");
    
    InfoBus.publish("com.mycompany.update.sales.temporary.employee", "some data");
    
    InfoBus.publish("com.mycompany.update.sales.outreach.new.temporary.employee", "some data");

For additional details

The Infobus mechanism is based on an implementation of the OpenAjax alliance. You may not need further details on this mechanism, but can get them as follows:
  1. Go to the OpenAjax alliance website:

       http://www.openajax.org/index.php

  2. Click Wikis > Member Wiki
  3. Type the following string in the Search field: OpenAjax Hub 1.0 Specification PublishSubscribe

Rich UI does not support the specification phrases related to filter or scope.