Chapter 8. Asynchronous event processing and notification 115
The SQL statement Example 8-1 shows how a connector might select event
records based on event priority. The SELECT statement sorts the events by
priority, and the connector processes each event in turn.
Example 8-1 Example SQL statement
SELECT event_id, object_name, object_verb, object_key
FROM event_table
WHERE event_status = 0 ORDER BY event_priority
8.3.6 Event distribution
The polling mechanisms can be implemented so that multiple connectors can
poll the same event store. Each connector can be configured to process certain
events, create specific business objects, and pass those business objects to
broker system. This configuration can streamline the processing of certain types
of events and increase the transfer of data out of an application.
To implement event distribution so that multiple connectors can poll the event
store, complete the following steps:
1. Add a column to the event record for an integer connector identifier (ID), and
design the event detection mechanism to specify which connector will pick up
the event. This might be done per application entity. For example, the event
detection mechanism might specify that all Customer events be picked up by
the connector that has the connectorId field set to 4.
2. Add an application-specific connector property named ConnectorId. Assign
each connector a unique identifier and store this value in its ConnectorId
property.
Implement the poll method to query for the value of the ConnectorId property. If
the property is not set, the poll method can retrieve all event records from the
event store as usual. If the property is set to a connector identifier value, the poll
method retrieves only those events that match the ConnectorId property.
8.4 Custom pollForEvents() method
For a Java connector, the CWConnectorAgent class defines the
pollForEvents() method. This class provides a default implementation of the
pollForEvents() method. You can use this default implementation or override
the method with your own poll method. However, the pollForEvents() method
must be implemented.
116 WebSphere Business Integration Adapters
The Java-based pseudo-code in Example 8-2 shows the basic logic flow for a
pollForEvents() method (see 8.3.2, “Basic logic for the poll method” on
page 112 for more details).
Example 8-2 Basic logic of the pollForEvents() method
public int pollForEvents() {
int status = 0;
get the events from the event store
for (events 1 to MaxEvents in event store) {
extract BOName, verb, and key from the event record
if(ConnectorBase.isSubscribed(BOName,BOverb) {
BO = JavaConnectorUtil.createBusinessObject(BOName)
BO.setAttrValue(key)
retrieve application data using doVerbFor()
BO.setVerb(Retrieve)
BO.doVerbFor()
BO.setVerb(BOverb)
status = gotApplEvent(BusinessObject);
archive event record with success or failure status
} else {
archive item with unsubscribed status
}
return status;
}
The method first retrieves a set of events from the event store. For each event,
the method calls the isSubscribed() method to determine whether any
subscriptions exist for the corresponding business object. If there are
subscriptions, the method retrieves the data from the application, creates a new
business object, and calls the gotApplEvent() method to send the business
object to InterChange Server. If there are no subscriptions, the method archives
the event record with a status value of unprocessed.
The steps in the basic logic for the event processing that the pollForEvents()
method typically performs are:
1. Set up a subscription manager for the connector.
2. Verify that the connector still has a valid connection to the event store.
Note: For a flow chart of the poll methods basic logic, see Figure 8-6 on
page 111.

Get WebSphere Business Integration Adapters: An Adapter Development and WebSphere Business Integration Solution now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.