Use a JavaCompute node
to query properties dynamically at run time, in user-defined policies.
Before you begin
Complete the following tasks:
About this task
If you created a user-defined policy, and created properties
for that policy, you can query those properties in a JavaCompute node. For example,
you can create a user-defined policy to set timeouts for processing
HTTP messages.
Procedure
- Right-click the JavaCompute node and click
Open Java to create and open a Java™
file in the Editor view, or open an existing file.
- Create the Java class for the JavaCompute node from which you want to access the user-defined
policy.
- Add user code as shown below to the Java class to
define the user-defined policy. In the example shown, a user-defined policy called MyUDCS has been
defined in a policy project called PP1.
MbPolicy myPol = getPolicy("UserDefined", "{PP1}:MyUDCS");
- Use the following code to access the policy.
if (myPol != null) {
System.out.println("Found policy: "+myPol.getName());
System.out.println(" with type: "+myPol.getType());
System.out.println(" and properties:");
System.out.println(" prop1: "+myPol.getPropertyValueAsString("prop1"));
System.out.println(" prop2: "+myPol.getPropertyValueAsString("prop2"));
System.out.println(" prop3: "+myPol.getPropertyValueAsString("prop3"));
}
This lookup syntax can be qualified by policy project. If no policy project is qualified, the
policy project that is defined on the defaultPolicyProject property in the
node.conf.yaml configuration file is used. Null is returned if either the
property or the policy does not exist.
If you created a user-defined policy, and created properties for that policy, you can query those
properties by using a Java class method that can be called from ESQL.