Copyright © Cloud Software Group, Inc. All Rights Reserved
Copyright © Cloud Software Group, Inc. All Rights Reserved


Appendix B Sample Programs : Rulebase Samples

Rulebase Samples
The example Java source files in examples/rulebase_api show how to use the Rulebase-related classes of the Configuration Object API.
For details of the code, refer to the Java source files.
RBIsample1.java
This sample shows how to create a simple rulebase and save it to a file. The rulebase uses the Spot microagent that is created using the provided sample application.
In the rulebase, the data source is the current color of the Spot microagent. The test in the rulebase checks the color of the Spot microagent. If the color is blue, it performs an action that changes the color to green.
RBIsample2.java
This sample extends RBIsample1.java to show how to use a compound test in a rulebase.
In this example, the rulebase created in RBIsample1.java is save to a file. After reading the rulebase from the file, RBIsample2.java replaces the test with a compound test. The compound test checks if the current color is either blue or red. If this condition is satisfied, it performs an action that changes the color to green.
RBIsample3.java
This sample demonstrates how an application can create, add, update, and delete a rulebase dynamically on an agent using the Configuration Object API and Console API. Refer to Appendix A, Common Configuration Object API Methods, for methods related to communication between a Console application and the TIBCO Hawk agent.
When running this sample, the Spot microagent should also be running. This allows you to see the effect of the action performed by the rulebase after being updated on the TIBCO Hawk agent.
The sample performs the following steps:
1.
Creates a rulebase using the color of the SPOT microagent as the data source, which changes to green if the current color is blue.
2.
3.
Changes the color of SPOT to blue. (At runtime, a few second after this call, the color on the Spot microagent will change to green due to the test in the rulebase.)
4.
Retrieves the rulebase, modifies it to change the color of SPOT to green if the current color is either blue or red, and updates the rulebase on the agent.
5.
Sets the color of SPOT on the agent to red. (At runtime, a few second later after this call, the color on the Spot microagent will change to green due to the test in the rulebase.)
6.
Sets the color of SPOT on the agent to blue. (At runtime, a few second later after this call, the color on the Spot microagent should change to green due to the test in the rulebase.)
7.

Copyright © Cloud Software Group, Inc. All Rights Reserved
Copyright © Cloud Software Group, Inc. All Rights Reserved