6.16 Events

ExternalEvents offer a way to communicate with a running XMA application by sending am event to it. At an XMA session a listener for ExternalEvents can be registered. As of now, the only implemented means of communication are Named Windows Pipes (see MSDN Pipes). The XMA application starts a named pipe server process listening for pipe clients if the application was started with the parameter at.spardat.xma.pipename set to some value, which thus identifies the pipe. The pipe name has to follow the Windows file name conventions, usually a pipe name should be unique for an application (like the URL starting an application).

A pipe client, which can send messages to an XMA application is not yet part of the XMA distribution. If needed it has to be implemented. Typically this pipe client could be implemented in the program launching the XMA application. Before a new Java VM is started the launcher checks via a named pipe if there is already an application running, which is listening at this named pipe. In that case, instead of starting the VM, the existing application is conntacted by the pipe and an ExternalEvent can be executed at it.

The pipe communication from the client follows this simple protocol:

  • transferred are bytes representing chars, encoded in the default platform encoding

  • this char stream has to consist of key - value pairs

  • as delimiter between each key and value serves the char '\b':

    [<name>'\b'<value>['\b'<name>'\b'<value>]*].

  • In the ExternalEvent this key value pairs are then available as Java properties.

  • A value with the name at.spardat.xma.evenName is set as event name (and not available in the properties). This can be used to distinguish between different "types" of ExternalEvents.

  • In the external event processing by an ExternalEventListener Java properties can be returned. These are transferred back to the pipe client in the protocol as described above (chars encoded in the default platform encoding): [<name>'\b'<value>['\b'<name>'\b'<value>]*].

For implementing the ExternalEvent processing these classes are used:


The registered ExternalEventListener classes are notified by an incoming ExternalEvent . This notification is performed in a Display.asyncExec(). That means that if the XMA application is busy with a GUI thread it waits for the notification of the listeners until this GUI thread is finished. Once the notification is started the XMA application (and therefore the XMA caller) waits for the completion of the code initiated by the listeners. XMA calls from COM wait only as long for ExternalEvent completion as long as the caller's timeout permits.

GlobalEvent s offer a mechanism to notify XMA clients actively from the server side. An incoming GlobalEvent can be used to initiate a client to show a message or to refresh some resource etc. The GlobalEvent mechanism has to be activated by the XProperty xma.runtime.activateGlobalEvents . Any other value than false (which is the default value) will activate the GlobalEvent mechanism and define a GlobalEvent scope. GlobalEvents are only written and read in the scope set by xma.runtime.activateGlobalEvents (e.g. xma.runtime.activateGlobalEvents=samplespar) . This mechanism prevents that GlobalEvents of different applications are mixed. For details of the XMA Runtime properties see:

XMA Runtime Properties(Appendix A: XMA Runtime Properties)

A GlobalEvent is produced and fired at a server where an XMA application is deployed (usually by a request to this server). If the server exist in a cluster environment the event is distributed to all servers and so to all clients of all servers. Recipients of a GlobalEvent are XMA servers and XMA clients, which have registered GlobalEventListener . A GlobalEvent can be sent to the server itself (actually to all servers in the cluster) and/or to all XMA clients connected to a server in the cluster. It is also possible to send the event only to a client identified by a given session ID.

For implementing the GlobalEvent processing the following classes are used, only methods are described which are important for the application programmer:

Class

Description

at.spardat.xma. event.global. GlobalEvent

Represents the global event received by the XMA client.

  • String getEventName() Returns the name of the global event, which is set at GlobalEvent creation time. The event name can be used to distinguish between different types of global events. So the GlobalEventListener can determine the type of the incoming event and take the proper action.

  • Properties getProperties() Returns all Properties.

  • String getProperty(String name) Returns the named property.

  • Object setProperty(String key, String value) Fills the event with a property. This is supposed to happen between the creation and sending of the GlobalEvent .

at.spardat.xma. event.global. GlobalEventListener

The GlobalEvent listener interface which has to be implemented by a listener class. This class can be registered at the server side at GlobalEventManager and at the client side at XMASessionClient.

  • void globalEvent(GlobalEvent event) The one method of this interface where the event is processed. At the client side the call to this method is performed in a Display.asyncExec().

at.spardat.xma. event.global. GlobalEventManager

This singleton class serves for creating, sending and polling GlobalEvent s.

  • void addGlobalEventListener( GlobalEventListener listener) To register GlobalEventListener classes at the server side. The added GlobalEventListener will be notified only by server events (RECIPIENT_ALL_SERVERS).

  • GlobalEvent createGlobalEvent(..) There are several kinds of this method to create a GlobalEvent. Usually the name, the recipient type (RECIPIENT_ALL_SERVERS, RECIPIENT_ALL_CLIENTS,...) and the timestamp when this event is no longer valid is given. The recipient types can be combined by the '|' operator. Non valid (outdated) events are not transferred to a recipient. For details see the javadoc.

  • GlobalEvent createGlobalEventTTL(..) As createGlobalEvent(..) only the time to live is given instead of the timestamp (to determine how long this event is valid). For details see the javadoc.

  • boolean removeGlobalEventListener( GlobalEventListener listener) Method to deregister GlobalEventListener classes at the server side.

  • void send(GlobalEvent event) Sends the event to a global data structure which distributes it to all severs in the cluster. Between creation of an event and send() the event can be filled with properties.

at.spardat.xma. session. XMASessionClient

Provides a method to register and deregister an GlobalEventListener at the client side.

  • void addGlobalEventListener( GlobalEventListener listener) The added GlobalEventListener will be notified only by client events (RECIPIENT_ALL_CLIENTS, RECIPIENT_BY_ID).

  • boolean removeGlobalEventListener( GlobalEventListener listener)

Table 6.16. Global Event Classes


First the event is created (by GlobalEventManager.createGlobalEvent(..) ) at the XMA server, where the name, the recipients and the time to live of the event is determined. If the event should only reach a special client, this client's session ID can be stated.

Usually, after creation the event is filled with properties, then the event is sent (by GlobalEventManager.send(..) ). To send an event means to incorporate it in a global data structure which can be accessed by all servers in the cluster (actually the event is bound to an JNDI tree).

The transmission of sent events to registered listeners is initiated by an RPC between XMA server and XMA client. An RPC reply (from server to client) polls at the server side for new (still undelivered) GlobalEvents. If the GlobalEvent is of the recipient type RECIPIENT_ALL_SERVERS the server side registered GlobalEventListener are notified.

If the GlobalEvent is of the recipient type RECIPIENT_ALL_CLIENTS or RECIPIENT_BY_ID (in this case the event's session ID has to match the RPC's session ID) the GlobalEvent is transmitted as RPC parameter to the client.

At the client side the GlobalEvent s are read from the RPC and are delivered to the client's GlobalEventListener classes. This notification is performed in a Display.asyncExec() before the RPC itself is routed to the application code.

Only GlobalEvent s are transmitted to the listeners which are still valid and which were not yet delivered (to the server, or to the client, depending on the recipient type).

A GlobalEventListener at the server side may seem pointless as the server is contacted for GlobalEvent creation anyway. But as a new event is distributed to all servers in the cluster it may be necessary to notify all the servers of the new event and to perform some action on each of them (like resource refreshing).

Note, that when there are no RPC's no GlobalEvents are delivered. So if a client should be notified by - let's say - the end of some batch process, the client has to poll the server actively by RPCs. If no user interaction can be assumed at the XMA client, RPC's could be sent in an own polling task.

The following snippets demonstrate creation, sending of GlobalEvent s and implementing of GlobalEventListener.