The Rich UI Infobus is a library that makes
a publish-and-subscribe
mechanism available.
The publish-and-subscribe
mechanism 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.
- Either 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
The InfoBus.publish function
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:
Event names and
wild cards
An event name
is composed of one or more tokens: character symbols
such as sample and test. Each symbol 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 you use an asterisk (*) in place of a token, the function that Infobus.subscribe registered
is invoked when your code publishes an 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 that Infobus.subscribe registered
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 you use a double asterisk (**) in place of the last token,
the function that Infobus.subscribe registered
is invoked when your code publishes an 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 that Infobus.subscribe registered
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.outreach.new.temporary.employee", "some data");
Additional details
The
Infobus mechanism
is based on an implementation of the OpenAjax alliance. For more details
about Infobus:
- Go to the OpenAjax alliance Web site:
http://www.openajax.org/index.php
- Click Wikis > Member Wiki
- In the Search field,
type the following
string: OpenAjax Hub 1.0 Specification PublishSubscribe
Note: Rich UI does not support the specification
phrases that are related to filter or scope.