Java Reference
In-Depth Information
The only two MBeans that meet the constraints of this query are the
Fax
and
Copier
MBeans.
The next example creates another simple query, but also restricts the scope
using a partial object name.
Query example 2
The second query is as follows:
All communication devices with a transfer rate greater
than 28800
. The results of this query should be only modem MBeans with a
transferRate
attribute greater than 28800. Again, the first thing you need to do
is define the query scope. The following is the partial object name to define the
scope of the query:
Hardware:type=com,*
This partial object name defines the scope of the query to be all MBeans with a
domain of
Hardware
and an object name property
type
set to
com
. The following
code constructs and executes the query:
QueryExp query = Query.gt( Query.attr( "transferRate" ),
Query.value( 28800 ) );
mbeanServer.queryMBeans( new ObjectName( "Hardware:type=com,*" ),
query);
The two modem MBeans are in the scope of the query; however, only
Modem2
has
a transfer rate greater than 28800, so it is the only MBean that satisfies this
query.
The next example creates a more complex expression by joining two expres-
sions together.
Query example 3
The third query is as follows:
All hardware with a
LOW
inkLevel
or
LOW
paper-
Count
. First, let's show the partial object name to define the scope. This is the
same as in the first example:
Hardware:*
Now, here's the code that constructs and executes the query:
QueryExp exp1 = Query.equals( Query.attr( "inkLevel" ),
Query.value( "LOW" ) );
QueryExp exp2 = Query.equals( Query.attr( "paperCount" ),
Query.value( "LOW" ) );
QueryExp finalExp = Query.or( exp1, exp2 );
mbeanServer.queryMBeans( new ObjectName( "Hardware:*" ), finalExp );