Using Specific Callbacks
The following example illustrates how to register a specific callback object using the use of the BrokerClient.registerCallbackForSubId method.
. . .
public static void main(String args[])
{
. . .
SampleCallback1 general_callback =
new SampleCallback1(num_to_receive);
SampleCallback2 specific_callback =
new SampleCallback2(num_to_receive);
/* Create a client */
. . .
/* Check if can subscribe */
. . .
/* Register general callback */
try {
c.registerCallback(general_callback,null);
} catch (BrokerException ex) {
System.out.println("Error on registering general callback\n"+ex);
return;
}
/* Register specific callback with a subscription ID of 1 */
try {
c.registerCallbackForSubId(1, specific_callback,null);
} catch (BrokerException ex) {
System.out.println("Error on registering specific callback\n"+ex);
return;
}
/* Open the subscription with a subscription ID of 1 */
try {
c.newSubscription( 1, "Sample::SimpleEvent",null);
} catch (BrokerException ex) {
System.out.println("Error on create subscription #1\n"+ex);
return;
}
/* Do main loop */
try {
BrokerClient.mainLoop();
} catch (BrokerException ex) {
System.out.println("Error on dispatch\n"+ex);
return;
}
. . .