<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0"><channel><title>Days of ... (jmx)</title><link>http://blog.yellowbluebus.com</link><description>Useful technology stuff</description><lastBuildDate>Wed, 03 Jul 2013 12:03:00 GMT</lastBuildDate><generator>nikola</generator><docs>http://blogs.law.harvard.edu/tech/rss</docs><item><title>Creating WebSphere 6 application MBeans</title><link>http://blog.yellowbluebus.com/posts/wordpress20060120creating-websphere-6-application-mbeans.html</link><description>&lt;html&gt;&lt;body&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;This is a little step by step guide on how to create and register custom service with JMX interface on WebSphere:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Create class, which implements two interfaces:&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;[java]&lt;/p&gt;
&lt;p&gt;com.ibm.websphere.runtime.CustomService&lt;/p&gt;
&lt;p&gt;com.ibm.websphere.management.JMXManageable&lt;/p&gt;
&lt;p&gt;[/java]&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Implement "initialize" method (inherited from CustomService)&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;This method has a parameter, Properties, which will contain properties defined via WS Administration console. We are interested in one property: externalConfigURLKey. This property contains path to external configuration file (if any is needed).&lt;/p&gt;
&lt;p&gt;This is how to get the path:&lt;/p&gt;
&lt;p&gt;[java]&lt;/p&gt;
&lt;p&gt;public void initialize(Properties configProperties) throws Exception {
 readConfig(configProperties.getProperty(externalConfigURLKey));
}&lt;/p&gt;
&lt;p&gt;[/java]&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;shutdown() method may be left blank.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;implement getType() method (inherited from JMXManageable):&lt;/p&gt;
&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;[java]&lt;/p&gt;
&lt;p&gt;public String getType() {
 return "MyMBean";
}&lt;/p&gt;
&lt;p&gt;[/java]&lt;/p&gt;
&lt;p&gt;Remember the name you returned here!&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;implement getMBeanProperties:&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;[java]&lt;/p&gt;
&lt;p&gt;public Properties getMBeanProperties() {
 Properties props = new Properties();
 props.put("SpecialProperty", "value");
 return props;
}&lt;/p&gt;
&lt;p&gt;[/java]&lt;/p&gt;
&lt;p&gt;I think this will return a list of properties, not declared in MBean descriptor. Read only, of course, since there is no setMBeanProperties() method.&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;implement getters and setters for properties you want to expose:&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;[java]&lt;/p&gt;
&lt;p&gt;public String getUserName() {
 return this.userName;
}&lt;/p&gt;
&lt;p&gt;public void setUserName(String param) {
 this.userName = param;
}&lt;/p&gt;
&lt;p&gt;[/java]&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Create MBean descriptor file, for example myTest.xml.&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;[xml]&lt;/p&gt;
&lt;?xml version="1.0" encoding="UTF-8"?&gt;&lt;mbean type="MyMBean"&gt;&lt;attribute name="UserName" type="java.lang.String" getmethod="getUserName" setmethod="setUserName"&gt;&lt;/attribute&gt;&lt;/mbean&gt;

&lt;p&gt;[/xml]&lt;/p&gt;
&lt;p&gt;IMPORTANT: Make sure that type matches the value you remembered on the step 4!&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;Compile and package. Create .jar, having descriptor in the root. Place .jar somewhere accesible for WebSphere.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Start WebSphere and open Administration console.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Go to Servers - Application Servers - yourserver - Server Infrastructure - Administration - Administration Services&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Click on "Extension MBean providers"&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Click on "New"&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;In the "Classpath" entry type the full path and name of your jar (created on step 8)&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Type something memorable in two other fields and click Apply.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Click on "Extension MBeans" (on the left)&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Click on "New"&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Enter the name of MBean descriptor file (see step 7.)&lt;/p&gt;
&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;for example:&lt;/p&gt;
&lt;p&gt;myTest.xml&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;Enter the type name of your MBean. IMPORTANT: must be the same name as it was on steps 4 and 7.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Click Apply.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Go to Servers - Application Servers - yourserver - Server Infrastructure - Administration - Custom Services&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Click New&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Place check on "Enable service at server startup".&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Enter full class name (with package) of your MBean class (the one we created on step 1) into "Classname" field.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Enter something memorable in "Display Name"&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Enter fill path and file name of the jar file (step 8) into "Classpath".&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;If your service requires configuration file (step 2) enter full path to it into " External Configuration URL"&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Click on Apply.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Click on Save (on top)&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Click Save.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Restart the server.&lt;/p&gt;
&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;Here are the commands, used to verify MBean from admin console:&lt;/p&gt;
&lt;p&gt;To run console:&lt;/p&gt;
&lt;p&gt;wsadmin.bat -conntype SOAP -port 8881&lt;/p&gt;
&lt;p&gt;To make sure that MBean started:&lt;/p&gt;
&lt;p&gt;$AdminControl queryNames &lt;em&gt;:&lt;/em&gt;,type=&amp;gt;&lt;/p&gt;
&lt;p&gt;Store MBean in Tcl variable:&lt;/p&gt;
&lt;p&gt;set mybean [$AdminControl queryNames &lt;em&gt;:&lt;/em&gt;,type=MBeanName]&lt;/p&gt;
&lt;p&gt;See MBean description:&lt;/p&gt;
&lt;p&gt;$Help all $mybean&lt;/p&gt;
&lt;p&gt;See MBean attributes and values:&lt;/p&gt;
&lt;p&gt;$AdminControl getAttributes $mybean&lt;/p&gt;
&lt;p&gt;Set specific attribute:&lt;/p&gt;
&lt;p&gt;$AdminControl setAttribute $mybean UserName mike&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</description><guid>http://blog.yellowbluebus.com/posts/wordpress20060120creating-websphere-6-application-mbeans.html</guid><pubDate>Fri, 20 Jan 2006 00:01:00 GMT</pubDate></item></channel></rss>