
You have already learned how to use the methods provided by the JMX standard and how to work with the different xml files you need to supply your application with. The following steps will help you to summarize what you have learned until now in one single procedure for instrumenting your application with monitoring:
…. <text-monitor name="Bank name" configuration-group="Name"> <monitored-resource name="BankMBean" type="APPLICATION"/> <text-attribute-mapping> <text-attribute> <observed-resource-attribute name="BankName"/> </text-attribute> </text-attribute-mapping> </text-monitor>
<servlet> <servlet-name> …</servlet-name> <servlet-class>… </servlet-class> <run-as> <role-name>MBeanCreator</role-name> </run-as> </servlet> … <security-role> <description>Role for accessing MBean server</description> <role-name>MBeanCreator</role-name> </security-role>
<web-j2ee-engine> <security-role-map> <role-name> MBeanCreator </role-name> <server-role-name> administrators </server-role-name> </security-role-map> </web-j2ee-engine>
InitialContext initialCtx = new InitialContext();
MBeanServer mbs = (MBeanServer) initialCtx.lookup("jmx");
ObjectName monitoringObjectName = ObjectNameFactory.getNameForApplicationResourcePerNode("BankMBean", RuntimeProperties.get(RuntimeProperties.PROPERTY_APPLICATION), ObjectNameFactory.EMPTY_VALUE, ObjectNameFactory.EMPTY_VALUE);
mbs.registerMBean(mBeanObject, monitoringObjectName);