April 10, 2008
I use Subversion for my daily work (and CVS before that) but I'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'm now curious to learn more about it.
Since I learn better by practicing, I moved one of my little projects, jmx4r, from Subversion to Git and hosted it on GitHub.
I don't use jmx4r at the moment and I don'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 tracker.
Or better, clone the Git project:
git clone git://github.com/jmesnil/jmx4r.git
and start hacking it!
P.S.: With the recent release of JRuby 1.1, I also checked that the latest version of jmx4r had no regression.
Congratulation to the JRuby team for the performance boost since version 1.0!
April 9, 2008
Finally, after almost 3 years running the same version of Wordpress for this weblog, I finally upgraded to Wordpress 2.5. The upgrade went smoothly except for a permission problem at the end which is documented in Wordpress forum.
Kudos to Wordpress team for releasing a web application which can upgrade a 3-year old version without any user intervention (almost...) while preserving all my content.
March 15, 2008
Since I've replaced my old PowerBook by a recent MacBook, I was looking for an opportunity to learn more about Objective-C and the cool new APIs from Leopard (especially Core Animation).
The release of the iPhone SDK is the right occasion to do that.
After a few hours of reading iPhone examples and coding, I was able to write a simple application to play Tangram:
The game is not entirely functional: you can drag the parts from the "box" at the bottom to the top to arrange them and form shapes but you can't rotate the parts.
Apple iPhone simulator can not simulate multi-gesture events corresponding to a rotation (put a finger down, with another finger draw an arc of circle).
There is nothing groundbreaking with this tiny application (it's not Spore or Monkey Ball!). However, having never used XCode before and knowing not much about Objective-C and Mac OS X APIs, I was impressed by the quality of the iPhone SDK to be able to do that in less than 4 hours and 600 lines of code.
If I ever want to release this application one day, I guess I'll have to apply for the iPhone developer program... and buy an iPhone or an iPod touch!
October 6, 2007
Cool: Adam Bosworth is blogging again.
I thought it was a shame he stopped talking when he was hired by Google because a few people could not make the difference between his own opinion and the company he was working for.
Now that he has left Google and created a new startup, I'm looking forward to reading what he is up to....
October 1, 2007
Update (Oct., 1st): A huge thank you to everyone that has mailed, phoned, or linked to me over the past several weeks. I was contacted by great people at companies with very interesting and cool things and it was a tough decision to choose among all these great offers.
But I finally took the decision and starting today I'm working for Red Hat in the JBoss division.
It is now official: I've been notified by my employer of my layoff (French R&D; office closing down, cost reduction and all).
The good news is that I'll have more time to work on jmx4r and eclipse-jmx and publish articles on this weblog.
But, as fun as it sounds, it won't pay the bills, so I need to find a new job.
Please hire me.
If you are unable to hire me, please do me a favor and link to this entry.
My resume is available in PDF or Word.
Thank you.
August 20, 2007
- Download Erlang
- Setup TextMate with a bundle for Erlang
- Read the white paper and the book
- Understand what the fuss is about
August 7, 2007
jmx4r 0.0.4 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.
To get this new release, just update the rubygem: jruby -S gem install jmx4r
All contributions to this new release were done by Skaar:
- CompositeData behave like regular read-only Ruby Hash
- custom classes can be loaded by
require
statements - custom JMX credentials are supported
CompositeData as read-only Hash
CompositeData are the open and interoperable way to return custom data structures from JMX.
They now behave in jmx4r as regular read-only Ruby Hash.
For example, the JVM exposes its heap memory usage with such a composite data:
memory = JMX::MBean.find_by_name "java.lang:type=Memory"
# heap is a CompositeData attribute
heap = memory.heap_memory_usage
To list the name and values of the heap
attribute, the code was:
heap.composite_type.key_set.each do |type|
puts "#{type} : #{heap.get type}"
end
and now it is simply:
heap.keys.each do |key|
puts "#{key} : #{heap[key]}"
end
Classloading using require
A second contribution by Skaar was to fix a classloading problem. In case you need to use custom classes in your JMX code, only classes loaded from JRuby's classpath were taken into account. It is now possible to reference classes loaded using require
statements.
Custom JMX credentials
jmx4r now allow you to specify custom credentials used by JMX authentication (as specified by a JMXAuthenticator) in addition to the "standard" :login/:password
credentials:
creds = create_my_custom_credentials()
# creds will be used by the JMXAuthenticator on the MBeanServer
JMX::MBean.establish_connection :credentials => creds
July 5, 2007
Something which is not obvious with the way jmx4r leverages JMX API and Ruby metaprogramming is that you can write simple scripts to manage a Java application without any dependency on the MBeans exposed by the application.
For simplicity, in my examples I always use MBeans exposed by the JVM but jmx4r works with any MBean even if its interface is unknown from the JVM running the management scripts.
Here is a simple example to manage Tomcat using jmx4r.
Let's assume that we have Tomcat running locally and manageable remotely on port 3000 (without authentication):
$ export CATALINA_OPTS="-Dcom.sun.management.jmxremote \
-Dcom.sun.management.jmxremote.port=3000 \
-Dcom.sun.management.jmxremote.ssl=false \
-Dcom.sun.management.jmxremote.authenticate=false"
$ ./bin/catalina.sh/run
We want to know among all the Web Modules running in Tomcat which ones are privileged and which ones are not. The whole script to do so is:
# tomcat_modules.rb
require "rubygems"
require "jmx4r"
JMX::MBean.establish_connection :host => "localhost", :port => 3000
web_modules = JMX::MBean.find_all_by_name "Catalina:j2eeType=WebModule,*"
privileged, unprivileged = web_modules.partition { |m| m.privileged }
puts "Privileged:\n" + privileged.map {|m| m.path }.join("\n ")
puts "Unprivileged:\n " + unprivileged.map {|m| m.path }.join("\n ")
Executing this script gives:
$ jruby tomcat_modules.rb
Privileged:
/balancer
/manager
/host-manager
Unprivileged:
/tomcat-docs
/servlets-examples
/jsp-examples
/webdav
That's were using JRuby shines: it combines the simplicity of using directly the MBeans exposed by a Java application without having to bother with classes dependency.
Using Java to write a corresponding script means choosing your "poison":
- No class dependency but tedious (and unnatural) use of MBeanServerConnection methods to interact with Tomcat MBeans
- Use directly Tomcat MBeans (thanks to MBeanServerInvocationHandler) but you must take care having all their interfaces (and dependencies) in the class path of the JVM running the script
I can not thank enough both the JMX and JRuby guys which make it so simple to get the best of both worlds in jmx4r:
- simple to use directly the MBeans API
- simple to deploy without class dependency issues
July 4, 2007
jmx4r 0.0.3 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.
Two new features in this release:
- some much-needed documentation
- as requested by Brian McCallister, I've modified the code so that it is now possible to write a script to manage many Java applications at the same time.
For example, the script to trigger a garbage collection on a cluster of Java applications at the same time (quite a bad idea but a simple one):
hosts = ["node1", "node2", "node3", "node4"]
hosts.each do |h|
memory = JMX::MBean.find_by_name "java.lang:type=Memory", :host => h, :port => port
memory.gc
end
Quite simple, isn't it?
JMX::MBean#find_by_name
and JMX::MBean#find_all_by_name
now accept an optional hash where you can specify specific information related to the connection to use (:host
, :port
, :username
, :password
or :connection
) as described in the documentation. Otherwise, a global connection will be used.
A complete example shows how to display memory usage on 3 Java applications before and after a garbage collection is triggered.
$ jruby -Ilib examples/memory_on_many_nodes.rb
Before GC:
+----------------+----------------+----------------+
| Node | Heap Used | Non Heap Used |
+----------------+----------------+----------------+
| localhost:3000 | 1264328 | 14414808 |
| localhost:3001 | 1345632 | 14465192 |
| localhost:3002 | 1405072 | 14501936 |
+----------------+----------------+----------------+
After GC:
+----------------+----------------+----------------+
| Node | Heap Used | Non Heap Used |
+----------------+----------------+----------------+
| localhost:3000 | 1142304 | 14421184 |
| localhost:3001 | 1205040 | 14476312 |
| localhost:3002 | 1218928 | 14506672 |
+----------------+----------------+----------------+
As usual, the simplest way to install it is by using RubyGems: jruby -S gem install **jmx4r**
.
June 27, 2007
jmx4r is a library for JRuby to make it super easy to write Ruby scripts to manage remote Java applications through JMX.
Thanks to RubyForge, installing jmx4r is now as simple as typing
jruby -S gem install jmx4r
and its use is straightforward
#!/usr/bin/env jruby
require 'rubygems'
require 'jmx4r'
# optional since by default, jmx4r tries to connect to
# a JMX Server on localhost which listens to port 3000
JMX::MBean.establish_connection :host => "localhost", :port => 3000
memory = JMX::MBean.find_by_name "java.lang:type=Memory"
# trigger a Garbage Collection
memory.gc
Since my previous post on jmx4r, I've added unit tests and some examples to highlight its features. It still needs to be properly documented though...
However, one new feature is worth mentioning: jmx4r now supports connection authentication
JMX::MBean.establish_connection :host => "localhost",
:username => "jeff", :password => "secret"
If you're using it, I'm very interested to now what you think about it.
And if you encounter any problem, do not hesitate to submit a bug.