Copyright © TIBCO Software Inc. All Rights Reserved
Copyright © TIBCO Software Inc. All Rights Reserved


Chapter 3 Adapter Program Elements : Event Model

Event Model
This section discusses the TIBCO Adapter event model.
Event Management Classes
Three classes participate in the TIBCO Adapter event model: event sources, events, and event listeners. Figure 9 illustrates the event management class hierarchy.
Figure 9 Event Management Class Hierarchy
Event sources generate events, that is, an event source creates an event instance when it is triggered. An example is the MSubscriber event source, which creates MDataEvent, MExceptionEvent, or MTimeOutEvent instances.
Events are created and owned by the event source. Instances of events encapsulate state information about an event. Some adapters may decide to provide a custom event for their source or target application.
An MSubscriber sends a special event, MExceptionEvent. See How Adapters Receive Data for details on when a subscriber receives an MException event.
Event listeners register interest with event sources. Custom adapters create appropriate subclasses of the SDK event listener class and implement onEvent() methods with application-specific behavior.
The following code fragment accesses a subscriber event source, which was defined in the project repository, and binds a listener—in effect, a callback—to the subscriber:
MSubscriber* pMSubscriber = pComponentRegistry -> getComponentByName ("mySub");
 
DataEventHandler* pDataEventHandler = new DataEventHandler( this );
pMSubscriber->addListener( pDataEventHandler );
 
The Java API supports MEventSource, MEvent, and MEventListener classes to implement an event model that mirrors that of the C++ API.
In contrast to the C++ API, the MIODescriptor event source and related MIOEvent are not supported because there is no need for them in conjunction with the Java event model.
TIBCO Adapter Flow of Event Information
Assume the custom adapter has been set up to listen to certain data events. In that case:
1.
2.
An MSubscriber instance (event source) receives the data and creates an instance of MDataEvent (event). A new event instance is created each time new data is received.
3.
The event source informs each registered listener by calling the listener’s onEvent() method. Each onEvent() method executes using the information stored in the MDataEvent instance.
Figure 10 TIBCO Adapter Event Model
Extending Adapter Event Classes
A custom adapter can use custom events to suit its needs. In these cases, the custom adapter needs to provide the following elements:
Custom event source(s)—subclass(es) of MEventSource—with these methods defined:
addListener() adds a listener to the event source.
removeListener() removes a listener from the event source. Calling this method does not cancel certified delivery agreement for RVCM.
notify() triggers an event in each event listener attached to this event source.
Custom adapters can also remove listeners from the event source.
A custom event (subclass of MEvent). This is the event the custom event source generates. In the constructor for the event, the related event source is provided.
Instances of MEventListener with appropriate onEvent() methods.

Copyright © TIBCO Software Inc. All Rights Reserved
Copyright © TIBCO Software Inc. All Rights Reserved