170 likes | 339 Views
Managing Components with JMX. Rickard Öberg JBoss. Overview. Purpose of JMX The JMX architecture A JMX example JMX in JBoss Q&A. Purpose of JMX. JMX=Java Management eXtensions Manage Java components Control Configure Allow portable server components
E N D
Managing Components with JMX Rickard Öberg JBoss
Overview • Purpose of JMX • The JMX architecture • A JMX example • JMX in JBoss • Q&A
Purpose of JMX • JMX=Java Management eXtensions • Manage Java components • Control • Configure • Allow portable server components • Integrate into existing management systems
The JMX architecture • Three levels • Instrumentation level (MBean) • Agent level (MBeanServer) • Distributed services level (Adaptor)
The JMX architecture • Standard MBeans • MBean-specific interface declares methods and attributes • Dynamic MBeans • Implements DynamicMBean interface • Allows info about MBean to change at runtime
The JMX architecture • Model MBeans • Use a ModelMBean through delegation
A JMX example package simplejmx; import javax.management.MBeanRegistration; import javax.management.MBeanServer; import javax.management.ObjectName; public class SimpleBean implements MBeanRegistration, SimpleBeanMBean { String phrase; public SimpleBean() { this("Hello World!"); } public SimpleBean(String phrase) { setPhrase(phrase); }
A JMX example // SimpleBeanMBean implementation public void printPhrase() { System.out.println(phrase); } public void setPhrase(String phrase) { this.phrase = phrase; } public String getPhrase() { return phrase; }
A JMX example // MBeanRegistration implementation public ObjectName preRegister(MBeanServer server, ObjectName name) throws java.lang.Exception { return name == null ? new ObjectName(":service=SimpleBean") : name; } public void postRegister(java.lang.Boolean registrationDone) { if (registrationDone.booleanValue()) printPhrase(); } public void preDeregister() throws java.lang.Exception { } public void postDeregister() { } }
A JMX example package simplejmx; public interface SimpleBeanMBean { public void printPhrase(); public void setPhrase(String phrase); public String getPhrase(); } • Name of interface is MBean class name suffixed with ”MBean” • Results in one manageable method, and one manageable attribute
A JMX example • MLet configuration <MLET CODE = "simplejmx.SimpleBean" ARCHIVE="simplejmx.jar" CODEBASE="../../lib/ext/"> <ARG TYPE="java.lang.String" VALUE="Hey World!"> </MLET> <MLET CODE = "simplejmx.SimpleBean" ARCHIVE="simplejmx.jar" CODEBASE="../../lib/ext/” NAME=”:name=Simple”> </MLET> • ARG list needs to match constructor • Name is optional
JMX in JBoss • JMX is used at core of Jboss • All functionality available as MBeans • Currently only Standard MBean model is used • Integration!
JMX in JBoss • Some additional core services, which are MBeans too, have been added • ServiceControl • Lifecycle management (init/start/stop/destroy) • Configuration • Persistent configuration (as XML)
JMX in JBoss • JBoss configuration XML: <server> <!-- Classloading --> <mbean code="org.jboss.web.WebService" name="DefaultDomain:service=Webserver"> <attribute name="Port">8083</attribute> </mbean> <!-- JNDI --> <mbean code="org.jboss.naming.NamingService" name="DefaultDomain:service=Naming"> <attribute name="Port">1099</attribute> </mbean> <!-- Transactions --> <mbean code="org.jboss.tm.TransactionManagerService" name="DefaultDomain:service=TransactionManager"> <attribute name="TransactionTimeout">300</attribute> </mbean> ...
JMX in JBoss • Logging is done as an MBean, and uses notifications for filtering • Custom RMI adaptor • J2EE deployment services pluggable • EJB container factory is an MBean
Q&A • JMX homepage:http://www.javasoft.com/products/JavaManagement/index.html • http://www.jboss.org • rickard@jboss.org