Java Reference
In-Depth Information
building a condition across two MBeans is impossible to represent using this que-
rying service. For example, the following query is not supported: If MBean A has an
attribute MyAttribute , then return MBean B with attribute TheAttribute value of 5 .
However, in chapter 11, we will discuss the relation service, which can provide for
MBean relationships.
8.3.2
Creating query expressions
Let's revisit the query we described earlier: All MBeans from application A that have
an attribute count whose value is greater than 10 but less than 20, or that have an
attribute owner whose value equals ABC .
JMX provides the capability to perform many types of query expressions,
including the ones in this query. In our query, we have attribute values that must
be either greater than, less than, or equal to some value. In addition, the query
combines these expressions by using an AND and an OR type expression.
JMX provides the class javax.management.Query as a mechanism for objects to
build simple and complex queries. The Query class contains static methods to
build expressions and to relate expressions into more complex expressions. Each
method returns a type of expression, represented by one of the following classes:
QueryExp
ValueExp
AttributeValueExp
StringValueExp
The ValueExp and StringValueExp classes represent an attribute value. The
AttributeValueExp represents the name of an attribute. The QueryExp class rep-
resents a query expression constructed of one or more other expressions. You
should never need to create instances of the classes yourself; rather, you should
use the methods of the Query class to build expressions.
As you will see in a moment, some of the methods of the Query class take
other expressions as inputs in order to build more complex queries. For exam-
ple, examine the following code that builds the query MBeans with attribute count
greater than 10 :
QueryExp exp = Query.gt( Query.attr( "count" ), Query.value( 10 ) );
The method gt() of the Query class indicates that a greater-than expression is being
constructed. The code uses the attr() method to indicate that the attribute
involved in the greater-than expression is called count and then uses the value()
method to indicate the second half of the greater-than expression.
Search WWH ::




Custom Search