292 WebSphere Business Integration Adapters
18.1 Using the pollForEvents() method
The CWConnectorAgent class is the default implementation for the
pollForEvents() method. You can override this method to provide your own
implementation.
Figure 18-1 shows a sequence diagram of the basic login for the
pollForEvents() method.
Figure 18-1 A sequence diagram for the pollForEvents() method
CWConnectorAgent
getEventsStore()
RMEventStore
fetchEvents()
getNextEvent()
eventObj
1. Get the EventStore implementation.
2. Fetch PollQuantity number of events
from the application.
3. Process each event retrieved from
the application. Get the next event to
be processed.
isSubscribed()
4. Check if the connector has subscribed
to the event generated for the business
object.
5. If there is a subscription, build a
business object based on the
information in the event that is retrieved.
getBO(eventObj)
businessObj
gotApplEvent(businessObj)
6. Send the event to the integration
broker.
7. If the event was sent to the connector
framework, archive and delete the
event from the event store.
archiveEvent()
deleteEvent()
Chapter 18. Polling for events 293
Example 18-1 shows the implementation of basic logic for the pollForEvents()
method.
Example 18-1 Default implementation for the pollForEvents() method
/** * Default implementation of pollForEvents. */
public int pollForEvents() {
CWConnectorUtil.traceWrite(
CWConnectorLogAndTrace.LEVEL5,
"Entering pollForEvents.");
// Get the EventStoreFactory implementation name from the
// getEventStore() method.
CWConnectorEventStore evts = getEventStore();
if (evts == null) {
CWConnectorUtil.generateAndLogMsg(
10533,
CWConnectorLogAndTrace.XRD_ERROR,
0,
0);
return CWConnectorConstant.APPRESPONSETIMEOUT }
try {
// Fetch PollQuantity number of events from the application.
try {
evts.fetchEvents();
} catch (StatusChangeFailedException e) {
CWConnectorUtil.generateAndLogMsg(
10533,
CWConnectorLogAndTrace.XRD_ERROR,
0,
0);
CWConnectorUtil.logMsg(e.getMessage());
e.printStackTrace();
return CWConnectorConstant.APPRESPONSETIMEOUT;
}
// Get the property values for PollQuantity and ArchiveProcessed.
int pollQuantity;
String poll = CWConnectorUtil.getConfigProp("PollQuantity");
try {
if (poll == null || poll.equals(""))
pollQuantity = 1;
else
pollQuantity = Integer.parseInt(poll);
} catch (NumberFormatException e) {
CWConnectorUtil.generateAndLogMsg(
Note: For the adapter, use the default implementation because it meets the
needs of the application.
294 WebSphere Business Integration Adapters
10544,
CWConnectorLogAndTrace.XRD_ERROR,
0);
CWConnectorUtil.logMsg(e.getMessage());
e.printStackTrace();
return CWConnectorConstant.FAIL;
}
String arcProcessed = CWConnectorUtil.getConfigProp("ArchiveProcessed");
// In case the ArchiveProcessed property is not set, use true
// as default.
if (arcProcessed == null || arcProcessed.equals(""))
arcProcessed = CWConnectorAttrType.TRUESTRING;
CWConnectorEvent evtObj;
CWConnectorBusObj bo = null;
try {
for (int i = 0; i < pollQuantity; i++) {
// Process each event retrieved from the application.
// Get the next event to be processed.
evtObj = evts.getNextEvent();
// A null return indicates that there were no events with
// READY_FOR_POLL status. Return SUCCESS.
if (evtObj == null) {
CWConnectorUtil.generateAndLogMsg(
10534,
CWConnectorLogAndTrace.XRD_INFO,
0,
0);
return CWConnectorConstant.SUCCEED;
}
// Check if the connector has subscribed to the event
// generated for the business object.
boolean isSub =
isSubscribed(evtObj.getBusObjName(), evtObj.getVerb());
if (isSub) {
// Retrieve the complete CWConnectorBusObj corresponding
// to the object using the getBO method in
// CWConnectorEventStore. This method sets the verb on a
// temporary business object to RetrieveByContent
// and retrieves the corresponding data information to be
// filled in the business object from the application.
try {
bo = evts.getBO(evtObj);
// Terminate flag will be set in the event store when
// the doVerbFor method returns APPRESPONSETIMEOUT in
// getBO.
if (evts.getTerminate())
return CWConnectorConstant.APPRESPONSETIMEOUT;
} catch (AttributeNotFoundException e) {
CWConnectorUtil.generateAndLogMsg(
Chapter 18. Polling for events 295
10536,
CWConnectorLogAndTrace.XRD_ERROR,
0,
2,
"getBO",
"AttributeNotFoundException");
CWConnectorUtil.logMsg(e.getMessage());
e.printStackTrace();
// Update the event status to ERROR_PROCESSING_EVENT
evts.updateEventStatus(
evtObj,
CWConnectorEventStatusConstants
.ERROR_PROCESSING_EVENT);
if (arcProcessed
.equalsIgnoreCase(CWConnectorAttrType.TRUESTRING)) {
// Archive the event in the application’s archive store
evts.archiveEvent(evtObj.getEventID());
// Delete the event from the event store
evts.deleteEvent(evtObj.getEventID());
}
continue;
} catch (SpecNameNotFoundException e) {
CWConnectorUtil.generateAndLogMsg(
10536,
CWConnectorLogAndTrace.XRD_ERROR,
0,
2,
"getBO",
"SpecNameNotFoundException");
CWConnectorUtil.logMsg(e.getMessage());
e.printStackTrace();
// Update the event status to ERROR_PROCESSING_EVENT
evts.updateEventStatus(
evtObj,
CWConnectorEventStatusConstants
.ERROR_PROCESSING_EVENT);
if (arcProcessed
.equalsIgnoreCase(CWConnectorAttrType.TRUESTRING)) {
// Archive the event in the application’s archive store
evts.archiveEvent(evtObj.getEventID());
// Delete the event from the event store
evts.deleteEvent(evtObj.getEventID());
}
continue;
} catch (InvalidVerbException e) {
CWConnectorUtil.generateAndLogMsg(
10536,
CWConnectorLogAndTrace.XRD_ERROR,
0,
296 WebSphere Business Integration Adapters
2,
"getBO",
"InvalidVerbException");
CWConnectorUtil.logMsg(e.getMessage());
e.printStackTrace();
// Update the event status to ERROR_PROCESSING_EVENT
evts.updateEventStatus(
evtObj,
CWConnectorEventStatusConstants
.ERROR_PROCESSING_EVENT);
if (arcProcessed
.equalsIgnoreCase(CWConnectorAttrType.TRUESTRING)) {
// Archive the event in the application’s archive store
evts.archiveEvent(evtObj.getEventID());
// Delete the event from the event store
evts.deleteEvent(evtObj.getEventID());
}
continue;
} catch (WrongAttributeException e) {
CWConnectorUtil.generateAndLogMsg(
10536,
CWConnectorLogAndTrace.XRD_ERROR,
0,
2,
"getBO",
"WrongAttributeException");
CWConnectorUtil.logMsg(e.getMessage());
e.printStackTrace();
// Update the event status to ERROR_PROCESSING_EVENT
evts.updateEventStatus(
evtObj,
CWConnectorEventStatusConstants
.ERROR_PROCESSING_EVENT);
if (arcProcessed
.equalsIgnoreCase(CWConnectorAttrType.TRUESTRING)) {
// Archive the event in the application’s archive store
evts.archiveEvent(evtObj.getEventID());
// Delete the event from the event store
evts.deleteEvent(evtObj.getEventID());
}
continue;
} catch (AttributeValueException e) {
CWConnectorUtil.generateAndLogMsg(
10536,
CWConnectorLogAndTrace.XRD_ERROR,
0,
2,
"getBO",
"AttributeValueException");

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

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.