Title: Java Management Extensions
1Java Management Extensions
- Borcon 2004
- Ken Sipe
- kensipe_at_codementor.net
2Overall Presentation Goal
- Defined the problem space and need that JMX
solves. - Provided details on the architecture and
understanding of the technology - Provide resources need to expound on this
learning.
3Speakers Qualifications
- Sun Certified Java 2 Architect.
- Instructor for VisiBroker for Java, OOAD,
Rational Rose, and Java Development. - Frequently speaks on the subject of distributed
computing programming, including CORBA and EJB
architecture. - JBoss Certified Developer )
4Presentation Agenda
- JMX Introduction
- JMX Architecture
- Instrumentation Level
- Agent Level
- Distributed Services Level
- JMX Object Naming
- Leveraging JMX
5What is JMX?
- Java Management Extensions
- Provides runtime application configuration and
management. - Update services on the fly
- No downtime
- Provides monitoring services with notification
services. - Standardized toolsets
- Required for future J2EE Services
6JMX History
- JSR 03
- Early need recognition
- JMX 1.0 Sept 2000
- JMX 1.2 Dec 2002
7Implementations of the Spec
- Sun
- http//java.sun.com/products/JavaManagement/index.
jsp - IBM
- http//alphaworks.ibm.com/tech/TMX4J
- Not really available separately any more, part of
WAS 5.x - AdventNet
- http//adventnet.com/
- JBoss
- http//jboss.org
- mx4j
- http//mx4j.sourceforge.net/
8Wheres JMX currently used
- WAS 5.0
- Tomcat 5.0
- mx4j
- JBoss 2.4.x, 3.x, and 4.0 beta
- jbossmx
- Weblogic 7.x
- Required
- J2EE 1.4
- J2SE 1.5
9Related Specifications
- JSR-77 J2EE Management API
- JSR-88 J2EE Deployment API
- JSR-160 JMX Remote API
- JSR-174 Monitoring and Management for the JVM
machine
10J2EE Management API JSR-77
- J2EE 1.4 Required
- Provides API for Managed Objects
- J2EEDomain
- JVM
- SessionBean
- State Management
- Performance Monitoring
- SNMP
Provides a common tool set to provide monitoring
tools for any J2EE server.
11Java Management Diagram
12J2EE Deployment API JSR-88
- J2EE 1.4 Required
- Leverages JSR-77 for Targeting deployment
13JMX Remote API JSR -160
- JMX specification since 1.0 defined distributed
services as a level of the architecture. However
even specification 1.2 merely mentions it and do
not define it. - Defines the an interoperable, transparent, secure
and flexible solution for clients to connect to
JMX servers. - Defines
- Connectors
- Transport
- Lookup Services
- Bindings
14New to JMX 1.2
- Open Mbeans manitory
- New interface StandardMBean interface
- Class loader repository redesigned and class
loading behavior clarified. - New Security Chapter
- Updates to
- Timer service
- Monitor service
- ObjectName class
15Presentation Agenda
- JMX Introduction
- JMX Architecture
- Instrumentation Level
- Agent Level
- Distributed Services Level
- JMX Object Naming
- Leveraging JMX
16JMX Architecture Diagram
17JMX Architecture
- Instrumentation Level
- Defines the implementation of manageable
resources commonly referred to as MBeans or
Managed Beans. There are several defined types
of MBeans which will be outlined in the
Instrumentation section. This level essentially
defines interfaces and APIs for the developer to
adhere to during the implement of an Mbean. - Agent Level
- Defines the agents and services which will
provide access to the managed resources. This
level is implemented and provided to the
developer providing services and the MBeanServer. - Distributed Level
- This level is defined in the specification as
being needed and provides the details of HTML
accessible, or SNMP capable. The specification
doesnt provide a clear direction here, stating
that it isnt in scope for this phase of the
specification. Tribal knowledge defines this
level as Connectors and Adaptors to the services.
Additionally there is JSR-160 which defines JMX
remote API, which purpose is to provide JMX agent
discovery and access to clients.
18Instrumentation Level
- MBeans
- Must provide the following characteristics
- Public and concrete
- One public constructor
- Does not have to be a no argument constructor
- Categories
- Standard MBean
- Dynamic MBean
19Standard MBean
- Most Simple
- Predefined set of attributes and operations which
are fixed in an Interface - Two Components
- The interface
- This interface defines the publicly exposed API
- It has a specific naming convention
- The class implementation
- Class must implement the defined interface
20Standard MBean Interface Example
- public interface VMMonitorMBean
-
- public String getThreadCount()
- public String getFreeMemory()
- public String getTotalMemory()
21Standard MBean Class Example
- public class VMMonitor implements VMMonitorMBean
- public String getThreadCount()
-
- ThreadGroup root Thread.currentThread().getT
hreadGroup() - while (root.getParent() ! null)
- root root.getParent()
- return root.activeCount() " active
threads" -
- public String getFreeMemory() return
Runtime.getRuntime().freeMemory() " bytes" - public String getTotalMemory() return
Runtime.getRuntime().totalMemory() " bytes"
22JMX 1.2 Standard MBean
- The JMX 1.2 Specification addresses the issue of
forcing the MBean notation on an interface name.
It allows for the creation of a standard MBean
with an interface of an arbitrary name. The
relationship of the interface and the
implementation is managed by the creation of a
StandardMBean object. - The new StandardMBean class removes the necessary
to follow the previously required naming
convention of the MBean interface. Previously
the association of the MBean interface to the
MBean implementation was by naming convention.
The StandardMBean constructor provides the
associate in JMX 1.2. This allows the developer
to name new interfaces any name desired or to
over existing interfaces without change. In our
StandardMBean example, the interface
VMMonitorMBean could be named VMMonitor. In this
case the following would create the StandardMBean
which could then be registered with the
MBeanServer - Mbean new StandardMBean(new VMMonitorImpl(),
VMMonitor.class)
23Dynamic MBean
- Does NOT define fixed list of attributes and
operations. - Attributes and operations are dynamic at runtime.
- Must implement the DynamicMBean interface
- Types
- Dynamic MBean
- Any MBean which is dynamic
- Model MBean
- Extends ModelMBean interface, which extends the
DynamicMBean interface - Open MBean
- Dynamic MBean which follows specific rules
24DynamicMBean Interface
- public interface DynamicMBean
- public MBeanInfo getMBeanInfo()
- public Object getAttribute(String attribute)
throws - AttributeNotFoundException, MBeanException,
ReflectionException - public void setAttribute(Attribute attribute)
throws - AttributeNotFoundException,
InvalidAttributeValueException, - MBeanException, ReflectionException
- public AttributeList getAttributes(String
attributes) - public AttributeList setAttributes(AttributeList
attributes) - public Object invoke(String method, Object
arguments, String params) - throws MBeanException, ReflectionException
25Dynamic MBean Characteristics
- Works much like a COM object.
- Query the interface with the getMBeanInfo()
- Invoke the method with the invoke() method
26MBeanInfo Class
- public class MBeanInfo implements Cloneable,
Serializable -
- public String getClassName()
- public String getDescription()
- public MBeanConstructorInfo getConstructors()
- public MBeanAttributeInfo getAttributes()
- public MBeanOperationInfo getOperations()
- public MBeanNotificationInfo
getNotifications()
27Dynamic MBean Pros / Cons
- Pro
- Programmatic access to the meta data
- MBean is not statically bound to Java class.
- The bean could manage a resource which didnt
exist at the time of development. - Faster execution.
- Cons
- Much more to develop.
28Model MBeans
- Mbean which extends the ModelMBean interface.
- public abstract interface ModelMBean extends
DynamicMBean, PersistentMBean, ModelMBeanNotificat
ionBroadcaster - void setModelMBeanInfo(ModelMBeanInfo
modelMBeanInfo) throws MBeanException,
RuntimeOperationsException - void setManagedResource(Object object, String
string) throws MBeanException, RuntimeOperationsEx
ception, InstanceNotFoundException,
InvalidTargetObjectTypeException -
- PersistentMBean
- Interfaces adds the signatures necessary to
persist the state of the Mbean - ModelMBeanNotificationBroadcaster
- Interface provides the methods necessary to
broadcast notifications
29Model Mbean Characteristics
- Provides a generic template for managing
resources. - Provides extensions to the management interfaces,
such as attributes, operations, constructors, and
notifications. - Defines behavioral properties such as security,
transactions, persistence, and caching.
30Open MBean
- The open in Open MBeans carries the same
connotation as open standards. - It refers to providing MBeans which follow
standards in such a way that there is a high
degree of interoperability. - Uses OpenMBeanInfo vs. MBeanInfo class
- Implements the DynamicMBean interface
- All types are constrained to
31XMBeans (Not part of Spec)
- Term first introduced by JBoss Development team.
- Defines a Dynamic Mbean which is configured and
specified in XML. - All the meta-data is described in XML
- Other follow
- IBM has a XML specification for Mbeans deployed
in WAS - Common Modeler
- Used by Tomcat 5
- http//jakarta.apache.org/commons/modeler/
32Presentation Agenda
- JMX Introduction
- JMX Architecture
- Instrumentation Level
- Agent Level
- Distributed Services Level
- JMX Object Naming
- Leveraging JMX
33Agent Level
- MBean Server
- MBean Registration Component
- Communication Channel
- Pre-defined Service / MBeans
- M-Let Service
- Dynamic loading service
- Timer Service
- Notification service
- Monitoring Service
- Counter Monitor, Gauge Monitor, String Monitor
- Relation Service
- Maintains relationship information
- Notifies on relationship changes
34MBeanServer
- Creating an MBeanServer
- MBeanServer server MBeanServerFactory.createMBe
anServer() - MBeanServer server MBeanServerFactory.createMBe
anServer(server1) - Finding an MBeanServer
- ArrayList servers MBeanServerFactory.findMBeanS
erver(null) - MBeanServer server (MBeanServer)servers.get(0)
35Registering an MBean
- MBeanServer server MBeanServerFactory.createMBea
nServer() - ObjectName name new ObjectName("ServernameMoni
tor") - server.registerMBean(new VMMonitor(), name)
36M-Let Services
- MLet Tag
- ltMLET CODE class ARCHIVEjar listgt
constructor arglist lt/MLETgt - Example
- ltMLET CODEnet.codementor.VMMonitor
ARCHIVEVM.jargt lt/MLETgt
37M-Let Dynamic Loading
- name new ObjectName(servicenameMLET")
- server.registerMBean(new MLet(), name)
-
- server.invoke(name,
- "getMBeansFromURL",
- new Object new
URL("http//codementor.net/config.mlet"), - new StringURL.class.getName
() - )
38Timer Service
- Registration of 2 Mbeans with MBeanServer
- Timer - Broadcaster
- Reciever
- Start the timer
- Invoke the addNotification method on the Timer
- addNotificationListener with a Filter
39Timer Registration
- ObjectName timer new ObjectName("servicenameti
mer") - ObjectName receiver new ObjectName("domainname
timerlistener") - // Timer import javax.management.timer.Timer
- server.registerMBean(new Timer(), timer)
- // TimerReciever is user defined, implements
- // javax.management.NotificationListener
- server.registerMBean(new TimerReceiver(),receiver)
- server.invoke(timer, "start", null, null)
40AddNotification
- Date date new Date(System.currentTimeMillis()
Timer.ONE_SECOND 5) - Integer id (Integer)server.invoke(timer,"a
ddNotification", - new
Object -
"timer.event", // type -
"Notification Message", // message - null,
// user specific data - date
// event time - ,
- new
String -
String.class.getName(), -
String.class.getName(), -
Object.class.getName(), -
Date.class.getName(),
- )
- server.addNotificationListener(timer, receiver,
new ExampleFilter(id), null)
41Notification Filter
- public class ExampleFilter implements
NotificationFilter - Integer id
- public ExampleFilter(Integer id) this.id
id - public boolean isNotificationEnabled(Notificatio
n notification) - // check / filter the notification message
- if(notification.getType().equals("timer.event")
) -
- // we know it is of type TimerNotification
- TimerNotification timerNote
(TimerNotification) notification - if(timerNote.getNotificationID().equals(id))
- // it's a timerNotification and it's this
specific timer notification - return true
-
- return false
-
42Presentation Agenda
- JMX Introduction
- JMX Architecture
- Instrumentation Level
- Agent Level
- Distributed Services Level
- JMX Object Naming
- Leveraging JMX
43Distribution Level
- Very loose in the specification
- Tribal definition Connectors and Adaptors
- HtmlAdaptorServer
- HttpAdaptor
- RMIAdaptor
- JSR-160 Remote Access Specification allows any
transport - RMI
- IIOP
- JMXMP
- HTTP
- SOAP
- JMS
44HtmlAdaptor Example
- HtmlAdaptorServer adaptor new
HtmlAdaptorServer() - adaptor.setPort(8082)
- ObjectName adName new ObjectName("ServernameHt
tpAdaptor") - server.registerMBean(adaptor, adName)
- // start he adaptor service, which blocks the
main thread - adaptor.start()
45Html Console
46HttpAdaptor Console
47Remote Access JSR-160
- MBeanServerConnection
- Provides remote access
- All methods through IOException
- Must explicitly close connections
48Remote / Local Access Comparison
- Local access
- MBeanServer server MBeanServerFactory.createMBea
nServer() - server.createMBean(className, obName)
- Object a server.getAttribute(obName, Attr)
- Set names server.queryNames(...)
- Remote access
- JMXConnector c JMXConnectorFactory.connect(url)
- MBeanServerConnection server c.getMBeanServerCon
nection() - server.createMBean(className, obName)
- Object a server.getAttribute(obName, Attr)
- Set names server.queryNames(...)
- c.close()
49Remote Listeners
- Code is the same as local
- Connector handles forwarding notifications to
remote clients. - class MyListener
- implements NotificationListener ...
- NotificationListener l new MyListener()
- server.addNotificationListener(obName, l)
50JMX Remote URL
- Starts with servicejmx
- servicejmxrmi//host/
- servicejmxjmxmp//hostport
51Presentation Agenda
- JMX Introduction
- JMX Architecture
- Instrumentation Level
- Agent Level
- Distributed Services Level
- JMX Object Naming
- Leveraging JMX
52ObjectName
- Defines a unique name for an Mbean
- Used to distinguish a bean for invocation
- Used to query a server for a specific bean
- Used to manage notification and relationship.
53Object Naming Convention
- Domainpropertyvalue,otherpropertyothervalue
- Special Characters can not be used in the name
- Colon ()
- Comma()
- Equals()
- Asterisks ()
- Example Names
- ServernameMonitor
- WebSpherenameserver1,processserver1,platformco
mmon,nodefezzik,version5.0,typeServer,mbeanIden
tifiercells/fezzik/nodes/fezzik/servers/server1/s
erver.xmlServer_1,cellfezzik,processTypeUnManag
edProcess
54Querying Object Names
- ,typeServer,
- All Mbeans of type Server
- ,cellfezzik
- All Mbeans on the cell named fezzik
55Presentation Agenda
- JMX Introduction
- JMX Architecture
- Instrumentation Level
- Agent Level
- Distributed Services Level
- JMX Object Naming
- Leveraging JMX
- Code and Demos
56VMMonitor Example
- public class VMMonitorTester
- public static void main(String args) throws
Exception - MBeanServer server MBeanServerFactory.createMBe
anServer() - // register the new service
- ObjectName name new ObjectName("VM")
- server.registerMBean(new VMMonitor(),
name) -
- // register the http adaptor
- // HttpAdaptor adaptor new HttpAdaptor()
- HtmlAdaptorServer adaptor new
HtmlAdaptorServer() - adaptor.setPort(8082)
- ObjectName adName new ObjectName("Servern
ameHttpAdaptor") - server.registerMBean(adaptor, adName)
- adaptor.start()
57Working with WAS 5
Starting Server
Starting wsadmin
Query a MBean object name. Get all attributes for
the MBean.
58Demos / Code
- VMMonitor
- Timer Example
- WAS 5
59Need to know Tools
- Mx4j
- http//mx4j.sourceforge.net/
- EJTools
- http//www.ejtools.org/
- https//sourceforge.net/projects/ejtools/
- Jakarta Commons Modeler
- http//jakarta.apache.org/commons/modeler/
- MBeanInspector - (WebSphere)
- http//www.alphaworks.ibm.com/tech/mbeaninspector
- Sun
- http//java.sun.com/jmx
60Conclusion
- JMX is mature
- JMX is here to stay
- JMX defines the standard for Management and
Monitoring
61Questions?
62Thank You
- Please fill out the speaker evaluation
- You can contact me further at ...
kensipe_at_codementor.net