<?xml version="1.0" encoding="UTF-8"?>
<commit>
  <added type="array">
    <added>
      <filename>lib/jdk/jdk5_helper.rb</filename>
    </added>
    <added>
      <filename>lib/jdk/jdk6_helper.rb</filename>
    </added>
    <added>
      <filename>lib/jdk_helper.rb</filename>
    </added>
  </added>
  <modified type="array">
    <modified>
      <diff>@@ -6,7 +6,7 @@ require &quot;rubygems&quot;
 
 dir     = File.dirname(__FILE__)
 lib     = File.join(dir, &quot;lib&quot;, &quot;jmx4r.rb&quot;)
-version = &quot;0.1.0&quot;
+version = &quot;0.1.0.1&quot;
 
 task :default =&gt; [:test]
 </diff>
      <filename>Rakefile</filename>
    </modified>
    <modified>
      <diff>@@ -12,7 +12,8 @@ module JConsole
   # By default, no authentication is required to connect to it.
   #
   # The args hash accepts 3 keys:
-  # [:port]        the port which will be listens to JMX connections
+  # [:port]        the port which will be listens to JMX connections.
+  #                if the port is 0, jmxrmi port is not published
   # [:pwd_file]    the path to the file containing the authentication credentials
   # [:access_file] the path to the file containing the authorization credentials
   #
@@ -29,13 +30,19 @@ module JConsole
     cmd =&lt;&lt;-EOCMD.split(&quot;\n&quot;).join(&quot; &quot;)
     jconsole
     -J-Dcom.sun.management.jmxremote 
-    -J-Dcom.sun.management.jmxremote.port=#{port} 
-    -J-Dcom.sun.management.jmxremote.ssl=false 
-    -J-Dcom.sun.management.jmxremote.authenticate=#{!pwd_file.nil?}
-EOCMD
-    if pwd_file and access_file
-      cmd &lt;&lt; &quot; -J-Dcom.sun.management.jmxremote.password.file=#{pwd_file}&quot; 
-      cmd &lt;&lt; &quot; -J-Dcom.sun.management.jmxremote.access.file=#{access_file}&quot;
+    EOCMD
+
+    if port != 0
+      cmd &lt;&lt; &lt;&lt;-EOCMD.split(&quot;\n&quot;).join(&quot; &quot;)
+      -J-Dcom.sun.management.jmxremote.port=#{port}
+      -J-Dcom.sun.management.jmxremote.ssl=false
+      -J-Dcom.sun.management.jmxremote.authenticate=#{!pwd_file.nil?}
+      EOCMD
+
+      if pwd_file and access_file
+        cmd &lt;&lt; &quot; -J-Dcom.sun.management.jmxremote.password.file=#{pwd_file}&quot;
+        cmd &lt;&lt; &quot; -J-Dcom.sun.management.jmxremote.access.file=#{access_file}&quot;
+      end
     end
     Thread.start { system cmd }
     sleep 3
@@ -46,7 +53,11 @@ EOCMD
   # By default, it will kill the process corresponding to an instance JConsole with 
   # a port on 3000. Another port can be specified in parameter.
   def JConsole.stop(port=3000)
-    jconsole_pid = `ps a -w -o pid,command | grep -w jconsole | grep port=#{port} | grep -v grep | grep -v ruby | cut -c -5`
+    ps  = &quot;ps a -w -o pid,command | grep -w jconsole&quot;
+    ps &lt;&lt; &quot; | grep port=#{port}&quot; if port != 0
+    ps &lt;&lt; &quot; | grep -v grep | grep -v ruby | cut -c -5&quot;
+
+    jconsole_pid = `#{ps}`
     `kill #{jconsole_pid}` if jconsole_pid != &quot;&quot;
     sleep 1
   end</diff>
      <filename>lib/jconsole.rb</filename>
    </modified>
    <modified>
      <diff>@@ -111,6 +111,7 @@ module JMX
     # 
     #   JMX::MBean.establish_connection :port =&gt; &quot;node23&quot;, :port =&gt; 1090
     #   JMX::MBean.establish_connection :port =&gt; &quot;node23&quot;, :username =&gt; &quot;jeff&quot;, :password =&gt; &quot;secret&quot;
+    #   JMX::MBean.establish_connection :command =&gt; /jconsole/i
     def self.establish_connection(args={})
       @@connection ||= create_connection args
     end
@@ -143,6 +144,15 @@ module JMX
     #                     if the url is specified, the host &amp; port parameters are
     #                     not taken into account
     #
+    # [:command]          the pattern matches the command line of the local
+    #                     JVM process.
+    #                     (listed as 'local processes' on JConsole).
+    #                     No default.
+    #                     this feature needs a JDK (&gt;=5) installed on the local
+    #                     system.
+    #                     if the command is specified, the host &amp; port or the url
+    #                     parameters are not taken into account
+    #
     # [:username]         the name of the user (if the MBean server requires authentication).
     #                     No default
     #
@@ -164,9 +174,15 @@ module JMX
       credentials = args[:credentials]
       provider_package = args[:provider_package]
       
-      # host &amp; port are not taken into account if url is set (see issue #7)
-      standard_url = &quot;service:jmx:rmi:///jndi/rmi://#{host}:#{port}/jmxrmi&quot;
-      url = args[:url] || standard_url
+      if args[:command]
+        require 'jdk_helper'
+        url = JDKHelper.find_local_url(args[:command]) or
+          raise &quot;no locally attacheable VMs&quot;
+      else
+        # host &amp; port are not taken into account if url is set (see issue #7)
+        standard_url = &quot;service:jmx:rmi:///jndi/rmi://#{host}:#{port}/jmxrmi&quot;
+        url = args[:url] || standard_url
+      end
       
       unless credentials
         if !username.nil? and username.length &gt; 0</diff>
      <filename>lib/jmx4r.rb</filename>
    </modified>
    <modified>
      <diff>@@ -77,4 +77,15 @@ class TestConnection &lt; Test::Unit::TestCase
     end
   end
 
+  def test_establish_connection_local
+    begin
+      JConsole::start :port =&gt; 0
+      connection = JMX::MBean.establish_connection \
+        :command =&gt; /jconsole/i
+      assert(connection.getMBeanCount &gt; 0)
+    ensure
+      JConsole::stop 0
+    end
+  end
+
 end</diff>
      <filename>test/tc_connection.rb</filename>
    </modified>
  </modified>
  <removed type="array"/>
  <parents type="array">
    <parent>
      <id>ebfc035c61fa9e231e51b96a5f498ba22a2c11b0</id>
    </parent>
  </parents>
  <author>
    <name>sat13f</name>
    <email>sat13f@gmail.com</email>
  </author>
  <url>http://github.com/jmesnil/jmx4r/commit/478de5bc0bc49dd8bc7145d87056080e8a3ee1df</url>
  <id>478de5bc0bc49dd8bc7145d87056080e8a3ee1df</id>
  <committed-date>2009-10-22T01:41:07-07:00</committed-date>
  <authored-date>2009-08-02T00:27:58-07:00</authored-date>
  <message>added local JVM connection feature</message>
  <tree>26600aecc434f3d1a58d573730fbdc33aa3273a1</tree>
  <committer>
    <name>Jeff Mesnil</name>
    <email>jmesnil@gmail.com</email>
  </committer>
</commit>
