Broker 10.15 | webMethods Broker Documentation | webMethods Broker Client Java API Programmer's Guide | Subscribing to and Receiving Events | Getting Events using the poll Method | Using the poll Method | A Polling Example
 
A Polling Example
The following snippet illustrates how you would code the steps described above.
static String broker_host = "localhost";
static String broker_name = null;
static String client_group = "sample";
int N = numberOfClients;
 
. . .
/* --------------------------------------------------------*/
/* Allocate the array for BrokerClients */
BrokerClient[] c = new BrokerClient[N]
 
/* --------------------------------------------------------*/
/* Create BrokerClients */
. . .
 
/* ---------------------------------------------------------*/
/* Allocate array for BrokerClientPoll Objects */
 
BrokerClientPoll[] poll = new BrokerClientPoll[N];
 
/* ---------------------------------------------------------*/
/* Create BrokerClientPoll objects for each BrokerClient */
 
for (int i = 0; i < N; i++) {
poll[i] = new BrokerClientPoll(c[i], BrokerClientPoll.GET_EVENTS, null);
 
/* ----- Prime the client -------------------------- */
c[i].prime(NUM_TO_PRIME);
}
 
/* ----------------------------------------------------------*/
/* Poll the queues of clients identified in BrokerClientPoll[]
 
for (;;) {
BrokerClientPoll[] result = BrokerClient.poll(poll, -1);
 
/* ----------------------------------------------------------*/
/* Get events for BrokerClients identified in results array */
 
for (int i = 0; i < result.length; i++) {
if (result[i].isReady(BrokerClient.GET_EVENTS)) {
BrokerEvents[] events = result[i].getBrokerClient().getEvents(MAX, 0);
 
/* ----- Re-prime the client ---------------- */
result[i].getBrokerClient().prime(NUM_TO_PRIME);
}
}
}