Broker 10.5 | webMethods Broker Documentation | webMethods Broker Client Java API Programmer's Guide | Load Balancing and Failover for Publish Operations | Broker Cluster Publisher Selection Notification | Canceling the Selection Callback Object
 
Canceling the Selection Callback Object
You can un-register a callback by invoking the BrokerClusterPublisher.cancelConnectionCallback.
static class ClusterSelCallback implements BrokerCPSelectionCallback
{
int sindex = 0;
int mindex = 0;
 
/* implements a round-robin algorithm on the list of available broker clients */
public int chooseClusterClient(BrokerClusterPublisher bcp,
BrokerEvent[] event,
BrokerInfo[] bi,
Object client_data) {
System.out.println("#of Broker cluster publishers: "+bi.length);
for (int i=0;i<bi.length;i++)
System.out.print(bi[i].broker_name+" ");
 
mindex = (mindex+1)%bi.length;
System.out.println(" ["+bi[mindex].broker_name+"]");
return mindex;
}
 
/* implements a round-robin algorithm on the list of available broker clients */
public int chooseClusterClient(BrokerClusterPublisher bcp,
BrokerEvent event,
BrokerInfo[] bi,
Object client_data) {
System.out.println("#of Broker cluster publishers: "+bi.length);
for (int i=0;i<bi.length;i++)
System.out.print(bi[i].broker_name+" ");
 
sindex = (sindex+1)%bi.length;
System.out.println(" ["+bi[sindex].broker_name+"]");
return sindex;
}
}
public static void main(String args[])
{
BrokerClusterPublisher bcp;
ClusterSelCallback sel_cb;
BrokerEvent e;
. . .
/* create BrokerClusterPublisher */
. . .
/* create and register connection callback */
sel_cb = new ClusterSelCallback();
try {
bcp.registerSelectionCallback( sel_cb, null)
} catch (BrokerException ex) {
System.out.println("Error in registering selection callback");
return;
}
. . .
/* operations on BrokerClusterPublisher */
try {
bcp.cancelSelectionCallback()
} catch (BrokerException ex) {
System.out.println("Error in canceling selection callback");
return;
}
/* disconnect or destroy up BrokerClusterPublisher */
. . .
 
}