Java Reference
In-Depth Information
8.3.1
The MBeanServer query methods
In section 8.2, we covered the methods of the
MBeanServer
interface. However,
we left out the two methods shown in table 8.3.
Table 8.3 The two remaining methods of the
MBeanServer
interface. These two methods are used
to query the MBean server for a set of qualifying MBean object names.
Method
Return type
Description
Returns the set of
ObjectInstance
objects
identifying the set of MBeans that qualify,
given the
QueryExp
object
queryMBeans( ObjectName,
QueryExp )
java.util.Set
Returns the set of
ObjectName
objects iden-
tifying the set of MBeans that qualify, given
the
QueryExp
object
queryNames( ObjectName,
QueryExp )
java.util.Set
The two methods,
queryMBeans()
and
queryNames()
, both accept an
ObjectName
instance and a
QueryExp
instance. The
ObjectName
instance defines the scope of
the query, and the
QueryExp
instance defines the constructed query expression.
The following sections describe the meaning of the parameters and how to use
these two methods.
The
queryMBeans()
method returns a set of
ObjectInstance
objects. The
ObjectInstance
class contains the
ObjectName
of an MBean and the MBean's
defining class type. The
queryNames()
method only returns a set of
ObjectName
s
of MBeans. Both methods execute queries in the same manner; only their return
type differs. You must choose to use one method over the other based purely on
the amount of information you needed returned.
Defining the scope of a query
We will discuss the
QueryExp
class in a moment—it represents a query like the
one we described in the first paragraph of section 8.3. However, let's first exam-
ine the first argument to the query methods, the
ObjectName
instance.
When executing a query, you need to describe a set of MBeans in which to
apply the query. By defining the scope of a query, you are almost performing a
pre-query. Defining the scope of the query is the role of the
ObjectName
argu-
ment passed to the two query methods. Table 8.4 lists the possible values for
this parameter.