|
![]() |
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectjavax.management.QueryNotificationFilter
public class QueryNotificationFilter
General-purpose notification filter. This filter can be used to
filter notifications from a possibly-remote MBean. Most filtering
decisions can be coded using this filter, which avoids having to
write a custom implementation of the NotificationFilter
class. Writing a custom implementation requires you to deploy it
on both the client and the server in the remote case, so using this class
instead is recommended where possible.
This class uses the Query API to specify the
filtering logic. For example, to select only notifications where the
type is "com.example.mytype"
,
you could use
NotificationFilter filter = new QueryNotificationFilter("Type = 'com.example.mytype'");
or equivalently
NotificationFilter filter = new QueryNotificationFilter( Query.eq(Query.attr("Type"), Query.value("com.example.mytype")));
(This particular example could also use
NotificationFilterSupport
.)
Here are some other examples of filters you can specify with this class.
QueryNotificationFilter("Type = 'com.example.type1' or
Type = 'com.example.type2'")
QueryNotificationFilter("Type in ('com.example.type1',
'com.example.type2')")
QueryNotificationFilter("SequenceNumber > 1000")
QueryNotificationFilter(AttributeChangeNotification.class, null)
AttributeChangeNotification
or a subclass of it.
QueryNotificationFilter(AttributeChangeNotification.class,
"AttributeName = 'Size'")
AttributeChangeNotification
or a subclass, and where the
name of the
changed attribute is Size
.
QueryNotificationFilter(AttributeChangeNotification.class,
"AttributeName = 'Size' and NewValue - OldValue > 100")
QueryNotificationFilter("like 'com.example.mydomain:*'")
QueryNotificationFilter("Source.canonicalName like
'com.example.mydomain:%'")
QueryNotificationFilter(MBeanServerNotification.class,
"Type = 'JMX.mbean.registered' and MBeanName.canonicalName like
'com.example.mydomain:%'")
MBeanServerNotification
representing
an object registered in the domain com.example.mydomain
.
Although the examples above are clear, looking closely at the
Query API reveals a subtlety. A QueryExp
is evaluated on
an ObjectName
, not a Notification
.
Every time a Notification
is to be filtered by a
QueryNotificationFilter
, a special MBeanServer
is created.
This MBeanServer
contains exactly one MBean, which represents the
Notification
. If the source of the notification is an ObjectName
, which is
recommended practice, then the name of the MBean representing the
Notification
will be this ObjectName
. Otherwise the
name is unspecified.
The query specified in the QueryNotificationFilter
constructor
is evaluated against this MBeanServer
and ObjectName
,
and the filter returns true if and only if the query does. If the
query throws an exception, then the filter will return false.
The MBean representing the Notification
has one attribute for
every property of the Notification
. Specifically, for every public
method T getX()
in the NotificationClass
, the MBean will
have an attribute called X
of type T
. For example, if the
Notification
is an AttributeChangeNotification
, then the
MBean will have an attribute called AttributeName
of type
"java.lang.String"
, corresponding to the method AttributeChangeNotification.getAttributeName()
.
Query evaluation usually involves calls to the methods of MBeanServer
. The methods have the following behavior:
getAttribute
method returns the
value of the corresponding property.
getObjectInstance
method returns an ObjectInstance
where the ObjectName
is the name of the MBean and the
ClassName
is the class name of the
Notification
.
isInstanceOf
method returns true
if and only if the Notification
's ClassLoader
can load the
named class, and the Notification
is an instance of that class.
These are the only MBeanServer
methods that are needed to
evaluate standard queries. The behavior of the other MBeanServer
methods is unspecified.
Constructor Summary | |
---|---|
QueryNotificationFilter(Class<? extends Notification> notifClass,
String query)
Construct a QueryNotificationFilter that evaluates the query
in the given string to determine whether to accept a notification,
and where the notification must also be an instance of the given class. |
|
QueryNotificationFilter(QueryExp query)
Construct a QueryNotificationFilter that evaluates the given
QueryExp to determine whether to accept a notification. |
|
QueryNotificationFilter(String query)
Construct a QueryNotificationFilter that evaluates the query
in the given string to determine whether to accept a notification. |
Method Summary | |
---|---|
QueryExp |
getQuery()
Retrieve the query that this notification filter will evaluate for each notification. |
boolean |
isNotificationEnabled(Notification notification)
Invoked before sending the specified notification to the listener. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public QueryNotificationFilter(QueryExp query)
QueryNotificationFilter
that evaluates the given
QueryExp
to determine whether to accept a notification.
query
- the QueryExp
to evaluate. Can be null,
in which case all notifications are accepted.public QueryNotificationFilter(String query)
QueryNotificationFilter
that evaluates the query
in the given string to determine whether to accept a notification.
The string is converted into a QueryExp
using
Query.fromString
.
query
- the string specifying the query to evaluate. Can be null,
in which case all notifications are accepted.
IllegalArgumentException
- if the string is not a valid
query string.public QueryNotificationFilter(Class<? extends Notification> notifClass, String query)
Construct a QueryNotificationFilter
that evaluates the query
in the given string to determine whether to accept a notification,
and where the notification must also be an instance of the given class.
The string is converted into a QueryExp
using
Query.fromString
.
notifClass
- the class that the notification must be an instance of.
Cannot be null.query
- the string specifying the query to evaluate. Can be null,
in which case all notifications are accepted.
IllegalArgumentException
- if the string is not a valid
query string, or if notifClass
is null.Method Detail |
---|
public QueryExp getQuery()
public boolean isNotificationEnabled(Notification notification)
NotificationFilter
isNotificationEnabled
in interface NotificationFilter
notification
- The notification to be sent.
true
if the notification has to be sent to the listener, false
otherwise.
|
![]() |
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |