public class Query extends Object
Constructs query object constraints.
The MBean Server can be queried for MBeans that meet a particular
condition, using its queryNames
or
queryMBeans
method. The QueryExp
parameter to the method can be any implementation of the interface
QueryExp
, but it is usually best to obtain the QueryExp
value by calling the static methods in this class. This is particularly
true when querying a remote MBean Server: a custom implementation of the
QueryExp
interface might not be present in the remote MBean Server,
but the methods in this class return only standard classes that are
part of the JMX implementation.
As an example, suppose you wanted to find all MBeans where the Enabled
attribute is true
and the Owner
attribute is "Duke"
. Here is how you could construct the appropriate QueryExp
by
chaining together method calls:
QueryExp query = Query.and(Query.eq(Query.attr("Enabled"), Query.value(true)), Query.eq(Query.attr("Owner"), Query.value("Duke")));
Constructor and Description |
---|
Query()
Basic constructor.
|
Modifier and Type | Method and Description |
---|---|
static QueryExp |
and(QueryExp q1,
QueryExp q2)
Returns a query expression that is the conjunction of two other query
expressions.
|
static QueryExp |
anySubString(AttributeValueExp a,
StringValueExp s)
Returns a query expression that represents a matching constraint on
a string argument.
|
static AttributeValueExp |
attr(String name)
Returns a new attribute expression.
|
static AttributeValueExp |
attr(String className,
String name)
Returns a new qualified attribute expression.
|
static QueryExp |
between(ValueExp v1,
ValueExp v2,
ValueExp v3)
Returns a query expression that represents the constraint that one
value is between two other values.
|
static AttributeValueExp |
classattr()
Returns a new class attribute expression which can be used in any
Query call that expects a ValueExp.
|
static ValueExp |
div(ValueExp value1,
ValueExp value2)
Returns a binary expression representing the quotient of two numeric
values.
|
static QueryExp |
eq(ValueExp v1,
ValueExp v2)
Returns a query expression that represents an equality constraint on
two values.
|
static QueryExp |
finalSubString(AttributeValueExp a,
StringValueExp s)
Returns a query expression that represents a matching constraint on
a string argument.
|
static QueryExp |
geq(ValueExp v1,
ValueExp v2)
Returns a query expression that represents a "greater than or equal
to" constraint on two values.
|
static QueryExp |
gt(ValueExp v1,
ValueExp v2)
Returns a query expression that represents a "greater than" constraint on
two values.
|
static QueryExp |
in(ValueExp val,
ValueExp[] valueList)
Returns an expression constraining a value to be one of an explicit list.
|
static QueryExp |
initialSubString(AttributeValueExp a,
StringValueExp s)
Returns a query expression that represents a matching constraint on
a string argument.
|
static QueryExp |
isInstanceOf(StringValueExp classNameValue)
Returns a query expression that represents an inheritance constraint
on an MBean class.
|
static QueryExp |
leq(ValueExp v1,
ValueExp v2)
Returns a query expression that represents a "less than or equal to"
constraint on two values.
|
static QueryExp |
lt(ValueExp v1,
ValueExp v2)
Returns a query expression that represents a "less than" constraint on
two values.
|
static QueryExp |
match(AttributeValueExp a,
StringValueExp s)
Returns a query expression that represents a matching constraint on
a string argument.
|
static ValueExp |
minus(ValueExp value1,
ValueExp value2)
Returns a binary expression representing the difference between two numeric
values.
|
static QueryExp |
not(QueryExp queryExp)
Returns a constraint that is the negation of its argument.
|
static QueryExp |
or(QueryExp q1,
QueryExp q2)
Returns a query expression that is the disjunction of two other query
expressions.
|
static ValueExp |
plus(ValueExp value1,
ValueExp value2)
Returns a binary expression representing the sum of two numeric values,
or the concatenation of two string values.
|
static ValueExp |
times(ValueExp value1,
ValueExp value2)
Returns a binary expression representing the product of two numeric values.
|
static ValueExp |
value(boolean val)
Returns a boolean value expression that can be used in any Query call
that expects a ValueExp.
|
static ValueExp |
value(double val)
Returns a numeric value expression that can be used in any Query call
that expects a ValueExp.
|
static ValueExp |
value(float val)
Returns a numeric value expression that can be used in any Query call
that expects a ValueExp.
|
static ValueExp |
value(int val)
Returns a numeric value expression that can be used in any Query call
that expects a ValueExp.
|
static ValueExp |
value(long val)
Returns a numeric value expression that can be used in any Query call
that expects a ValueExp.
|
static ValueExp |
value(Number val)
Returns a numeric value expression that can be used in any Query call
that expects a ValueExp.
|
static StringValueExp |
value(String val)
Returns a new string expression.
|
public static final int GT
gt(javax.management.ValueExp, javax.management.ValueExp)
query. This is chiefly
of interest for the serialized form of queries.public static final int LT
lt(javax.management.ValueExp, javax.management.ValueExp)
query. This is chiefly
of interest for the serialized form of queries.public static final int GE
geq(javax.management.ValueExp, javax.management.ValueExp)
query. This is chiefly
of interest for the serialized form of queries.public static final int LE
leq(javax.management.ValueExp, javax.management.ValueExp)
query. This is chiefly
of interest for the serialized form of queries.public static final int EQ
eq(javax.management.ValueExp, javax.management.ValueExp)
query. This is chiefly
of interest for the serialized form of queries.public static final int PLUS
plus(javax.management.ValueExp, javax.management.ValueExp)
expression. This
is chiefly of interest for the serialized form of queries.public static final int MINUS
minus(javax.management.ValueExp, javax.management.ValueExp)
expression. This
is chiefly of interest for the serialized form of queries.public static final int TIMES
times(javax.management.ValueExp, javax.management.ValueExp)
expression. This
is chiefly of interest for the serialized form of queries.public static final int DIV
div(javax.management.ValueExp, javax.management.ValueExp)
expression. This is
chiefly of interest for the serialized form of queries.public static QueryExp and(QueryExp q1, QueryExp q2)
q1
- A query expression.q2
- Another query expression.public static QueryExp or(QueryExp q1, QueryExp q2)
q1
- A query expression.q2
- Another query expression.public static QueryExp gt(ValueExp v1, ValueExp v2)
v1
- A value expression.v2
- Another value expression.relOp
equal
to GT
.public static QueryExp geq(ValueExp v1, ValueExp v2)
v1
- A value expression.v2
- Another value expression.relOp
equal
to GE
.public static QueryExp leq(ValueExp v1, ValueExp v2)
v1
- A value expression.v2
- Another value expression.relOp
equal
to LE
.public static QueryExp lt(ValueExp v1, ValueExp v2)
v1
- A value expression.v2
- Another value expression.relOp
equal
to LT
.public static QueryExp eq(ValueExp v1, ValueExp v2)
v1
- A value expression.v2
- Another value expression.relOp
equal
to EQ
.public static QueryExp between(ValueExp v1, ValueExp v2, ValueExp v3)
v1
- A value expression that is "between" v2 and v3.v2
- Value expression that represents a boundary of the constraint.v3
- Value expression that represents a boundary of the constraint.public static QueryExp match(AttributeValueExp a, StringValueExp s)
?
", "*
", "[
",
each of which may be escaped with "\
";
character classes may use "!
" for negation and
"-
" for range.
(*
for any character sequence,
?
for a single arbitrary character,
[...]
for a character sequence).
For example: a*b?c
would match a string starting
with the character a
, followed
by any number of characters, followed by a b
,
any single character, and a c
.a
- An attribute expressions
- A string value expression representing a matching constraintpublic static AttributeValueExp attr(String name)
Returns a new attribute expression. See AttributeValueExp
for a detailed description of the semantics of the expression.
Evaluating this expression for a given
objectName
includes performing MBeanServer.getAttribute(objectName,
name)
.
name
- The name of the attribute.name
.public static AttributeValueExp attr(String className, String name)
Returns a new qualified attribute expression.
Evaluating this expression for a given
objectName
includes performing MBeanServer.getObjectInstance(objectName)
and MBeanServer.getAttribute(objectName,
name)
.
className
- The name of the class possessing the attribute.name
- The name of the attribute.public static AttributeValueExp classattr()
Returns a new class attribute expression which can be used in any Query call that expects a ValueExp.
Evaluating this expression for a given
objectName
includes performing MBeanServer.getObjectInstance(objectName)
.
public static QueryExp not(QueryExp queryExp)
queryExp
- The constraint to negate.public static QueryExp in(ValueExp val, ValueExp[] valueList)
val
- A value to be constrained.valueList
- An array of ValueExps.public static StringValueExp value(String val)
val
- The string value.public static ValueExp value(Number val)
val
- An instance of Number.public static ValueExp value(int val)
val
- An int value.public static ValueExp value(long val)
val
- A long value.public static ValueExp value(float val)
val
- A float value.public static ValueExp value(double val)
val
- A double value.public static ValueExp value(boolean val)
val
- A boolean value.public static ValueExp plus(ValueExp value1, ValueExp value2)
value1
- The first '+' operand.value2
- The second '+' operand.op
equal to
PLUS
.public static ValueExp times(ValueExp value1, ValueExp value2)
value1
- The first '*' operand.value2
- The second '*' operand.op
equal to
TIMES
.public static ValueExp minus(ValueExp value1, ValueExp value2)
value1
- The first '-' operand.value2
- The second '-' operand.op
equal to
MINUS
.public static ValueExp div(ValueExp value1, ValueExp value2)
value1
- The first '/' operand.value2
- The second '/' operand.op
equal to
DIV
.public static QueryExp initialSubString(AttributeValueExp a, StringValueExp s)
a
- An attribute expression.s
- A string value expression representing the beginning of the
string value.public static QueryExp anySubString(AttributeValueExp a, StringValueExp s)
a
- An attribute expression.s
- A string value expression representing the substring.public static QueryExp finalSubString(AttributeValueExp a, StringValueExp s)
a
- An attribute expression.s
- A string value expression representing the end of the string
value.public static QueryExp isInstanceOf(StringValueExp classNameValue)
Example: to find MBeans that are instances of
NotificationBroadcaster
, use
Query.isInstanceOf(Query.value(NotificationBroadcaster.class.getName()))
.
Evaluating this expression for a given
objectName
includes performing MBeanServer.isInstanceOf(objectName,
((StringValueExp)classNameValue.apply(objectName)).getValue()
.
classNameValue
- The StringValueExp
returning the name
of the class of which selected MBeans should be instances. Submit a bug or feature
For further API reference and developer documentation, see Java SE Documentation. That documentation contains more detailed, developer-targeted descriptions, with conceptual overviews, definitions of terms, workarounds, and working code examples.
Copyright © 1993, 2022, Oracle and/or its affiliates. All rights reserved. Use is subject to license terms. Also see the documentation redistribution policy.