Java Reference
In-Depth Information
Table 8.10
Devices in a imaginary JMX agent used in the query examples in this section.
Device
MBean object name
Attributes and values
status = OK , transferRate =
28800
Modem1
Hardware:type=com,location=
office,name=modem1
status = ERROR , transferRate =
56000
Modem2
Hardware:type=com,location=
office,name=modem2
status = OK , paperCount = LOW ,
inkLevel = HIGH
Printer
Hardware:type=paper,location=
network,name=printer
status = OK , paperCount = NORM ,
inkLevel = LOW
Fax
Hardware:type=paper,location=
network,name=fax
status = OK , paperCount = LOW ,
inkLevel = LOW
Copier
Hardware:type=paper,location=
network,name=copier
do the two modems). Each MBean object name provides some detailed informa-
tion about the devices as well, including location, type (modem or paper), and
name. These object name properties could be represented as attributes, but you
will leave them in the object name because doing so gives you a good way to
restrict the scope of a query.
Now that you are familiar with the set of MBeans involved in the examples,
let's move on to the first query.
Query example 1
The first query is as follows: All hardware with a LOW inkLevel . The results of this
query should return only MBeans that have an inkLevel attribute with a value of
LOW . Remember, the MBean server's methods for performing queries have two
arguments: the first argument (the object name) defines scope, and the second
argument is the actual query. Let's define the scope first with the following par-
tial object name:
Hardware:*
This partial object name defines the scope of the query to be all MBeans with a
domain of Hardware .
The query expression itself is also simple. The following code constructs the
necessary query expression and invokes the query method from your imaginary
MBean server in the agent:
QueryExp query = Query.equals( Query.attr( "inkLevel" ),
Query.value( "LOW" ) );
mbeanServer.queryMBeans( new ObjectName( "Hardware:*" ), query );
Search WWH ::




Custom Search