Beauty Is in the Eye of the Beholder
Alex Papadimoulis discusses ugly code, where it comes from, how to avoid it, and how to get rid of it.
The content has been bookmarked!
There was an error bookmarking this content! Please retry.
Posted by Werner Schuster on Jun 29, 2007
You get this for free, just by running JRuby with Java 6. You can attach to any Java process at all. Remotely too. And get this kind of information. Can your Ruby do that?The tool he used to monitor the JVM process was JConsole, which has been shipped with Java since version 5. Another way of accessing JMX information is now available: jmx4r by Jeff Mesnil allows to access JMX MBeans from JRuby code. Here a simple example:
require 'java'This connects to an MBean server on localhost with default connection parameters, but it's possible to use a custom JMX Service URL as well.
require 'jmx4r'
memory = JMX::MBean.find_by_name "java.lang:type=Memory"
memory.verbose = true
memory.gc
memory.verbose is an attribute which would normally have to be set with a verbose JMX method call. Jmx4r sets up an accessors in the class that represents the memory MBean. Information about the MBean is fetched and define_method is used to create the necessary methods for every attribute.method_missing, which is called when no method definition for a method call can be found. In the sample, memory.gc is a call to the Memory MBean's operation that runs the Garbage Collector - but such a method is not defined in the class of the memory object. Instead, the method_missing method is invoked, determines if there is an operation for this method name, and then invokes it using JMX APIs. logging = JMX::MBean.find_by_name "java.util.logging:type=Logging"
logging.logger_names.each do |logger_name|
logging.set_logger_level logger_name, "INFO"
end
JMX::MBean.establish_connection :host => "localhost",
:username => "jeff", :password => "secret"
Using Drools? See what you're missing! Get the Power of Drools with the Assurance of Red Hat
Getting Started with Stratos - an Open Source Cloud Platform
18 agile and lean practices for effective software development governance
This post is interesting. I was also watching Rich Kilmer the other day. Reference: Rich Kilmer on the Power of Ruby, and I was really intrigued by Ruby's features. I haven't used Ruby so far..
Rich says:
they wanted to be able to freeze these 300 JVM's at once.
I had a Ruby process that was running all 300 VM's were underneath it, and I could freeze it in about a half of second. All 300 of them.
To be fair, the metaprogramming ideas, like that find_by_name example, had come from Aaron Batalion's post
Werner, thanks for the article!
The real work was already done by JMX and JRuby guys: I just needed to put a little glue to bind everything required to write simple management scripts in Ruby.
Val, to be fair, I implemented the metaprogramming parts to glue JRuby with JMX without knowing about Aaron code[1] (he used missing_method for attributes while I went the define_method way for them).
However once I saw his post, I took his better syntax to make the code looks like Ruby/Rails[2] rather than Java.
[1] jmesnil.net/weblog/2007/05/31/jmx-scripts-using...
[2] revolutiononrails.blogspot.com/2007/05/ruby-esq...
Alex Papadimoulis discusses ugly code, where it comes from, how to avoid it, and how to get rid of it.
John Davies examines Visa’s architecture and shows how enterprises have architected complex integrations incorporating Hadoop, memcached, Ruby on Rails, and others to deliver innovative solutions.
Sean Comerford unveils ESPN.com’s architecture, what components are used and why, and the current changes the website goes through.
Are there repeated patterns of failure on Enterprise Agile Enablement efforts? Sanjiv and Arlen discuss Seven Deadly Sins to avoid when adopting Agile in an enterprise.
Erik Dörnenburg answers: What is Enterprise and Evolutionary Architecture?, discussing 4 issues: Turning strategy into execution, Ensuring conformance, Where do the architects sit? Buying or building?
Sean Cribbs explains what Map-Reduce and Riak are, why and how to use Map-Reduce with Riak, and how to convert SQL queries into their Map-Reduce equivalents.
Chris Richardson shows how he ported a relational database to three NoSQL data stores: Redis, Cassandra and MongoDB.
Jean Tabaka challenges the audience to reflect on what Agile practices they are employing, how they are using them, ending with the questions “Why have their organization chosen to go Agile?
3 comments
Watch Thread Reply