node.x, a Asynchronous Event Framework for the JVM ☛
What is Node.x?
- A general purpose framework that uses an asynchronous event based style for building highly scalable network or file system aware applications
- Runs on the JVM.
- Everything is asynchronous.
- Embraces the style of node.js and extends it to the JVM. Think node.js on steroids. Plus some.
- Polyglot. The same (or similar) API will be available in multiple languages: Ruby, Java, Groovy, (Python?, JS?, Clojure?), etc
- Goes with the recent developments with InvokeDynamic in Java 7 and bets on the JVM being the future premier runtime for dynamic languages.
- Enables you to create network servers or clients incredibly easily.
- True threading. Unlike node.js, Python Twisted or Ruby EventMachine, it has true multi-threaded scalability. No more spinning up 32 instances just to utilise the cores on your server.
- Understands multiple protocols out of the box including: TCP, SSL, UDP, HTTP, HTTPS, Websockets, AMQP, STOMP, Redis etc
- Provides an elegant api for composing asynchronous actions together. Glue together HTTP, AMQP, Redis or whatever in a few lines of code.
A framework a la node.js (and some more) in a multithreaded environment on the JVM is an intriguing idea with a lot of potential and the examples look both simple and powerful.
This project is based on Netty, an asynchronous event-driven network application framework, that I can’t stop to praise. We use it in HornetQ and is a big reason why HornetQ is so fast.
Tim is an ex-colleague from Red Hat and the previous lead of HornetQ. He knows his stuff about performance, concurrent and asynchronous code and I am intrigued to see where he will go with node.x (esp. if he adds a Clojure layer on top of it, functional programming is a good match for an asynchronous event framework).
⚑Red Hat Wins “Most Innovative Java Company” at JAXconf ☛
Red Hat rightly deserves this award with all the innovative Java projects managed by its middleware division JBoss.
Congratulations to all Red Hat developers who drive this innovation with a special attention to my ex-teamates on HornetQ who are doing a tremendous work on the best and fastest messaging service :)
⚑Code Quarterly’s Q&A with Rich Hickey ☛
A very interesting interview of the creator of Clojure, Rich Hickey, by Michael Fogus, the co-author of Joy of Clojure1.
If you appreciate this interview, Rich’s talk about Value, Identity and State is a must-see for anybody interested in computing and software languages (no knowledge of Lisp or Clojure is required).
- It is on my reading list but I have not read it yet. ↩
HornetQ Talks at Marseille & Nice JUGs
Next week, I will talk about HornetQ and Messaging at the French mediterranean JUGs.
The first talk will be at Marseille on Thursday 2011/03/10 and the second at Nice on Friday 2011/03/11. On the same days, Arnaud Simon from Red Hat will also present AMQP and Qpid.
My talks will be about HornetQ & the Web, how HornetQ embraces the Web and offers messaging features on top of Web technologies (REST, HTML5, etc.). It will also have a (brief) introduction to Messaging and JMS for developers who want to leverage messages for their application (Web-based or not).
See you there!
Oracle and Apple Announce OpenJDK Project for Mac OS X ☛
Oracle and Apple today announced the OpenJDK project for Mac OS X. Apple will contribute most of the key components, tools and technology required for a Java SE 7 implementation on Mac OS X, including a 32-bit and 64-bit HotSpot-based Java virtual machine, class libraries, a networking stack and the foundation for a new graphical client. OpenJDK will make Appleās Java technology available to open source developers so they can access and contribute to the effort.
That’s the right move from Apple: they focus on their platforms (iOS, Mac OS X) and the Web (with WebKit) and let the OpenJDK community handles the Java platform.
⚑Java API, Trade-Off Between Ugliness and Durability
In my previous post, I complained that JMX API was not consistent about the return types of DynamicMBean‘s getAttribute() and getAttributes() methods.
Eamonn McManus replied with a very good explanation on why getAttributes() is designed that way in order to be consistent with setAttributes(). This bit of “ugliness” in the API is a very good compromise. It requires some attention from the API user but it helps tremendously developers providing MBeans as they don’t have to deal with the atomicity of setting different attribute values.
I would still object that getAttribute() should have been consistent and return an Attribute instead of the value. But I can understand that the Attribute indirection has no purpose in that case.
I like JMX API for that reason: it’s both simple and flexible. There are some parts which are ugly or require more work than I would like (writing an OpenMBean is a chore with too much information that should be handled by the JVM or JMX library) but I understand that JMX is widely used and backwards compatibility is a mandatory requirement. If every new release of Java was coming with a refined JMX API without a regard to backwards compatibility, I would not praise it like I do.
Writing an API both simple and empowering is hard. Support it over several releases is a tremendous task.In the Java world, Eclipse is the front leader on that task.
Several years ago, I developed a plug-in, eclipse-jmx, to manage JMX application inside Eclipse (it is also integrated into JBoss Tools as its JMX tool). And release after release, it is still supported by Eclipse without any changes to the API calls.
The last release of eclipse-jmx was written against Eclipse 3.2 and 3 years and 4 Eclipse releases later, eclipse-jmx still works fine, you can even install it using Eclipse Marketplace. I have a love/hate relationship with Eclipse as I use it everyday but I have only admiration for its developers who have been able to craft such a software and took on themselves to support APIs over long time and multiple versions instead of pushing all the work to the contributors to constantly update their plug-ins for each new release. The beauty of Eclipse APIs is in their durability and resiliency.
If you want to know how to write great Java API, the best resources to start are Eclipse and JMX.
On a similar topic, I am having a deep look at HTML5 and its various JavaScript APIs (WebSockets, geolocation, storage, canvas, etc.). I am curious to see how they will evolve and if lessons will have been learnt from the evolution (or lack of) of the DOM API…
jmx4r 0.1.0 Is Released
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 is also two new features:
- support for Java CamelCase style in addition to Ruby snake_case (thanks again to Dan)
logging = JMX::MBean.find_by_name "java.util.logging:type=Logging" # Ruby syntax works logging.set_logger_level "global", "FINEST" # Java syntax works too logging.setLoggerLevel "global", "FINEST"
- Connection to a local JVM (thanks to Mr ohtsuka).
You can now connect to a JVM running on the same machine without adding the
com.sun.management.jmxremotesystem properties.
For example, start an instance of jconsole without any additional system properties:
$ jconsole &You can now manage this Java application locally:
require 'rubygems' require 'jmx4r' # :command is a regexp corresponding to the Java process to connect to JMX::MBean.establish_connection :command => /JConsole/ memory = JMX::MBean.find_by_name "java.lang:type=Memory" memory.gc
In addition to the previous :host, :port and :url arguments that you can pass to establish a JMX connection, there is now :command 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 jps:
$ jps 4255 JConsole 4395 Jps
You can connect to a local Java application running on Java 5 or 6. Is someone interested to contribute support for JDK7 too?
Once again, thanks to all the contributors and users who help make jmx4r even more useful!
As usual, to get this new release, just update the rubygem:
jruby -S gem install jmx4r
and do not hesitate to contribute:
git clone git://github.com/jmesnil/jmx4r.git
“Read Lature”: A Web Application to Save Articles and Read Them Later
As an exercice when I learn a new programming language or a new environment, I develop simple applications to get a feel on the language, the platform, its libraries, etc. When I lack ideas for these applications, I redevelop applications that I use.
In order to learn Clojure and Google App Engine, I have developed Read Lature, a web application to save articles and read them later (very similar to Instapaper)1.
The idea is simple: I want to keep reference on articles or blog posts that can be interesting but I don’t want or don’t have time to read them immediately. I do not use bookmarks for that (either using my browser bookmarks or delicious): my bookmarks are long-lived while I want to keep a reference to these articles only for a short period (and keeping them open in tabs does not scale).
To save articles, you just need to drag a bookmarklet to your bookmarks bar. When you find a good article or blog post, you click on the bookmarklet to save it. It will be added to Read Lature so that you can read it when you have some time. Once it is read, it is automatically moved to the archive. Articles can also be starred for further readings.
The second way to save article to Read Lature is to use Google Reader. Setup a custom link and you can send articles to Read Lature directly from Google Reader (as explained in the instructions).
I mainly use Read Lature to save articles and read them later on my iPhone when I am away:

The application is hosted on Google “Cloud” and leverages Google accounts for user credentials.
To try it, go to Read Lature, login using your Google (or Gmail) account, and follow the instructions.
The application is written using Clojure, Compojure and jQuery and is less than 500 SLOC (75% is Clojure code, the rest is JavaScript).
Read Lature code is released the code under Apache 2.0 License on GitHub.
I will write later a review of the book “Progamming Clojure”, that I have just finished reading, and some thoughts about Clojure base on my experience with it so far.
- So similar in fact that I first named the project Instapapure for “Instapaper in Clojure” but I did not like it and renamed it Read Lature (for “Read Later with Clojure”). Naming projects is a dark art that I do not master… ↩
Nice Clojure Outline in TextMate
TextMate is my favorite text editor and my preferred IDE when I’m not writing Java or Objective-C (for these two, I use Eclipse and Xcode).
I am currently learning Clojure and installed a bundle to have proper syntax highlighting and macros in TextMate.
I found a cool feature by accident yesterday. My file was starting to be “big” and I added comments to separate the different “sections”:
;; ************* ;; ;; Configuration ;; ;; ************* ;; ;; Configuration-related code ;; ********* ;; ;; DB Layer ;; ;; ********* ;; ;; DB-related code ;; *********** ;; ;; Web Layer ;; ;; *********** ;; ;; Web-related code ;; ******* ;; ;; Startup ;; ;; ******* ;; (db/init) (server/start)
While I was writing code, I wanted to move from one part of the file to another and I used TextMate’s outline for that (the outline is the right part of the status bar at the bottom of the window, when you click it, it displays a list of all defined functions in the file). I noticed that these special comments were also displayed:
I don’t know if the “magic” comes from TextMate or the Clojure bundle.
To make it appear in the outline, the comment must end with ;;:
;; This will appear in TextMate outline ;; ;; This won't
I tried several comment formats in Ruby code but I was not able to make them appear in the outline. I assume the kudos should go the the bundle’s authors rather than to TextMate1.
Outline the “logical” structure of the code
It is a very good idea to display these comments in the outline as they help to show the logical structure of a file.
For example in Java, the code is often organized as public/protected/private methods but it is does not give enough information on the logical composition of the class. I add comments to delimit the various interfaces implementations:
class Foo extends Thread implements IFoo, IBar { // IFoo implementation ... // IBar implementation ... // Thread overrides ... // Public ... // etc. ... }
This valuable information is not displayed in Eclipse, in its outline or any other views2. This valuable information is lost while it would greatly improve the outline and make it more useful.
I already encountered such “special comments” when I was developing an iPhone application with Xcode. It supports a special preprocessor directive to display text in the outline:
#pragma mark This will appear in Xcode outline // This is a regular Objective-C comment // it won't appear in the outline
I used them to split my Objective-C class in different logical sections (e.g. controller implementation, UI actions, protocol delegate):
I rarely uses code outline. Most of the time, I navigate in the code using the keyboard or the mouse wheel. Naturally, I prefer the outline to not clutter the UI when I do not use it.
However, when I want to use it, I prefer when it shows a “logical” outline of the code and not only a simple listing.
Compared to TexMate or Xcode, I find that Eclipse’s outline is cluttered:
I can not use it without either maximizing the view or scroll it horizontally (both requires too much UI gestures before reading the outline). I also find that it is overloaded with too much information:
- different icons for private/protected/public fields
- icon overlays for static, final modifiers or warnings
- nested hierarchy losing valuable UI space
All these details brings noise instead of information: an outline should display a general view of the class, not all these tiny details.
Using quite often these three softwares, I find TextMate and XCode approach to outlines more adapted to my workflow:
- they do not show it until you require it
- It displays a logical view of the code (using the comments/directive to show the logical sections)
- it does not show too much details not relevant to a broad view of the code
- To be fair, TextMate deserves a meta-kudos to allow such cool features through its bundle mechanism! ↩
- I have not check if NetBeans or IDEA can display “special comments” in their outlines but I never heard about such a thing… ↩
Concurrency Is My New Memory Management Criteria
Way back in school, I started studying object-oriented programming language with C++. I found the object concepts simple and powerful (especially after learning procedural programming with Fortran) but I did not like C++.
I browsed the internet to find if there were other OO languages that I could use instead of C++. I quickly found Java (1.0.x at the time, if I remember correctly) and preferred it for 3 reasons:
- the concept and syntax were similar to C++ but simpler and well-defined. I could still leverage what I learn with C/C++ and applied it to Java
- the documentation was good: with the javadoc, the whole platform API was one-click away
- it had an automatic garbage collector
So I started to study Java seriously during my spare time, I found internships where I could learn from other Java developers and I ended up using it for most of my professional career.
Retrospectively, reasons #1 and #2 were nice to have but automatic garbage collection was the real decision criteria.
When I develop an application, most of the time I don’t care when I should allocate objects, if should I take ownership or release them, etc. I just want to have an object and use it1.
But C++ forced me to think about all these details while Java made it simpler: new Foo() and that’s it. Back then, I was just starting to learn programming languages and I preferred to let the languages handle the memory: it would be less error-prone than if I had to do it manually.
My student friends told me that my Java programs would consume more memory than the C++ equivalent and likely run slower. Maybe it was true at the time, but the Java programs were simpler and faster to write, less buggy and less likely to leak memory during their lifetime.
So I chose Java and never looked back to C++.
Back to the present.
We now have multiple cores in our machines and to use them efficiently, we need to increase the concurrency of our code.
And I’m not enthusiastic with Java. The java.util.concurrent library helps a lot but I find really hard to write correct concurrent code and too easy to screw it up.
I’m in the same state of mind that when C++ was “forcing” me to think about memory management.
I have added other languages to my toolbox (mainly Ruby/JRuby and Javascript). They complement nicely Java but they are not more fit for concurrency. There should be a language/platform that can handle concurrency for me or at least help me write correct concurrent code.
Which languages/platform will I use for that? Erlang, Clojure2, Scala, Reia, other?
Which concepts should I use? STM, messages, actors, fork/join, Grand Central Dispatch, other?
I don’t even know if I am looking for a new platform or another language on top of the Java platform.
But I know that I am looking for something to help me with concurrency the same way Java helps me manage the memory.
Concurrency is likely to be one of the main decision criteria when I choose which next language/platform to learn. I envision it being as important as memory management was when I started to learn OO and how it tipped the balance for Java instead of C++.
Choosing Java over C++ shaped the beginning of my career. Choosing a concurrent language/platform may have the same importance for the next part of it…
- I waited the release of Objective-C 2.0 to learn about Mac programming. I wanted to learn this language since I bought my first Powerbook but I waited until they added a garbage collector because I was not interested to manually manage the memory. Finally I still ended up having to learn it since the garbage collector is not available on the iPhone. Unsurprisingly, I have to track down a few memory leaks in the iPhone applications I develop. ↩
- I received the printed version of Programming Clojure a few days ago. I like what I am reading so far. ↩


