Broker 10.15 | webMethods Broker Documentation | webMethods Broker Client Java API Programmer's Guide | Using Event Filters | Using BrokerFilters
 
Using BrokerFilters
 
Obtaining Filter Strings
Obtaining Event Type Names
Converting Broker Filters to Strings
You client application can create a BrokerFilter using the BrokerFilter constructor. A BrokerFilter can be used locally by the client application, in conjunction with the BrokerFilter.match method, to determine whether a particular event type matches the filter.
When creating a BrokerFilter, you must specify an event type name and a filter string. You can then use the BrokerFilter.match method to check any events that your client application might receive.
The following example shows a code excerpt that creates three filters for use by a client application. The BrokerFilter.match method is then used to determine whether the event matches each filter's criteria.
. . .
BrokerClient my_client;
BrokerEvent e;
. . .
special = new BrokerFilter(my_client,"Type1",
"(A<B) && ((C+12) >(D*3))");
type1 =new BrokerFilter(my_client, "Type1", null);
type2 = new BrokerFilter(my_client,"Type2", null);
 
try {
e = c.getEvent(-1);
} catch (BrokerException ex) {
System.out.println("Error on getting event\n"+ex);
return;
}
 
if (special.match(e)) {
/* A special case of Type1 events that requires special processing */
. . .
} else if (type1.match(e)) {
/*A Type1 event */
. . .
} else if (type2.match(e)) {
/* A Type2 event */
. . .
}
. . .
To do this same processing without filters, your code would look like that shown in the following example.
. . .
BrokerClient my_client;
BrokerEvent e;
String name;
Int a, b, c, d;
. . .
try {
e = c.getEvent(-1);
} catch (BrokerException ex) {
System.out.println("Error on getting event\n"+ex);
return;
}
 
name = e.getTypeName();
a = e.getIntegerField("A");
b = e.getIntegerField("B");
c = e.getIntegerField("C");
d = e.getIntegerField("D");
if( (name.equals("Type1") && (a<b) && ((c+12) >(d*3)) ) {
/* A special case of Type1 events that requires special processing */
} else if (name.equals("Type1") {
/*A Type1 event */
} else if (name.equals("Type1") {
/*A Type2 event */
}
. . .