|
This document describes an optional MBean developed
as an enhancement to TMX4J. It is available
in the jmxext.jar
package. This MBean logs by default
in a log file with the suffix Tmx4j_ unless a user-defined log file name prefix
is specified in the jmx.properties
file. The log level can be configured
with the key JmxUserLogLevel.
All the classes related to this MBean are grouped in the package
com.tivoli.jmx.jar
.
All the MBeans defined in this package are
meant to offer a service to register and
deregister javax.managemet.loading.MLet
s in a MBeanServer according to the jar files
available in some user-defined directories. This
service could be summarized as a jar management
system that allows to update and upgrade
a running JMX agent without stopping the
JVM.
The DirectoryObserver MBean. This MBean is a javax.mangement.NotificationBroadcaster
. It checks a directory in order to verify
whether one or more files have been added,
modified, removed or erased with respect
to a previous check. The check is performed
through an "observe" method. Every
time one of such events occur, a com.tivoli.jmx.jar.ObserverNotification
is emitted to all the listeners registered.
The notification contains the observed file
and specifies one of the following types:
- com.tivoli.jmx.observer.added,
- com.tivoli.jmx.observer.removed,
- com.tivoli.jmx.observer.modified
- com.tivoli.jmx.observer.error
javax.management.NotificationListener
. The "handleNotification" invokes
the "observe" method. In this way,
the DirectoryObserver
can work as a listener of javax.mangement.timer.TimerNotification
s in order to perform a periodic directory
check.
javax.management.NotificationListener
. Every time it receives an "ObserverNotification",
it collects from the notification the notification
type and the file name. According to the
notification type -added, removed, modified
- it can register, deregister or perform
a deregistration and registration of an MLet
linked to the jar file name received in
the notification itself. The MLet
management is done in the same MBeanServer
where this MBean is registered. The reference
to the MBeanServer
is collected at registration time through
the javax.management.MBeanRegistration
interface. Note that all the Mlet
s registered in the MBeanServer
will be added to the javax.management.loading.DefaultLoaderRepository
. This repository is used by the MBeanServer
when a "createMBean" or an "instantiate"
are invoked.MLetManager
will be optionally deregistered at deregistration
time. In case the user does not specify
a
domain, a default one is used. This default
domain is accessible through the static
constant
DEPLOYMENT_DOMAIN.
javax.management.Timer
, a DirectoryObserver
for each directory specified, and an MLetManager
. All the DirectoryObserver
s are added as listeners to the Timer
while the MLetManager
is added as listener in all the DirectoryObserver
s. When the "enable" method is
invoked, the Timer
is started. Periodically the Timer sends
a Notification to all the DirectoryObservers in order to perform the directory check
to verify, for instance, if a new jar has
been added. In turn., if a change is observed,
the MletManger might receive a notification
to register or unregister an MLet. This process
can be stopped through the "disable"
method since it stops the Timer
. At deregistration time the Timer
, the MLetManager
and all the DirectoryObserver
s are deregistered according to the "purge"
attribute value. In case the "purge"
attribute is set to true, the MLetManager
provides, in turn, to deregister all the
MLet
s.
Note that if there is a dependency between
a jar file and other jar files, the Class-Path
attribute in the manifest file should be
used.
The following code snippet shows the basic usage of the JarInstallerMBean:
server.createMBean(
JarInstaller.class.getName(), installerObjName,
new Object[] {new File("/to_be_monitored/jar_dir"), "mydomain"},
new String[] {File.class.getName(), String.class.getName()});
// set the purge flag
Attribute purge = new Attribute("Purge", Boolean.TRUE);
server.setAttribute(installerObjName, purge);
//enable the installer
server.invoke(installerObjName, "enable", null, null);
// create mbeans or instantiate objects using classes available in the
// jar files observed in the directories specified
...
server.createMBean(....);
...
// disable the installer, further changes in the directories
// observed will not be detected.
server.invoke(installerObjName, "disable", null, null);
...
// if the purge attribute is true, the JarInstaller de-registration
// will unregister all the MLets, the Timer and the DirectoryObservers
// in the domain "mydomain"
server.unregisterMBean(installerObjName);
|