<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Jeff Mesnil &#187; jmx4r</title>
	<atom:link href="http://jmesnil.net/weblog/category/jmx4r/feed/" rel="self" type="application/rss+xml" />
	<link>http://jmesnil.net/weblog</link>
	<description>Thoughts about Java, Web and Software Development</description>
	<lastBuildDate>Wed, 25 Jan 2012 10:23:13 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>&#9873; jmx4r 0.1.3 Is Released</title>
		<link>http://jmesnil.net/weblog/2010/11/20/jmx4r-0-1-3-is-released/</link>
		<comments>http://jmesnil.net/weblog/2010/11/20/jmx4r-0-1-3-is-released/#comments</comments>
		<pubDate>Sat, 20 Nov 2010 17:45:38 +0000</pubDate>
		<dc:creator>Jeff Mesnil</dc:creator>
				<category><![CDATA[jmx4r]]></category>

		<guid isPermaLink="false">http://jmesnil.net/weblog/?p=1324</guid>
		<description><![CDATA[jmx4r 0.1.3 has just been released (jmx4r is a JRuby library which makes it super easy to write simple Ruby scripts to manage Java &#38; JRuby applications using JMX). There is a single new feature on this release: JMX CompositeData attributes can now be accessed as Ruby attributes. Before, to access the committed attribute of [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://github.com/jmesnil/jmx4r">jmx4r</a> 0.1.3 has just been released (jmx4r is a JRuby library which makes it super easy to write simple Ruby scripts to manage Java &amp; JRuby applications using JMX).</p>

<p>There is a single new feature on this release:</p>

<ul>
<li>JMX <code>CompositeData</code> attributes can now be accessed as Ruby attributes.  </li>
</ul>

<p>Before, to access the <code>committed</code> attribute of the <code>heap_memory</code> composite data, you needed to write:</p>


<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;">  memory.<span style="color:#9900CC;">heap_memory_usage</span>.<span style="color:#9900CC;">get</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">&quot;committed&quot;</span><span style="color:#006600; font-weight:bold;">&#41;</span>
&nbsp;
  <span style="color:#008000; font-style:italic;"># or</span>
&nbsp;
  memory.<span style="color:#9900CC;">heap_memory_usage</span><span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#996600;">&quot;committed&quot;</span><span style="color:#006600; font-weight:bold;">&#93;</span></pre></div></div>


<p>while now, you can simply do:</p>


<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;">  memory.<span style="color:#9900CC;">heap_memory_usage</span>.<span style="color:#9900CC;">committed</span></pre></div></div>


<p>You write the attribute like a normal snake_cased attribute and jmx4r will automatically retrieve the corresponding CamelCased attribute from the composite data.</p>

<p>Thanks to <a href="http://dominique.broeglin.fr/">Dominique Broeglin</a> who contributed this enhancement.</p>

<p>When I pushed the new gem on <a href="https://rubygems.org/gems/jmx4r">RubyGems.org</a>, I also noticed that the RDoc is automatically published to <a href="http://rubydoc.info/gems/jmx4r/frames">rubydoc.info</a> and looks much better that the old version that I was pushing to Rubyforge.</p>

<p>As usual, to get this new release, just update the rubygem:</p>

<pre><code>jruby -S gem install jmx4r
</code></pre>

<p>and do not hesitate to contribute:</p>

<pre><code>git clone git://github.com/jmesnil/jmx4r.git
</code></pre>
]]></content:encoded>
			<wfw:commentRss>http://jmesnil.net/weblog/2010/11/20/jmx4r-0-1-3-is-released/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>&#9873; jmx4r 0.1.2 Is Released</title>
		<link>http://jmesnil.net/weblog/2010/08/02/jmx4r-0-1-2-is-released/</link>
		<comments>http://jmesnil.net/weblog/2010/08/02/jmx4r-0-1-2-is-released/#comments</comments>
		<pubDate>Mon, 02 Aug 2010 16:53:15 +0000</pubDate>
		<dc:creator>Jeff Mesnil</dc:creator>
				<category><![CDATA[jmx4r]]></category>

		<guid isPermaLink="false">http://jmesnil.net/weblog/?p=1174</guid>
		<description><![CDATA[jmx4r 0.1.2 has just been released (jmx4r is a JRuby library which makes it super easy to write simple Ruby scripts to manage Java &#38; JRuby applications using JMX). it fixes a bug in the getAttributes() method that is exposed by Ruby objects extending jmx4r&#8217;s DynamicMBean class I introduced the bug but it is one [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://github.com/jmesnil/jmx4r">jmx4r</a> 0.1.2 has just been released (jmx4r is a JRuby library which makes it super easy to write simple Ruby scripts to manage Java &amp; JRuby applications using JMX).</p>

<ul>
<li>it fixes a bug in the <code>getAttributes()</code> method that is exposed by Ruby objects extending jmx4r&#8217;s <code>DynamicMBean</code> class</li>
</ul>

<p>I introduced the bug but it is one of the rare cases where I would still blame JMX API. Its <a href="http://download.oracle.com/javase/1.5.0/docs/api/javax/management/DynamicMBean.html">DynamicMBean</a> interface has
two methods:</p>

<ul>
<li><code>getAttribute(String attribute)</code></li>
<li><code>getAttributes(String[] attributes)</code></li>
</ul>

<p>Following the <a href="http://en.wikipedia.org/wiki/Principle_of_least_surprise">principle of least surprise</a>, I expected <code>getAttribute(String)</code> to return the value of the attribute and <code>getAttributes(String[])</code> to return a collection of the attribute values. But that&#8217;s not the case. As expected <code>getAttribute(String)</code> returns the value of the attribute but <code>getAttributes(String[])</code> returns a <code>AttributeList</code> which is a list of <code>Attribute</code> objects (which in turns contains the name and value of an attribute).<br />
jmx4R 0.1.2 fixes the issue and make sure the methods return the correct objects.</p>

<p>JMX is one of my favorite Java API, simple, flexible and powerful at the same time. Its evolution made it both a bit uglier and more convenient (I wish open types were more simpler to use and less verbose to declare). Providing a library to use JMX in JRuby applications is the perfect match between a simple and powerful library (JMX) and a simple and powerful language (Ruby) on a <strike>simple and</strike> powerful platform (JVM).</p>

<p>From time to time, I receive mails inquiring about the status of jmx4r.<br />
I no longer use jmx4r in my daily job and it is not actively developed. However it is actively maintained. If you find bugs, I can release a new version quite fast. jmx4r users are awesome and most of the time, they provide patches when they report bugs.<br />
If you have ideas for improvements, do not hesitate to send me a mail or fork the project. Most recent contributions were done through forks on GitHub.</p>

<p>Once again, thanks to all the contributors and users who help make jmx4r even more useful!</p>

<p>As usual, to get this new release, just update the rubygem:</p>

<pre><code>jruby -S gem install jmx4r
</code></pre>

<p>and do not hesitate to contribute:</p>

<pre><code>git clone git://github.com/jmesnil/jmx4r.git
</code></pre>
]]></content:encoded>
			<wfw:commentRss>http://jmesnil.net/weblog/2010/08/02/jmx4r-0-1-2-is-released/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>&#9873; jmx4r: How to Use Dotted MBean Attribute Names</title>
		<link>http://jmesnil.net/weblog/2010/01/20/jmx4r-how-to-use-dotted-mbean-attribute-names/</link>
		<comments>http://jmesnil.net/weblog/2010/01/20/jmx4r-how-to-use-dotted-mbean-attribute-names/#comments</comments>
		<pubDate>Wed, 20 Jan 2010 17:56:15 +0000</pubDate>
		<dc:creator>Jeff Mesnil</dc:creator>
				<category><![CDATA[jmx4r]]></category>

		<guid isPermaLink="false">http://jmesnil.net/weblog/?p=893</guid>
		<description><![CDATA[An user reported an issue with jmx4r because he was not able to access a MBean attribute. See for example attribute names under the amx:j2eeType=X-MonitoringDottedNames,name=na mbean of a GlassFish instance. Trying to get the value of an attribute like server.http_service.file_cache.maxentries_lastsampletime doesn&#8217;t work. He is right that jmx4r does not work with dotted attributes. For example, [...]]]></description>
			<content:encoded><![CDATA[<p>An user reported an <a href="http://github.com/jmesnil/jmx4r/issues#issue/1">issue</a> with <a href="http://github.com/jmesnil/jmx4r/">jmx4r</a> because he was not able to access a MBean attribute.</p>

<blockquote>
  <p>See for example attribute names under the amx:j2eeType=X-MonitoringDottedNames,name=na mbean of a GlassFish instance.</p>
  
  <p>Trying to get the value of an attribute like <code>server.http_service.file_cache.maxentries_lastsampletime</code> doesn&#8217;t work.</p>
</blockquote>

<p>He is right that jmx4r does not work with dotted attributes. For example, this code will fail:</p>


<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;">server = <span style="color:#6666ff; font-weight:bold;">JMX::MBean</span>.<span style="color:#9900CC;">find_by_name</span> <span style="color:#996600;">&quot;amx:j2eeType=X-MonitoringDottedNames,name=na&quot;</span>
<span style="color:#CC0066; font-weight:bold;">puts</span> server.<span style="color:#9900CC;">http_service</span>.<span style="color:#9900CC;">file_cache</span>.<span style="color:#9900CC;">maxentries_lastsampletime</span></pre></div></div>


<p>JMX supports dotted attributes but they can not be used directly with jmx4r because of Ruby syntax.<br />
Ruby will read <code>server.http_service.file_cache.maxentries_lastsampletime</code> and will rightfully call <code>http_service</code> on the 
<code>server</code> object first. But there is no such method or attribute and the call will fail.</p>

<p>To circumvent this issue and be able to use jmx4r with dotted MBean attributes, you can use Ruby <a href="http://ruby-doc.org/core/classes/Object.html#M000332">Object#send</a>.</p>

<p>Instead of</p>


<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;">server.<span style="color:#9900CC;">http_service</span>.<span style="color:#9900CC;">file_cache</span>.<span style="color:#9900CC;">maxentries_lastsampletime</span></pre></div></div>


<p>you will have to use</p>


<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;">server.<span style="color:#9900CC;">send</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">&quot;http_service.file_cache.maxentries_lastsampletime&quot;</span><span style="color:#006600; font-weight:bold;">&#41;</span></pre></div></div>


<p>This looks ugly but it works.</p>

<p>The user proposed to have jmx4r objects implement <code>[]</code> and work like a Hash to support dotted names.
I am not convinced that such edge cases are worth supporting <code>[]</code> but if you think otherwise, do not hesitate to vote for this <a href="http://github.com/jmesnil/jmx4r/issues#issue/1">feature</a> and I will add it to jmx4r.</p>
]]></content:encoded>
			<wfw:commentRss>http://jmesnil.net/weblog/2010/01/20/jmx4r-how-to-use-dotted-mbean-attribute-names/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>&#9873; jmx4r 0.1.0 Is Released</title>
		<link>http://jmesnil.net/weblog/2009/10/22/jmx4r-0-1-0-is-released/</link>
		<comments>http://jmesnil.net/weblog/2009/10/22/jmx4r-0-1-0-is-released/#comments</comments>
		<pubDate>Thu, 22 Oct 2009 17:31:29 +0000</pubDate>
		<dc:creator>Jeff Mesnil</dc:creator>
				<category><![CDATA[java]]></category>
		<category><![CDATA[jmx]]></category>
		<category><![CDATA[jmx4r]]></category>
		<category><![CDATA[jruby]]></category>
		<category><![CDATA[misc]]></category>

		<guid isPermaLink="false">http://jmesnil.net/weblog/?p=870</guid>
		<description><![CDATA[jmx4r 0.1.0 has just been released (jmx4r is a JRuby library which makes it super easy to write simple Ruby scripts to manage Java applications using JMX). fixed compatibility with Rake 0.8.7 (thanks Dan!) fixed dynamic mbean issues where attributes and methods were added to all the dynamic mbeans in the thread (thanks Munesse!) There [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://github.com/jmesnil/jmx4r">jmx4r</a> 0.1.0 has just been released (jmx4r is a JRuby library which makes it super easy to write simple Ruby scripts to manage Java applications using JMX).</p>

<ul>
<li>fixed compatibility with Rake 0.8.7 (thanks <a href="http://twitter.com/jrubyist">Dan</a>!)</li>
<li>fixed dynamic mbean issues where attributes and methods were added to <em>all</em> the dynamic mbeans in the thread (thanks <a href="http://muness.blogspot.com/">Munesse</a>!)</li>
</ul>

<p>There is also two new features:</p>

<ul>
<li>support for Java CamelCase style in addition to Ruby snake_case (thanks again to Dan)</li>
</ul>


<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;">logging = <span style="color:#6666ff; font-weight:bold;">JMX::MBean</span>.<span style="color:#9900CC;">find_by_name</span> <span style="color:#996600;">&quot;java.util.logging:type=Logging&quot;</span>
&nbsp;
<span style="color:#008000; font-style:italic;"># Ruby syntax works</span>
logging.<span style="color:#9900CC;">set_logger_level</span> <span style="color:#996600;">&quot;global&quot;</span>, <span style="color:#996600;">&quot;FINEST&quot;</span>
<span style="color:#008000; font-style:italic;"># Java syntax works too</span>
logging.<span style="color:#9900CC;">setLoggerLevel</span> <span style="color:#996600;">&quot;global&quot;</span>, <span style="color:#996600;">&quot;FINEST&quot;</span></pre></div></div>


<ul>
<li>Connection to a local JVM (thanks to <a href="http://github.com/sat13f">Mr ohtsuka</a>).
You can now connect to a JVM running on the same machine without adding the <code>com.sun.management.jmxremote</code> system properties.</li>
</ul>

<p>For example, start an instance of jconsole without any additional system properties:</p>


<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">$ jconsole <span style="color: #000000; font-weight: bold;">&amp;</span></pre></div></div>


<p>You can now manage this Java application locally:</p>


<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;"><span style="color:#CC0066; font-weight:bold;">require</span> <span style="color:#996600;">'rubygems'</span>
<span style="color:#CC0066; font-weight:bold;">require</span> <span style="color:#996600;">'jmx4r'</span>
&nbsp;
<span style="color:#008000; font-style:italic;"># :command is a regexp corresponding to the Java process to connect to</span>
<span style="color:#6666ff; font-weight:bold;">JMX::MBean</span>.<span style="color:#9900CC;">establish_connection</span> <span style="color:#ff3333; font-weight:bold;">:command</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#006600; font-weight:bold;">/</span>JConsole<span style="color:#006600; font-weight:bold;">/</span>
memory = <span style="color:#6666ff; font-weight:bold;">JMX::MBean</span>.<span style="color:#9900CC;">find_by_name</span> <span style="color:#996600;">&quot;java.lang:type=Memory&quot;</span>
memory.<span style="color:#9900CC;">gc</span></pre></div></div>


<p>In addition to the previous <code>:host</code>, <code>:port</code> and <code>:url</code> arguments that you can pass to establish a JMX connection, there is now <code>:command</code> which must be a regular expression corresponding to the local Java process you want to connect to. You can find the name of the process using <code>jps</code>:</p>


<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">$ jps
<span style="color: #000000;">4255</span> JConsole
<span style="color: #000000;">4395</span> Jps</pre></div></div>


<p>You can connect to a local Java application running on Java 5 or 6. Is someone interested to contribute support for JDK7 too?</p>

<p>Once again, thanks to all the contributors and users who help make jmx4r even more useful!</p>

<p>As usual, to get this new release, just update the rubygem:</p>

<pre><code>jruby -S gem install jmx4r
</code></pre>

<p>and do not hesitate to contribute:</p>

<pre><code>git clone git://github.com/jmesnil/jmx4r.git
</code></pre>
]]></content:encoded>
			<wfw:commentRss>http://jmesnil.net/weblog/2009/10/22/jmx4r-0-1-0-is-released/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>&#9873; jmx4r 0.0.8: &#8220;Through the Looking Glass&#8221;</title>
		<link>http://jmesnil.net/weblog/2009/06/15/jmx4r-0-0-8-through-the-looking-glass/</link>
		<comments>http://jmesnil.net/weblog/2009/06/15/jmx4r-0-0-8-through-the-looking-glass/#comments</comments>
		<pubDate>Mon, 15 Jun 2009 17:35:42 +0000</pubDate>
		<dc:creator>Jeff Mesnil</dc:creator>
				<category><![CDATA[jmx]]></category>
		<category><![CDATA[jmx4r]]></category>
		<category><![CDATA[jruby]]></category>

		<guid isPermaLink="false">http://jmesnil.net/weblog/?p=425</guid>
		<description><![CDATA[jmx4r 0.0.8 has just been released. Why &#8220;Through the Looking Glass&#8221;? Until this version, jmx4r was a library which made it super easy to write simple Ruby scripts to manage Java applications using JMX. With this version, the perspective has changed, we went through the looking glass and are now on the other side: jmx4r [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://github.com/jmesnil/jmx4r/">jmx4r</a> 0.0.8 has just been released.</p>

<p>Why &#8220;Through the Looking Glass&#8221;?<br />
Until this version, jmx4r was a library which made it super easy to write <em>simple Ruby scripts to manage Java applications</em> using JMX.</p>

<p>With this version, the perspective has changed, we went through the looking glass and are now on the other side: jmx4r makes it super easy to <em>directly manage Ruby applications</em> by leveraging JRuby and the Java platform.</p>

<p>A 30-line example is worth 10,000 words:</p>


<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;"><span style="color:#008000; font-style:italic;">#!/usr/bin/env jruby</span>
<span style="color:#CC0066; font-weight:bold;">require</span> <span style="color:#996600;">'rubygems'</span>
<span style="color:#CC0066; font-weight:bold;">require</span> <span style="color:#996600;">'jmx4r'</span>
&nbsp;
<span style="color:#008000; font-style:italic;"># a regular Ruby object we want to manage</span>
<span style="color:#9966CC; font-weight:bold;">class</span> Foo <span style="color:#006600; font-weight:bold;">&lt;</span> <span style="color:#6666ff; font-weight:bold;">JMX::DynamicMBean</span>
   operation <span style="color:#996600;">&quot;a polite management operation&quot;</span>
   parameter :<span style="color:#CC0066; font-weight:bold;">string</span>, <span style="color:#996600;">&quot;how do you want to be called?&quot;</span>
   returns :<span style="color:#CC0066; font-weight:bold;">string</span>
   <span style="color:#9966CC; font-weight:bold;">def</span> hello<span style="color:#006600; font-weight:bold;">&#40;</span>name=<span style="color:#996600;">&quot;world&quot;</span><span style="color:#006600; font-weight:bold;">&#41;</span>
      <span style="color:#996600;">&quot;hello, #{name}!&quot;</span>
   <span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
   operation <span style="color:#996600;">&quot;double the value&quot;</span>
   parameter <span style="color:#ff3333; font-weight:bold;">:long</span>
   returns <span style="color:#ff3333; font-weight:bold;">:long</span>
   <span style="color:#9966CC; font-weight:bold;">def</span> double<span style="color:#006600; font-weight:bold;">&#40;</span>value<span style="color:#006600; font-weight:bold;">&#41;</span>
     value <span style="color:#006600; font-weight:bold;">*</span> <span style="color:#006666;">2</span>
   <span style="color:#9966CC; font-weight:bold;">end</span>
<span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
<span style="color:#008000; font-style:italic;"># Java objects to register the Ruby object in the platform</span>
import java.<span style="color:#9900CC;">lang</span>.<span style="color:#9900CC;">management</span>.<span style="color:#9900CC;">ManagementFactory</span>
import javax.<span style="color:#9900CC;">management</span>.<span style="color:#9900CC;">ObjectName</span>
&nbsp;
foo = Foo.<span style="color:#9900CC;">new</span>
<span style="color:#008000; font-style:italic;"># each managed object needs an unique 'ObjectName'</span>
object_name = ObjectName.<span style="color:#9900CC;">new</span> <span style="color:#996600;">&quot;foo:type=Foo&quot;</span> 
ManagementFactory.<span style="color:#9900CC;">platform_mbean_server</span>.<span style="color:#9900CC;">register_mbean</span> foo, object_name
&nbsp;
<span style="color:#008000; font-style:italic;"># we keep the script running to manage it using jconsole</span>
<span style="color:#CC0066; font-weight:bold;">puts</span> <span style="color:#996600;">&quot;open jconsole to manage foo registered under 'foo:type=Foo'&quot;</span>
<span style="color:#CC0066; font-weight:bold;">gets</span>
ManagementFactory.<span style="color:#9900CC;">platform_mbean_server</span>.<span style="color:#9900CC;">unregister_mbean</span> object_name</pre></div></div>


<p>Save this script and run it using JRuby (tested it with version 1.3.0):</p>

<pre><code>$  jruby bean.rb
open jconsole to manage foo registered under 'foo:type=Foo'
</code></pre>

<p>That&#8217;s it: you have a Ruby application which can be managed using any Java management console.</p>

<p>For example, if we start jconsole to manage the bean.rb script:</p>

<p><img src="http://jmesnil.net/weblog/wp-content/uploads/2009/06/jconsole_connection1.png" alt="jconsole_connection" title="jconsole_connection" width="426" height="175" class="alignnone size-full wp-image-465" /></p>

<p>In the MBeans tab, we can expand Foo to see the management operation:</p>

<p><img src="http://jmesnil.net/weblog/wp-content/uploads/2009/06/jconsole_operation1.png" alt="jconsole_operation" title="jconsole_operation" width="872" height="370" class="alignnone size-full wp-image-466" /></p>

<p>And we can finally invoke it (e.g. by pushing the <code>hello</code> or <code>double"</code> button) and get a result after the method is called on the Ruby object:</p>

<p><img src="http://jmesnil.net/weblog/wp-content/uploads/2009/06/jconsole_result.png" alt="jconsole_result" title="jconsole_result" width="262" height="167" class="alignnone size-full wp-image-436" /></p>

<h3>How to manage a Ruby object</h3>

<p>To be manageable from a management console, the Ruby object must inherit from
<code>JMX::DynamicMBean</code></p>

<p>Since Java is statically typed, you also need to give some hints to help Java calls the Ruby object.</p>

<p>Each method you want to expose as a <em>management operation</em> must be annotated with:</p>

<ul>
<li>an <code>operation</code> (and an optional description)</li>
<li>a list of <code>parameter</code> (with a mandatory type and optional name and description)</li>
<li>a <code>returns</code> type</li>
</ul>

<p>The <code>returns</code> and <code>parameter</code> type must be one of <code>:boolean, :byte, :int, :long, :float, :double, :list, :map, :set, :string, and :void</code></p>

<p>For example, if we have a method which prints the name and age of an user, it can be minimally exposed as:</p>


<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;">   operation
   parameter :<span style="color:#CC0066; font-weight:bold;">string</span>
   parameter <span style="color:#ff3333; font-weight:bold;">:int</span>
   returns <span style="color:#ff3333; font-weight:bold;">:void</span>
   <span style="color:#9966CC; font-weight:bold;">def</span> display<span style="color:#006600; font-weight:bold;">&#40;</span>name, age<span style="color:#006600; font-weight:bold;">&#41;</span>
     <span style="color:#CC0066; font-weight:bold;">puts</span> <span style="color:#996600;">&quot;#{name} is #{age} years old
   end</span></pre></div></div>


<p>Exposing Ruby attributes for management is <em>even simpler</em>:</p>


<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;"><span style="color:#9966CC; font-weight:bold;">class</span> AttributeTypesMBean <span style="color:#006600; font-weight:bold;">&lt;</span> <span style="color:#6666ff; font-weight:bold;">JMX::DynamicMBean</span>
   rw_attribute <span style="color:#ff3333; font-weight:bold;">:my_attr</span>, :<span style="color:#CC0066; font-weight:bold;">string</span>, <span style="color:#996600;">&quot;a read/write String attribute&quot;</span>
   r_attribute <span style="color:#ff3333; font-weight:bold;">:another_attr</span>, <span style="color:#ff3333; font-weight:bold;">:int</span>, <span style="color:#996600;">&quot;a readonly int attribute&quot;</span>
&nbsp;
    ...
  <span style="color:#9966CC; font-weight:bold;">end</span></pre></div></div>


<p>the <code>rw_attribute</code> declares a Ruby attribute (using <code>attr_accessor</code>) which is also exposed for management and can be read and write from a management console. Likewise, <code>r_attribute</code> declares a read-only Ruby attribute  (using <code>attr_reader</code>) which can only be read from a management console.</p>

<p><a href="http://jmx4r.rubyforge.org/doc/">DynamicMBean RDoc</a> contains a description of all these annotations.</p>

<p>Finally, the code to register/unregister the Ruby object is taken directly from the Java library using <code>ManagementFactory.platform_mbean_server</code> to access the Java Platform&#8217;s MBean Server.<br />
Each managed object must be registered with an unique ObjectName that is created using the <code>javax.management.ObjectName</code> class (the <a href="http://java.sun.com/javase/technologies/core/mntr-mgmt/javamanagement/best-practices.jsp">JMX Best Practices</a> is a good start for an overview of JMX, the umbrella name for management in Java).</p>

<p>Most of this code was taken from the <code>jmx</code> module of <a href="http://rubyforge.org/projects/jruby-extras/">jruby-extras</a>.
I fixed some issues with it but, from now on, the remaining bugs are likely written by me!</p>

<p>jmx4r was a simple and small library to write Ruby scripts to manage Java applications.<br />
It is now also a simple and small library to manage <em>Ruby applications</em>.</p>

<p>With the success of <a href="http://jruby.org">JRuby</a> and the rise of Ruby applications running on Java  such as <a href="http://torquebox.org">Torquebox</a>, <a href="http://fi.github.com/">GitHub:fi</a>, etc., I believe it can be very useful to leverage the features provided by the Java platform to manage Ruby applications.</p>

<p>As usual, to get this new release, just update the rubygem:</p>

<pre><code>jruby -S gem install jmx4r
</code></pre>

<p>and do not hesitate to contribute:</p>

<pre><code>git clone [git://github.com/jmesnil/jmx4r.git][jmx4r]
</code></pre>
]]></content:encoded>
			<wfw:commentRss>http://jmesnil.net/weblog/2009/06/15/jmx4r-0-0-8-through-the-looking-glass/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>&#9873; JRuby Cookbook Has a Section About jmx4r</title>
		<link>http://jmesnil.net/weblog/2008/11/26/jruby-cookbook-has-a-section-about-jmx4r/</link>
		<comments>http://jmesnil.net/weblog/2008/11/26/jruby-cookbook-has-a-section-about-jmx4r/#comments</comments>
		<pubDate>Wed, 26 Nov 2008 16:42:51 +0000</pubDate>
		<dc:creator>Jeff Mesnil</dc:creator>
				<category><![CDATA[book]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[jmx]]></category>
		<category><![CDATA[jmx4r]]></category>
		<category><![CDATA[ruby]]></category>

		<guid isPermaLink="false">http://jmesnil.net/weblog/?p=398</guid>
		<description><![CDATA[I noticed today that O&#8217;Reilly just released JRuby Cookbook. I have a few ideas I&#8217;d like to implement using JRuby and I was browsing the table of contents to check if the book could be helpful. I was pleasantly surprised to see that it contains a section about &#8220;Performing Remote Management with JMX&#8221; using jmx4r [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://oreilly.com/catalog/9780596519803/"><img src='http://oreilly.com/catalog/covers/9780596519803_cat.gif' class='alignleft' /></a></p>

<p>I noticed today that O&#8217;Reilly just released <a href="http://oreilly.com/catalog/9780596519803/">JRuby Cookbook</a>. I have a few ideas I&#8217;d like to implement using <a href="http://jruby.codehaus.org/">JRuby</a> and I was browsing the <a href="http://oreilly.com/catalog/9780596519803/toc.html">table of contents</a> to check if the book could be helpful.</p>

<p>I was pleasantly surprised to see that it contains a section about &#8220;Performing Remote Management with JMX&#8221; using <a href="http://code.google.com/p/jmx4r/">jmx4r</a> (you can read a preview of the section by expanding it from the <a href="http://oreilly.com/catalog/9780596519803/toc.html">table of contents</a>).</p>

<p>I&#8217;m obviously biased but I  deeply believe that a small library such as jmx4r (less than 200 <abbr title="Source Lines of Code">SLOC</abbr> for the <a href="http://github.com/jmesnil/jmx4r/tree/master/lib/jmx4r.rb">main file</a> and 1/3 are comments) shows what the combination of Ruby and Java can achieve.<br />
JRuby leverages the strong Java runtime (with its garbage collection and hotspot) and allows to access a wide range of Java libraries with all the strengths of the Ruby language.</p>

<p>For example, in jmx4r case, I extensively use Ruby metaprogramming toolset to dynamically create the properties and methods correponding to the MBean attributes and operations.</p>

<p>There are also other <a href="http://syntatic.wordpress.com/2008/11/25/the-closet-jrubyists/">stories</a> which demonstrates what JRuby brings to the table coming from the C-Ruby world.</p>

<p>I&#8217;m looking forward to read this cookbook and write some ruby code built on top of the Java platform.</p>
]]></content:encoded>
			<wfw:commentRss>http://jmesnil.net/weblog/2008/11/26/jruby-cookbook-has-a-section-about-jmx4r/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>&#9873; jmx4r 0.0.6 is released</title>
		<link>http://jmesnil.net/weblog/2008/08/01/jmx4r-006-is-released/</link>
		<comments>http://jmesnil.net/weblog/2008/08/01/jmx4r-006-is-released/#comments</comments>
		<pubDate>Fri, 01 Aug 2008 17:49:50 +0000</pubDate>
		<dc:creator>Jeff Mesnil</dc:creator>
				<category><![CDATA[java]]></category>
		<category><![CDATA[jmx]]></category>
		<category><![CDATA[jmx4r]]></category>
		<category><![CDATA[jruby]]></category>

		<guid isPermaLink="false">http://jmesnil.net/weblog/?p=213</guid>
		<description><![CDATA[jmx4r 0.0.6 has just been released (jmx4r is a JRuby library which makes it super easy to write simple Ruby scripts to manage Java applications using JMX). This release adds helper methods to make it more natural to work with TabularData attributes and ObjectName properties Iterate over TabularData attribute TabularData attributes now behave like regular [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://code.google.com/p/jmx4r/">jmx4r</a> 0.0.6 has just been released (jmx4r is a JRuby library which makes it super easy to write simple Ruby scripts to manage Java applications using JMX).</p>

<p>This release adds helper methods to make it more natural to work with <a href="http://java.sun.com/j2se/1.5.0/docs/api/javax/management/openmbean/TabularData.html">TabularData</a> attributes and <a href="http://java.sun.com/j2se/1.5.0/docs/api/javax/management/ObjectName.html">ObjectName</a> properties</p>

<h3>Iterate over TabularData attribute</h3>

<p>TabularData attributes now behave like regular Ruby <a href="http://www.ruby-doc.org/core/classes/Enumerable.html">Enumerable</a>:</p>


<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;"><span style="color:#008000; font-style:italic;">#!/usr/bin/env jruby</span>
<span style="color:#CC0066; font-weight:bold;">require</span> <span style="color:#996600;">'rubygems'</span>
<span style="color:#CC0066; font-weight:bold;">require</span> <span style="color:#996600;">'jmx4r'</span>
&nbsp;
runtime = <span style="color:#6666ff; font-weight:bold;">JMX::MBean</span>.<span style="color:#9900CC;">find_by_name</span> <span style="color:#996600;">&quot;java.lang:type=Runtime&quot;</span>
<span style="color:#008000; font-style:italic;"># runtime.system_properties is a TabularData</span>
runtime.<span style="color:#9900CC;">system_properties</span>.<span style="color:#9900CC;">each</span> <span style="color:#9966CC; font-weight:bold;">do</span> <span style="color:#006600; font-weight:bold;">|</span> sysprop <span style="color:#006600; font-weight:bold;">|</span> 
  <span style="color:#CC0066; font-weight:bold;">puts</span> <span style="color:#996600;">&quot;#{sysprop[&quot;</span>key<span style="color:#996600;">&quot;]} = #{sysprop[&quot;</span>value<span style="color:#996600;">&quot;]}&quot;</span>
<span style="color:#9966CC; font-weight:bold;">end</span></pre></div></div>


<h3>ObjectName properties</h3>

<p>ObjectName properties can now be accessed using the <code>[]</code> method:</p>


<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;"><span style="color:#008000; font-style:italic;">#!/usr/bin/env jruby</span>
<span style="color:#CC0066; font-weight:bold;">require</span> <span style="color:#996600;">'rubygems'</span>
<span style="color:#CC0066; font-weight:bold;">require</span> <span style="color:#996600;">'jmx4r'</span>
<span style="color:#CC0066; font-weight:bold;">require</span> <span style="color:#996600;">'jconsole'</span>
&nbsp;
mem_pools = <span style="color:#6666ff; font-weight:bold;">JMX::MBean</span>.<span style="color:#9900CC;">find_all_by_name</span> <span style="color:#996600;">&quot;java.lang:type=MemoryPool,*&quot;</span>
mem_pools.<span style="color:#9900CC;">each</span> <span style="color:#9966CC; font-weight:bold;">do</span> <span style="color:#006600; font-weight:bold;">|</span>pool<span style="color:#006600; font-weight:bold;">|</span>
  <span style="color:#008000; font-style:italic;"># print the 'name' property of the pool's ObjectName</span>
  <span style="color:#CC0066; font-weight:bold;">puts</span> pool.<span style="color:#9900CC;">object_name</span><span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#996600;">&quot;name&quot;</span><span style="color:#006600; font-weight:bold;">&#93;</span>
<span style="color:#9966CC; font-weight:bold;">end</span></pre></div></div>


<p>As usual, to get this new release, just update the rubygem:</p>

<pre><code>jruby -S gem install jmx4r
</code></pre>

<p>and do not hesitate to contribute:</p>

<pre><code>git clone git://github.com/jmesnil/jmx4r.git
</code></pre>
]]></content:encoded>
			<wfw:commentRss>http://jmesnil.net/weblog/2008/08/01/jmx4r-006-is-released/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>&#9873; Monitoring Weblogic 9.2 with JMX and JRuby</title>
		<link>http://jmesnil.net/weblog/2008/04/18/monitoring-weblogic-92-with-jmx-and-jruby/</link>
		<comments>http://jmesnil.net/weblog/2008/04/18/monitoring-weblogic-92-with-jmx-and-jruby/#comments</comments>
		<pubDate>Fri, 18 Apr 2008 15:43:05 +0000</pubDate>
		<dc:creator>Jeff Mesnil</dc:creator>
				<category><![CDATA[java]]></category>
		<category><![CDATA[jmx]]></category>
		<category><![CDATA[jmx4r]]></category>
		<category><![CDATA[jruby]]></category>
		<category><![CDATA[ruby]]></category>

		<guid isPermaLink="false">http://jmesnil.net/weblog/?p=171</guid>
		<description><![CDATA[From Tim Koopmans: After getting nowhere with lack luster HP support, I turned to the power of the Open Source community and got a very simple script up and running to remotely monitor Weblogic JVM Performance and JMS queues using JMX and JRuby. [...] This script will enumerate JVM performance and also JMS queue depths [...]]]></description>
			<content:encoded><![CDATA[<p>From <a href="http://90kts.com/blog/2008/monitoring-weblogic-92-with-jmx-and-jruby/">Tim Koopmans</a>:</p>

<blockquote>
  <p>After getting nowhere with lack luster HP support, I turned to the power of the Open Source community and  got a very simple script up and running to remotely monitor Weblogic JVM Performance and JMS queues using JMX and JRuby.</p>
  
  <p>[...]</p>
  
  <p>This script will enumerate JVM performance and also JMS queue depths in around 50 lines of code</p>
</blockquote>

<p>That&#8217;s a good example of the conciseness that JRuby brings to the Java platform: in 50 lines of code, Tim connects to a remote Weblogic MBean server, retrieves attributes about memory usage and JMS queue and stores them in a CSV file.</p>
]]></content:encoded>
			<wfw:commentRss>http://jmesnil.net/weblog/2008/04/18/monitoring-weblogic-92-with-jmx-and-jruby/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>&#9873; jmx4r 0.0.5 is released with support for custom JMX URL</title>
		<link>http://jmesnil.net/weblog/2008/04/14/jmx4r-005-is-released-with-support-for-custom-jmx-url/</link>
		<comments>http://jmesnil.net/weblog/2008/04/14/jmx4r-005-is-released-with-support-for-custom-jmx-url/#comments</comments>
		<pubDate>Mon, 14 Apr 2008 14:48:06 +0000</pubDate>
		<dc:creator>Jeff Mesnil</dc:creator>
				<category><![CDATA[java]]></category>
		<category><![CDATA[jmx]]></category>
		<category><![CDATA[jmx4r]]></category>
		<category><![CDATA[jruby]]></category>
		<category><![CDATA[ruby]]></category>

		<guid isPermaLink="false">http://jmesnil.net/weblog/?p=169</guid>
		<description><![CDATA[jmx4r 0.0.5 has just been released (jmx4r is a JRuby library which makes it super easy to write simple Ruby scripts to manage Java applications using JMX). There is only one enhancement to this release but it is an important one: you can now specify a custom JMX URL to connect to a MBean Server. [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://code.google.com/p/jmx4r/">jmx4r</a> 0.0.5 has just been released (jmx4r is a JRuby library which makes it super easy to write simple Ruby scripts to manage Java applications using JMX).</p>

<p>There is only one enhancement to this release but it is an important one: you can now <a href="http://code.google.com/p/jmx4r/issues/detail?id=7&amp;can=1">specify a custom JMX URL</a> to connect to a MBean Server.</p>

<p>Before this release, the URL was hard-wired to connect using the <a href="http://java.sun.com/j2se/1.5.0/docs/guide/management/agent.html#connecting">JMX URL</a> defined by Sun <code>service:jmx:rmi:///jndi/rmi://#{host}:#{port}/jmxrmi</code>.</p>

<p>This means it was not possible to use jmx4r to connect to a MBean server which used another URL or another connector that RMI/JRMP.</p>

<p>With this release, you can now fully specify the url:</p>


<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;">    url = <span style="color:#996600;">&quot;service:jmx:rmi:///jndi/iiop://node1:7001/weblogic.management.mbeanservers.runtime&quot;</span>
    <span style="color:#6666ff; font-weight:bold;">JMX::MBean</span>.<span style="color:#9900CC;">establish_connection</span> <span style="color:#ff3333; font-weight:bold;">:url</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> url</pre></div></div>


<p>As an example, the code above can be used to connect to a <a href="http://www.performanceengineer.com/monitoring/monitoring-weblogic-using-jmx">Weblogic server using RMI/IIOP</a>.</p>

<p>When the <code>:url</code> argument is used, <code>:host</code>and <code>:port</code> arguments are ignored. If you&#8217;re connecting to a Sun JRE, it is still simpler to specify only <code>:host</code> &amp; <code>:port</code> though.</p>

<p>This enhancement was proposed by <a href="http://www.90kts.com/">Tim Koopmans</a>. Thanks Tim!</p>

<p>As usual, to get this new release, just update the rubygem:</p>


<div class="wp_syntax"><div class="code"><pre class="text" style="font-family:monospace;">jruby -S gem install jmx4r</pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://jmesnil.net/weblog/2008/04/14/jmx4r-005-is-released-with-support-for-custom-jmx-url/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>&#9873; jmx4r moved to git</title>
		<link>http://jmesnil.net/weblog/2008/04/10/jmx4r-moved-to-git/</link>
		<comments>http://jmesnil.net/weblog/2008/04/10/jmx4r-moved-to-git/#comments</comments>
		<pubDate>Thu, 10 Apr 2008 20:14:38 +0000</pubDate>
		<dc:creator>Jeff Mesnil</dc:creator>
				<category><![CDATA[git]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[jmx]]></category>
		<category><![CDATA[jmx4r]]></category>
		<category><![CDATA[ruby]]></category>

		<guid isPermaLink="false">http://jmesnil.net/weblog/?p=168</guid>
		<description><![CDATA[I use Subversion for my daily work (and CVS before that) but I&#8217;ve never used a distributed VCS before. One of my ex-colleagues, Marc, explained to me all the advantages of these systems but I never took the time to play with them. With all the increasing noise about Git and Mercurial, I&#8217;m now curious [...]]]></description>
			<content:encoded><![CDATA[<p>I use <a href="http://subversion.tigris.org/">Subversion</a> for my daily work (and CVS before that) but I&#8217;ve never used a distributed <abbr title="Version Control System">VCS</abbr> before.
One of my ex-colleagues, Marc, explained to me all the advantages of these systems but I never took the time to play with them.<br />
With all the increasing noise about <a href="http://git.or.cz/">Git</a> and <a href="http://www.selenic.com/mercurial/wiki/">Mercurial</a>, I&#8217;m now curious to learn more about it.</p>

<p>Since I learn better by practicing, I moved one of my little projects, <a href="http://code.google.com/p/jmx4r/">jmx4r</a>, from Subversion to Git and hosted it on <a href="http://github.com/jmesnil/jmx4r">GitHub</a>.</p>

<p>I don&#8217;t use jmx4r at the moment and I don&#8217;t plan to develop it more (less features is the new black). However, if you have requests for a new feature or enhancement (or bugs), do not hesitate to fill an issue on the <a href="http://code.google.com/p/jmx4r/issues/list">tracker</a>.<br />
Or better, clone the Git project:</p>


<div class="wp_syntax"><div class="code"><pre class="text" style="font-family:monospace;">git clone git://github.com/jmesnil/jmx4r.git</pre></div></div>


<p>and start hacking it!</p>

<p>P.S.: 
With the recent release of <a href="http://jruby.codehaus.org/">JRuby</a> 1.1, I also checked that the latest version of jmx4r had no regression.<br />
Congratulation to the JRuby team for the performance boost since version 1.0!</p>
]]></content:encoded>
			<wfw:commentRss>http://jmesnil.net/weblog/2008/04/10/jmx4r-moved-to-git/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

