Java Reference
In-Depth Information
the method on the MBean with the given
ObjectName
value. Notice that the class
uses the
server
MBeanServer
reference from its parent.
This class may be overly simple, but it highlights the possibility of implement-
ing MBeans that can be preconfigured to take corrective steps when system errors
occur. By using
JMX
monitors to observe managed attributes, you can design
MBeans to reroute messaging, reconfigure services, or start new processes.
12.4 Sending dated notifications: the timer service
Now that we have discussed the
JMX
monitoring services, let's switch gears and
cover the
JMX
timer service. The timer service is an MBean class available to
every
JMX
agent that emits user-defined notifications at specific times. Each
notification from the timer service contains a date and time when it should be
emitted. Alternatively, the timer service can continue to send a particular notifi-
cation at intervals once a date has been reached.
Other MBeans can use a service such as the timer to send notifications of any
type. For instance, if an MBean is not a
NotificationBroadcaster
, it cannot emit
notifications. However, by using the timer service, it can send notifications at will.
Such a scenario does not take into account the timing abilities of the timer, but it
shows a simple use of the service.
In this part of this chapter we will examine the classes in the
javax.manage-
ment.timer
package, including the
Timer
MBean and its notification class. You
will also create some examples showing the various features of the timer service.
12.4.1
Examining the timer
The first class we need to discuss is
javax.management.timer.Timer
. The
Timer
class is a
JMX
class that defines a Standard MBean containing the
JMX
timer ser-
vice. Before we begin examining individual methods, you need to understand
more about how the timer works.
Timer behavior
As you read in the introductory section, the timer service is an MBean that emits
dated notifications once, or repeatedly at intervals. The timer service is given the
dated notifications by the user. Every notification emitted by a
Timer
MBean is
an instance of the class
TimerNotification
, but the notification type is user
defined. In this manner, many notification types are emitted by the service even
though they are all of the same Java type.