A query expression is built up from constraints on attribute values (such as “equals” and “less-than” for numeric values and “matches” for strings). These constraints may then be associated by relational operators (“and”, “or”, and “not”) to form complex expressions involving several attributes of an MBean.
For example, the agent or the manager should be able to express a query such as: “Retrieve the MBeans for which the attributeageis at least20and the attribute namestarts withGand ends withling”.
A query expression is evaluated on a single MBean at a time, and if and only if the expression is true, that MBean is included the query result. The MBean server tests the expression individually for every MBean in the scope of the query. It is not possible for a query expression to apply to more than one MBean: there is no mechanism for defining cross-MBean constraints.
The following classes and interfaces are defined for developing query expressions:
■ TheQueryExpinterface identifies objects that are complete query expressions. These objects can be used in a query or composed to form more complex queries.
■ TheValueExpandStringValueExpinterfaces identify objects that represent numeric and string values, respectively, for placing constraints on attribute values.
■ TheAttributeValueExpinterface identifies objects that represent the attribute involved in a constraint.
■ TheQueryclass supports the construction of the query. It contains static methods that return the appropriateQueryExpandValueExpobjects.
In practice, users do not instantiate theValueExpandQueryExpimplementation classes directly. Instead, they should rely on the methods of theQueryclass to return the values and expressions, composing them together to form the final query expression.
Methods of the
Query
Class
The static methods of theQueryclass are used to construct the values, constraints, and subexpressions of a query expression.
The following methods return aValueExpinstance that may be used as part of a constraint, as described:
■ classattr- The result represents the class name of the MBean and may only be used in a string constraint.
■ attr- The result represents the value of the named attribute. This result may be used in boolean, numeric or string constraints, depending upon the type of the attribute. Attributes may also be constrained by the values of other attributes of an equivalent type. This method is overloaded to also take a class name: this is equivalent to also setting a constraint on the name of the MBean’s class.
■ value- The result represents the value of the method’s argument, and it is used in a constraint. This method is overloaded to take any one of the following types: ■ java.lang.String ■ java.lang.Number ■ int ■ long ■ float ■ double ■ boolean
In all of these cases, the resulting value must be used in a constraint on an equivalent attribute value.
■ plus,minus,times,div- These methods each take twoValueExparguments and return aValueExpobject that represents the result of the operation. These operations only apply to numeric values. These methods are useful for
constructing constraints between two attributes of a same MBean.
The following methods represent a constraint on one or more values. They take ValueExpobjects and return aQueryExpobject that indicates if the constraint is satisfied at runtime. This return object can be used as the query expression, or it can be composed into a more complex expression using the logical operators.
■ gt,geq,lt,leq,eq- These methods represent the standard relational operators between two numeric values, respectively: greater than, greater than or equals, less than, less than or equals, and equals. The constraint is satisfied if the relation is true with the arguments in the given order.
■ between- This method represents the constraint where the first argument is strictly within the range defined by the other two arguments. All arguments must be numeric values.
■ in- This method is equivalent to multiple “equals” constraints between a numeric value argument and an array of numeric values. The constraint is satisfied (true) if the numeric value is equal to any one of the array elements.
■ match- This method represents the equality between an attribute’s value and a given string value or string pattern. The pattern admits wildcards (*and?), character sets ([Aa]), and character ranges ([A-Z]) with the standard meaning. The attribute must have a string value, and the constraint is satisfied if it matches the pattern.
■ initialSubString,finalSubString,anySubString- These methods represent substring constraints between an attribute’s value and a given substring value. The constraint is satisfied if the substring is a prefix, suffix or any substring of the attribute string value, respectively.
A constraint can be seen as computing a boolean value and can be used as a subexpression to the following methods. They also return aQueryExpobject that can either be used in a query or as a subexpression of an even more complex query using the same methods:
■ and- The resulting expression is the logical AND of the two subexpression arguments.
■ or- The resulting expression is the logical OR of the two subexpression arguments.
■ not- The resulting expression is the logical negation of the single subexpression argument.