Originally published on: Tue, 09 Mar 2010 00:27:59 +0000
NailGun is a Java-oriented protocol that is used to speed up Java command-line applications. A NailGun server process must first be initiated that will listen for traffic on port 2113 by default.
The NailGun client program (ng) is then used to specify Java classnames to the NailGun server which executes those classes in its already-running JVM. The standard input/output channels are redirected to those of the ng client instead of the ones tied to the running JVM.
The benefit is that each command-line task can avoid the load-time of a JVM for each invocation; a single JVM is shared among multiple requests.
For more information on using NailGun with Java programs, please see this link:
http://martiansoftware.com/nailgun/quickstart.html
The NailGun server and client were merged into the JRuby distribution as of version 1.3. No changes need to be made to JRuby code to allow them to execute with the packaged NailGun server.
To start the JRuby ng server enter the following at a command-prompt:
You should see output similar to the following:
You can then invoke a JRuby script by entering the following at a command-prompt in a different console window:
...where scriptname.rb is the name of the JRuby script that you'd like to execute.
I tried the above procedures with the JPoppy.rb script shown here: http://www.mailsend-online.com/blog?p=73.
I encountered some sort of odd error when I tried this the first time on Windows XP from the JRuby/ng client. It crashed due to an invalid instruction or something along those lines. This also crashed the running ng server process, showing a Java stack trace on the ng process's console window.
I was not able to recreate the error situation after several attempts. I even tried to break out of the ng client side prematurely to see if the ng server would again throw an unhandled exception, but I could not cause an exception to occur.
I was going to start using NailGun by simply writing some Java code to use it. I changed my mind once I saw how simple it was to use NailGun with JRuby.
The NailGun homepage states that the product should be considered to be an alpha release. As such, it should not be used for production purposes.
I would like to understand more about how concurrent ng clients using the same scripts ( or classes ) are handled by a single instance of the NailGun server. I hope to get around to those experiments in the near future.
Unless otherwise noted, all code and text entries are Copyright ©2010 by James K. Lawless
Views expressed in this blog are those of the author and do not necessary reflect those of the author's employer. Views expressed in the comments are those of the responding individual.

Save to StumbleUpon
Digg it
Save to Reddit
Share on Facebook
Share on Twitter
More bookmarks
Click **here**
A JavaScript REPL for Android Devices
A Review of Kevin Mitnick's Book Ghost in the Wires
Play MP3 Files with Python on Windows
PHP, Transparent GIF's, and Web Tracking
Internet Protocols and Rhino JavaScript
Extracting URL Addresses from Text in C
A Scrolling Banner using Canvas and JavaScript
Why Some Web Sites will go Dark on Jan 18th
Book Review : Paull Allen - Idea Man
A 90's Experiment in Online Systems - The U.S. West CommunityLink Service