Sunday Mar 21, 2010

Day 2 - Ruby Conf India 2010 Trip Report

Ruby Conf India 2010 Day 2 (follow up from Day 1) started with Nick Sieger's presentation on "Rails 3 Through Choices".

He started by talking about the state of Ruby in 2010

Liked the "Auto" mode of camera analogy with Rails 3, basically start changing the settings as you get more advanced.

Here are some of the highlights of Rails 3:

  • --skip-activerecord, --skip-testunit, --skip-prototype are new options in Rails 3
  • script/server | generate | console == script/rails s g c == rails server generate console (within the app directory)
  • Routing is much cleaner
  • XSS safety is default in Rails 3
  • Railties: extension API for Rails - encapsulates configuration information and enables decoupling.
    • Four main components: Initialization, Rake tasks, Generators, Logging Events.
    • All components in Rails are themselves Railties.
  • Rack is now bundled in Rails 3
  • ActiveModel: creates a contract between controller and model (7 methods), can be connected to any backend data store, provides a bunch of default functionality
  • Migration from 2.0 -> 3.0: has a presentation on migration from earlier versions.

Railties certainly reminds me of the recent modularity in JDK 7 and GlassFish v3. Watch Nick's demo of Rails 3 in this 2-part video. It showed how Rails 3 Active Model can be used to store data in Neo4j (a graph database) instead of a traditional relational database.

My "GlassFish can support multiple Ruby frameworks ... really ?" talked about the pluggable architecture of GlassFish v3 and how it supports multiple Ruby frameworks. It described the 3 deployment models of Rails applications in GlassFish (Gem, WAR, Directory-based), showed live samples of Rails and Sinatra applications, talked about the advantages of NetBeans, and a lot about JRuby. All my talks on Rails/GlassFish end up promoting JRuby a lot as that is indeed the entry point for deploying your Rails applications on GlassFish. Anyway, enjoy the complete slides at:

And I received the following messages few minutes after the presentation was posted on slideshare:

Here are some of the tweets during/after the talk:

  • @gautamrege Really cool article by @arungupta Day 1 – Ruby Conf India 2010 « Miles to go … #rubyconfindia
  • @ytvinay sitting with @nicksieger and listening 2 @arungupta 's gr8 talk on glassfish n jruby. is this really happening? #rubyconfindia #honoured
  • @yob_au Enjoying Arun Gupta's jruby and glassfish talk at #rubyconfindia - very clear overview and demos for an MRI traditionalist like me
  • @arjunghosh Second day @ #rubyconfindia Some interesting talks until now,like Nic one on Rails 3, @arungupta 's Glassfish,Sahar's Templating
  • @vijay_dev feeling completely at home in the GlassFish talk! Helps to be a Java and Rails guy :-) #rubyconfindia

Totally love the instant feedback :-) You can follow the complete set of comments at #rubyconfindia.

Post lunch I had a brief hacking session with Obie and ran a local version of using JRuby/Rails 2.3.5/GlassFish Gem/PostgreSQL. Other than installing the required gems, every thing was pretty straight forward. It re-confirms the fact that JRuby is just Ruby and can run any Rails application on GlassFish in a seamless manner.

I would've loved to attend Roy's closing keynote but had to step out because of a prior personal commitment.

Overall, Ruby Conf India turned out to be an excellent experience. I certainly enjoyed spending time with Nick, Ola, Obie and a bunch of folks from ThoughtWorks, specifically Roy, Sagar, Tina, Rohit, Christabel, and Judy. The entire team put a wondertastic show and I certainly hope this is a more regular event.

There is a relentless demand for entrepreneurial spirit and trying out the bleeding edge technologies. I hope other similar conferences will start showing up in the near future. I also hope that the local community pick up efforts to take leadership roles and start organizing free Ruby or Rails workshop to expand the Ruby ecosystem. And of course, I certainly wish they all use JRuby, after all it's Ruby. And once you are using JRuby, that's it - GlassFish serves your Rails, Sinatra, Ramaze, and any other Rack-based framework applications.

Here are a few pictures from Day 2:

And the complete album so far:

The speaker gift is certainly a nice gesture and my son will surely it enjoy more than me. Thanks a lot to Thought Works for organizing the conference!

On a little bit of fun front, totally loved the following advertisement of "Bingo! Spicy Masala Remix" on the local TV channels:

2 conferences, 2 cities, 2 hotels, 5 planned + 1 unplanned sessions covered, 1 city + 4 planned sessions remaining!

Next stop is Tech Days, Hyderabad!

Technorati: conf rubyconfindia ruby jruby rubyonrails glassfish bangalore bengaluru india

Saturday Mar 20, 2010

Mahaswami Software enjoys the "perfect marriage" of JRuby + Rails + GlassFish

Mahaswami Software (based in Bengaluru, India) uses its homegrown Rapid Application Development framework to deliver quality applications in quick time. The framework leverages JRuby, Rails, and the J2EE platform along with Test Driven Development and Continuous integration tools. Mahaswami offers product development services and specific consulting on JRuby/Rails based application development. The Mahaswami team actively contributes back to the Ruby and Rails community.

And they picked GlassFish for a web-based supply chain management product for a large enterprise application service provider in India. They picked GlassFish instead of JBoss because they loved the web-based admin console and high performance.

Watch more details in the following video:

Here is what the customer has to say about their experience:

We were pleasantly surprised by this team's fantastic ability to deliver complex solutions with great agility, and have gained an edge to our product development efforts.

Do you have any JRuby/Rails/GlassFish consulting requirements in Bengaluru ? Mahaswami Software is your one stop shop for providing all the services.

See other similar success stories here.

Technorati: mahaswami bangalore bengaluru india jruby rubyonrails glassfish stories

Day 1 - Ruby Conf India 2010

Roy Singham, founder and chairman of ThoughtWorks Inc, kick started Ruby Conf India by stating that this conference is more important than just Ruby in India. He also mentioned that this conference is sponsored by developers in India instead of any big corporations.  He talked about a global shift is happening because of the passion outside silicon valley in open source, Ruby, Python and other similar technologies. In his opinion, India & Brazil are going to reshape the world of software. He'd like Ruby conference to present the best of humanity, innovative and welcome to all. I think inclusive as opposed to exclusive is certainly a key message for the Ruby audience.

Ola's talk on "The Future of Programming Languages" was interesting as always. He talked about different types of languages such as general purpose (Java & Ruby), special purpose (Erlang & JavaScript), Domain specific (SQL), Functional, Logic, Object-oriented (Prototype or class-based), Multi paradigm (some aspects of each such as C# or Scala).

An interesting part of his talk explored the key Ruby features inherited from which other languages. Lets see how many can you guess ?

  1. Multiple assignments like a, b, c = 1, 2, 3
  2. Regular expressions
  3. $/ (input record separator), $= case insensitive
  4. Object Orientation
  5. Message Passing & Introspection
  6. Mixins
  7. Closures

Try to note down your answers and then match with the corrects ones at the end of this blog :-)

Obie's talk on Blood, Sweat, and Rails was well tailored to the Indian audience. The reference to "All izz well" and couple of pictures from the movie 3 Idiots got a good laugh but then he got reprimanded during his talk to stop using the "F" bomb. From my prior experience, I counted approx 14 times of him dropping the bomb ;-)

Matz skyped in and talked about current state of Ruby and the future. Matz is to Ruby as James Gosling is to Java so the attendees were extremely excited to see him live on the skype session.

It took him 6 months to write the first "Hello World" in Ruby and the first run crashed. But that started the long journey bringing Ruby to its current state. The name "Ruby" was chosen on Feb 24, 1993 and is officially considered the birthday of Ruby. During a later Q&A session he mentioned the name "Ruby" was chosen because the language came after "Perl" which was named after a gem and "Diamond" etc were too long a name. Later on he found out that Pearl is a birth stone for the month of June and Ruby is the birth stone for the month of July so it turned out logical that way as well :-)

Matz also mentioned that Ruby 1.9.2 will be released end of August and then start working on Ruby 2.0. Ruby's future will be faster, more powerful, distributed programming, faster IPC, multi-core aware, broader (for embedded devices to HPC environments), smaller implementation, and more modular.

The social gathering in the evening was fun and gave me the opportunity to interact with lots of folks from the local community. I answered the question "What has Oracle got to do with Rails" at least 4 times during the social. Here are several articles on that topic:

And, of course, now Oracle owns GlassFish that allows native deployment of Rails along with Java EE applications.

The highlight for me was finding a happy customer using the "perfect marriage" of JRuby, Rails, and GlassFish. More details coming on that in a separate blog. I'm giving a session on "GlassFish supports multiple Ruby frameworks ... really ?" at 11am on Day 2.

Now here are some pictures so far:

And here is the evolving album so far:

And now the answers from Ola's talk:

  1. Multiple assignments like a, b, c = 1, 2, 3 from CLU (also templates, generators)
  2. Regular expressions from Perl
  3. $/ (input record separator), $= case insensitive from Perl
  4. Object Orientation from Smalltalk
  5. Message Passing & Introspection from Smalltalk
  6. Mixins from Lisp Machine Lisp
  7. Closures from Scheme

How many did you get right ? :)

Now looking forward to Day 2 starting in a few more hours.

Technorati: conf rubyconfindia ruby jruby rubyonrails glassfish bangalore bengaluru india oracle

Friday Mar 19, 2010

Spark IT 2010 Trip Report

Spark IT 2010 - the inaugural conference by CIOL and PCQuest (@pcquest) wrapped up earlier today.

With 1000+ attendees, 3 session tracks, and 1 hands-on lab running simultaneously, there was a lot for the attendees to consume.

Watch a brief video chat with Anil Chopra, Editor PCQuest on why/where/how of the conference:

Here are the three originally planned sessions (+ slides) I delivered over the past couple of days:

The fourth session was a slide-free session and showed Java EE 6 tooling using NetBeans (TOTD #122, screencast #29, TOTD #95, TOTD #94, TOTD #93) and Eclipse (TOTD #102 and TOTD #99). Future sessions will include IntellIJ as well as the support over there is still primitive and I need to spend more time trying to understand it ;-) 

One of the Day 2 keynote session speaker could not deliver the session and so I was called to talk about something that might be of interest to the broader set of attendees. After much thinking I delivered a presentation talking about the evolution of the Java platform and how it provides a rich and robust platform for creating next generation services. The session also included details on some features in the upcoming JDK 7 which was well appreciated. Anyway, the slides are available here:

The Hudson session was also covered here and Day 2 keynote session got coverage here.

There were tons of interesting discussions with @tshanky, @venkat_s, @iamprabhu, @rbhardwaj1, @binodmaliel, @akkirajub, @simon, Dr B V Kumar, and several other speakers.

Many thanks to Cyber Media and all the volunteers who did a meticulous job in coordinating the conference!

Now a little bit about my personal stay at the hotel.

Selva Kumaran is the current Mr Bengaluru and was amongst top-10 in Mr India Body Building Championship last year. He provides free personal training sessions to the guests staying at Goldfinch Hotel. And I certainly availed couple of sessions there and totally enjoyed them. He is one of the reasons I'll probably go back and stay at that hotel :-)

Another reason to go back to this hotel is Kabab Studio restaurant on their terrace. An open air dining, live ghazal singing, and well marinated barbecue together adds to the overall ambience. 

Here are some pictures from the conference:

And the complete evolving album at:

So for now, 1 conference, 4 planned + 1 unplanned sessions, and 1 hotel are covered. Many thanks to Cyber Media for inviting and hosting us. I certainly look forward to participating in SparkIT 2011.

There are 2 more conferences, 5 planned sessions, 2 hotels, and 1 more city still remaining.

The first Ruby Conf India starts tomorrow ... yaay! And of course you'll hear about how GlassFish seamlessly supports multiple Ruby frameworks on Mar 21 (Sunday) at 11am in Track1.

Technorati: conf bengaluru india glassfish netbeans eclipse javaee jruby rubyonrails sparkit

Monday Dec 07, 2009

TOTD #116: GlassFish v3 Administration using JavaFX front-end - JNLP available

As mentioned in TOTD #113, this Tip Of The Day (TOTD) provides a working version of the JavaFX front-end for GlassFish v3 administration.

Please click here to launch the JNLP or click here to a page that provides some introduction along with the link to JNLP. You may like to enable Java Console as explained in TOTD #114 for any log messages.

See a video of the tool in action:

Many thanks to Rajeshwar for providing feedback and helping me understand the RESTful interface better. TOTD #96 explains how the REST interface can be used.

Here is a TODO list in no particular order:

  • Show a splash screen after the startup to indicate server status
  • Allow the administration host/port to be changed
  • Tie the "server stats" with the server uptime instead of fetching once and then binding it locally
  • Provide dynamic updates of the monitoring data, currently its a snapshot
  • Convert the monitoring levels text boxes to radio buttons
  • Provide complete hints on setting monitoring level based upon the engines
  • Enable/Disable the buttons based upon the status of server running (or not)
  • Introduce charts to track dynamic shrink/expand of threads/pools/etc.
  • Probably something else that I'm forgetting :-)

How are you using JavaFX with GlassFish ?

How will you use GlassFish v3 REST interface in your tools ?

Technorati: totd javafx glassfish v3 rest web jruby rubyonrails rest administration monitoring management

Tuesday Nov 10, 2009

TOTD #113: JavaFX front-end for GlassFish v3 Administration - Using REST interface

GlassFish v3 provides a REST interface to management and monitoring information as discussed in TOTD #96. As mentioned in that blog "the REST interface is a lower level API that enables toolkit developers and IT administrators to write their custom scripts/clients using language of their choice". This blog introduces a tool that uses the REST API to provide management and monitoring of GlassFish v3 and is written using JavaFX.

This tool is only a proof-of-concept that demonstrates that GlassFish v3 REST interface is functionally very rich and can indeed be used to write third-party administration tools. The tool uses a subset of the REST interface and exposes only a limited amount of management and monitoring capabilities otherwise exposed. After all this is a proof-of-concept :-)

A screencast of this tool in action along with a downloadable JNLP version will soon be available. For now, here is a snapshot of the main window of this tool:

The main screen allows you to enter a URL for the GlassFish administration. Then the GlassFish instance can be stopped/restarted from the main window using the buttons on top right. There is an animation at the bottom of the screen where the glassfish is swimming in the ocean and is directly related to the state of server running in the background. If the server is running, the animation works. If the server is not running then the animation stops as well.

The main screen has three main buttons:

  • "List Applications" - list all the applications deployed on the running instance
  • "Show Monitoring Levels" - show/Update all the monitoring levels
  • "Server Stats" - show statistics of the running server

Clicking on "List Applications" shows the list of applications deployed on this particular instance. Here is how a snapshot looks like for an instance running on my localhost at port 4848:

As shown in the screen, it shows a radio-bulleted list of all the applications. Each bullet is also accompanied by an image indicating the type of application - Web or Rails for now. Select the application and click on "Monitor" button to monitor that particular application. The REST API exposes a vast amount of monitoring data but a subset of monitoring data is displayed for Web and Rails application for now. Here is a snapshot of the monitoring data published for a Web application:

As evident by the list of engines, this web application has EJBs bundled as well. It also shows total number of Servlets/JSPs loaded, number of requests made to this web application and some other monitoring data.

Here is a snapshot of the monitoring data published for a Rails application:

It shows number of JRuby runtimes configured for the application, number of requests sent to the application, number of responses with different HTTP access codes and some other data.

The monitoring levels of different containers can be easily updated by clicking on "Show Monitoring Levels" as shown below:

And finally some server statistics are shown by clicking on "Server Stats" as shown below:

It shows when the server was started, host/port information, version and finally how long the server has been running for. The dials are an animation that shows the server up time.

Here are other related JavaFX and GlassFish related blogs published earlier:

How are you going to use the REST interface exposed by GlassFish v3 in your environment ?

Are you using JavaFX with GlassFish together in any way ?

Leave a comment on this blog if you do!

Technorati: javafx glassfish v3 rest web jruby rubyonrails rest administration monitoring management

Friday Sep 18, 2009

Free Rails/GlassFish Webinar with live Q&A: Sep 23, 2009,10am PT

Got the following message in my inbox today:

All details (including registration) are available here.

Looking forward to see you there!

Technorati: glassfish rubyonrails jruby webinar

Thursday Sep 17, 2009

TOTD #104: Popular Ruby-on-Rails applications on GlassFish v3 – Redmine, Typo, Substruct

GlassFish v3 is opening up new frontiers by allowing to easily deploy Rails, Grails and Django applications, in addition to Java EE, without any additional packaging. You can even write a custom container to support new types of applications. Numerous entries on this blog have talked about how to deploy Rails applications on GlassFish v3. This Tip Of The Day (TOTD) will recap them and, once again, demonstrate how to easily get started with deploying some popular open source Rails applications on GlassFish v3.

Lets prepare a GlassFish v3 build for deploying Rails applications. This blog is going to use 9/16 nightly but you should pick the latest nightly or promoted.

  1. Unzip the downloaded bundle as:
    ~/tools/glassfish/v3/9-16 >unzip ~/Downloads/
  2. Configure JRuby/Rails in GlassFish v3 - JRuby/rails can be configured three different ways - use a previously installed JRuby/Rails directory, install JRuby/Rails module using the graphical Update Center or the "pkg" binary. This Update Center module comes packaged with JRuby 1.3.1, Rails 2.3.2 and some other useful gems. Pick the option you are most comfortable with and use it for your GlassFish installation.
    1. Configure previously installed JRuby/Rails directory as:
      ~/tools/glassfish/v3/9-16/glassfishv3/bin/asadmin create-jvm-options -Djruby.home=/Users/arungupta/tools/jruby
      Authentication failed with password from login store: /Users/arungupta/.asadminpass
      Enter admin password >
      created 1 option(s)
      Command create-jvm-options executed successfully.

      That's it!
    2. Install JRuby/Rails module using graphical Update Tool
      1. The graphical Update Tool tool can be invoked as:
        ~/tools/glassfish/v3/9-16/glassfishv3 >./bin/updatetool
        The software needed for this command (updatetool) is not installed.
        If you choose to install Update Tool, your system will be automatically
        configured to periodically check for software updates. If you would like
        to configure the tool to not check for updates, you can override the
        default behavior via the tool's Preferences facility.
        When this tool interacts with package repositories, some system information
        such as your system's IP address and operating system type and version
        is sent to the repository server. For more information please see:
        Once installation is complete you may re-run this command.
        Would you like to install Update Tool now (y/n): y
        Proxy: Using system proxy settings.
        Install image: /Users/arungupta/tools/glassfish/v3/9-16/glassfishv3
        Installing pkg packages.
        Installing updatetool packages.
        Registering notifier: Already registered.
        Initialization complete.
        Software successfully installed. You may now re-run this command (updatetool).
      2. The first invocation of the command installs the Update Tool and the second invocation shows the following screen after "JRuby on GlassFish" module is selected:

        Click on green button in the top left to install the module and it picks up the dependencies as well as shown below:

        Click on "Install" to start the installation and click on "Accept" to accept the license.
      3. Close the Update Tool window once the installation is completed. The module creates "glassfish/jruby" directory.
    3. Install JRuby/Rails module using "pkg" binary
      1. Install the JRuby/Rails bits using the "pkg" binary. Invoke the command as:
        ~/tools/glassfish/v3/9-16/glassfishv3 >./bin/pkg

        The software needed for this command (pkg) is not installed. When this tool interacts with package repositories, some system information such as your system's IP address and operating system type and version is sent to the repository server. For more information please see: Once installation is complete you may re-run this command. Would you like to install this software now (y/n): y Proxy: Using system proxy settings. Install image: /Users/arungupta/tools/glassfish/v3/9-16/glassfishv3 Installing pkg packages. Initialization complete. Software successfully installed. You may now re-run this command (pkg).
      2. The command "pkg list -a" shows all the modules available for installation and the output looks like:

        ~/tools/glassfish/v3/9-16/glassfishv3 >./bin/pkg list -a
        NAME (PUBLISHER)                              VERSION         STATE      UFIX
        ant (                   1.7.1-0.6       known      ----
        felix                                         2.0.0-0         installed  ----
        glassfish-appclient                           3.0-65          installed  ----
        glassfish-cmp                                 3.0-65          installed  ----
        . . .
        jersey-docs-and-examples                      1.1.2-1.0       known      ----
        jmaki (                 1.8.1-2.0       known      ----
        jruby                                         1.3.1-1.1       known      ----
        jruby (                 1.2.0-1.1       known      u---
        jruby-gems (            2.3.2-1.1       known      ----
        jython-container (      0.5.3-1.0       known      ----
        jython-runtime (        2.5.0-1.0       known      ----
        metro                                         2.0-19          installed  ----
        . . .
        updatetool                                    2.3.0-36.2403   known      ----
        updatetool (            2.2.2-30.2311   known      u---
        wxpython2.8-minimal                  known      ----
        wxpython2.8-minimal (   2.8.8-30.2311   known      u---
      3. Start the installation of "jruby" module as:

        ~/tools/glassfish/v3/9-17/glassfishv3 >./bin/pkg install jruby
        DOWNLOAD                                  PKGS       FILES    XFER (MB)
        Completed                                  2/2 14810/14810    37.0/37.0
        PHASE                                        ACTIONS
        Install Phase                            17273/17273
  3. Redmine on GlassFish - Redmine is an open source project management web application. The simplified steps to deploy Redmine on GlassFish v3 are given below (also on GlassFish Gem and on GlassFish v3 TP2):
    1. Download and unzip Redmine 0.8.5 (latest stable release).
    2. Change the database adapter from "mysql" to "jdbcmysql" as:

      sed s/'adapter: mysql'/'adapter: jdbcmysql'/ <config/ >config/database.yml
    3. Create the database manually as "sudo mysqladmin create redmine_development". "db:create" fails because of JRUBY-3502.
    4. Migrate the database as "db:migrate".
    5. Deploy the application as:
      ~/samples/jruby/redmine >~/tools/glassfish/v3/9-16/glassfishv3/bin/asadmin deploy redmine-0.8.5
       Authentication failed with password from login store: /Users/arungupta/.asadminpass
      Enter admin password>
      Command deploy executed successfully.
    6. Here are some snapshots from the deployed application:

  4. Typo on GlassFish - Typo is the oldest Ruby on Rails blogware. The simplified steps to deploy Typo on GlassFish v3 are given below (also on GlassFish Prelude):
    1. Download and unzip Typo 5.3 (latest stable release).
    2. Change the database adapter from "mysql" to "jdbcmysql" as:

      sed s/'adapter: mysql'/'adapter: jdbcmysql'/ <config/database.yml.example >config/database.yml
    3. Create the database manually as "sudo mysqladmin create typo_dev". "db:create" fails because of JRUBY-3502.
    4. Typo runs using Rails 2.2.2 so lets install Rails 2.2.2 so lets install Rails 2.2.2 as:
      ~/samples/jruby/typo/typo-5.3 >~/tools/glassfish/v3/9-16/glassfishv3/glassfish/jruby/bin/jruby -S gem install rails -v 2.2.2
      JRuby limited openssl loaded. gem install jruby-openssl for full support.
      Successfully installed activesupport-2.2.2
      Successfully installed activerecord-2.2.2
      Successfully installed actionpack-2.2.2
      Successfully installed actionmailer-2.2.2
      Successfully installed activeresource-2.2.2
      Successfully installed rails-2.2.2
      6 gems installed
      Installing ri documentation for activesupport-2.2.2...
      Installing ri documentation for activerecord-2.2.2...
      Installing ri documentation for actionpack-2.2.2...
      Installing ri documentation for actionmailer-2.2.2...
      Installing ri documentation for activeresource-2.2.2...
      Installing ri documentation for rails-2.2.2...
      Installing RDoc documentation for activesupport-2.2.2...
      Installing RDoc documentation for activerecord-2.2.2...
      Installing RDoc documentation for actionpack-2.2.2...
      Installing RDoc documentation for actionmailer-2.2.2...
      Installing RDoc documentation for activeresource-2.2.2...
      Installing RDoc documentation for rails-2.2.2...
    5. Migrate the database as "db:migrate".
    6. Deploy the application as:
      ~/samples/jruby/typo >~/tools/glassfish/v3/9-16/glassfishv3/bin/asadmin deploy typo-5.3
      Authentication failed with password from login store: /Users/arungupta/.asadminpass
      Enter admin password>
      Command deploy executed successfully.
    7. Here are are some snapshots from the deployed application:

  5. Substruct on GlassFish - Substruct is an open source E-Commerce project in Ruby-on-Rails. The simplified steps to deploy Substruct on GlassFish v3 are given below (also on GlassFish v3 Gem):
    1. Download and unzip substruct 1.0 a6 (latest stable release).
    2. Install the required gems as:
      ~/samples/jruby/substruct >~/tools/glassfish/v3/9-16/glassfishv3/glassfish/jruby/bin/jruby -S gem install RedCloth fastercsv mime-types mini_magick ezcrypto jruby-openssl --no-ri --no-rdoc
    3. Change the database adapter from "mysql" to "jdbcmysql" as:

      ~/samples/jruby/substruct/substruct_rel_1-0-a6>sed s/'adapter: mysql'/'adapter: jdbcmysql'/ <config/database.yml
      ~/samples/jruby/substruct/substruct_rel_1-0-a6>mv config/ config/database.yml
    4. Create the database manually as "sudo mysqladmin create substruct_development". "db:create" fails because of JRUBY-3502.
    5. Initialize the database as:
      ~/samples/jruby/substruct/substruct_rel_1-0-a6 >~/tools/glassfish/v3/9-16/glassfishv3/glassfish/jruby/bin/jruby -S rake substruct:db:bootstrap
    6. Deploy the application as:
      ~/samples/jruby/substruct >~/tools/glassfish/v3/9-16/glassfishv3/bin/asadmin deploy substruct_rel_1-0-a6
      Authentication failed with password from login store: /Users/arungupta/.asadminpass
      Enter admin password>
      Command deploy executed successfully.
    7. Here is a snapshot of the deployed application:

So we deployed Redmine, Typo, and Substruct using JRuby/Rails on GlassFish without any additional packaging. There are several Rails applications deployed in production on GlassFish.

What Rails applications are you deploying on GlassFish ?

Technorati: glassfish v3 rubyonrails jruby redmine typo mephisto substruct

Tuesday Aug 11, 2009

TOTD #92: Session Failover for Rails applications running on GlassFish

The GlassFish High Availability allows to setup a cluster of GlassFish instances and achieve highly scalable architecture using in-memory session state replication. This cluster can be very easily created and tested using the "clusterjsp" sample bundled with GlassFish. Here are some clustering related entries published on this blog so far:
  • TOTD #84 shows how to setup Apache + mod_proxy balancer for Ruby-on-Rails load balancing
  • TOTD #81 shows how to use nginx to front end a cluster of GlassFish Gems
  • TOTD #69 explains how a GlassFish cluster can be front-ended using Sun Web Server and Load Balancer Plugin
  • TOTD #67 shows the same thing using Apache httpd + mod_jk
#67 & #69 uses a web application "clusterjsp" (bundled with GlassFish) that uses JSP to demonstrate in-memory session replication state replication. This blog creates a similar application "clusterrails" - this time using Ruby-on-Rails and deploy it on GlassFish v2.1.1. The idea is to demonstrate how Rails applications can leverage the in-memory session replication feature of GlassFish.

Rails applications can be easily deployed as a WAR file on GlassFish v2 as explained in TOTD #73. This blog will guide through the steps of creating the Controller and View to mimic "clusterjsp" and configuring the Rails application for session replication.
  1. Create a template Rails application and create/migrate the database. Add a Controller/View as:

    ~/samples/jruby/session >~/tools/jruby/bin/jruby script/generate controller home index
    JRuby limited openssl loaded. gem install jruby-openssl for full support.
          exists  app/controllers/
          exists  app/helpers/
          create  app/views/home
          exists  test/functional/
          create  test/unit/helpers/
          create  app/controllers/home_controller.rb
          create  test/functional/home_controller_test.rb
          create  app/helpers/home_helper.rb
          create  test/unit/helpers/home_helper_test.rb
          create  app/views/home/index.html.erb

  2. Edit the controller in "app/controllers/home_controller.rb" and change the code to (explained below):

    class HomeController < ApplicationController
      include Java

      def index
        @server_served = servlet_request.get_server_name
        @port = servlet_request.get_server_port
        @instance = java.lang.System.get_property "com.sun.aas.instanceName"
        @server_executed =
        @ip =
        @session_id = servlet_request.session.get_id
        @session_created = servlet_request.session.get_creation_time
        @session_last_accessed = servlet_request.session.get_last_accessed_time
        @session_inactive = servlet_request.session.get_max_inactive_interval

        if (params[:name] != nil)
          servlet_request.session[params[:name]] = params[:value]

        @session_values = ""
        value_names = servlet_request.session.get_attribute_names
        unless (value_names.has_more_elements)
          @session_values = "<br>No parameter entered for this request"
            @session_values << "<UL>"
            while (value_names.has_more_elements)
                param = value_names.next_element
                unless (param.starts_with?("__"))
                  value = servlet_request.session.get_attribute(param)
                  @session_values << "<LI>" + param + " = " + value + "</LI>"
            @session_values << "</UL>"


      def adddata
        servlet_request.session.set_attribute(params[:name], params[:value])
        render :action => "index"

      def cleardata
        render :action => "index"

    The "index" action initializes some instance variables using the "servlet_request" variable mapped from "javax.servlet.http.ServletRequest" class. The "servlet_request" provides access to different properties of the request received such as server name/port, host name/address and others. It also uses an application server specific property "com.sun.aas.instanceName" to fetch the name of particular instance serving the request. In this blog we'll create a cluster with 2 instances. The action then prints the servlet session attributes name/value pairs entered so far.

    The "adddata" action takes the name/value pair entered on the page and stores them in the servlet request. The "cleardata" action clears any data that is storied in the session.
  3. Edit the view in "app/views/home/index.html.erb" and change to (explained below):

    <p>Find me in app/views/home/index.html.erb</p>
    <B>HttpSession Information:</B>
    <LI>Served From Server:   <b><%= @server_served %></b></LI>
    <LI>Server Port Number:   <b><%= @port %></b></LI>
    <LI>Executed From Server: <b><%= @server_executed %></b></LI>
    <LI>Served From Server instance: <b><%= @instance %></b></LI>
    <LI>Executed Server IP Address: <b><%= @ip %></b></LI>
    <LI>Session ID:    <b><%= @session_id %></b></LI>
    <LI>Session Created:  <%= @session_created %></LI>
    <LI>Last Accessed:    <%= @session_last_accessed %></LI>
    <LI>Session will go inactive in  <b><%= @session_inactive %> seconds</b></LI>
    <% form_tag "/session/home/index" do %>
      <label for="name">Name of Session Attribute:</label>
      <%= text_field_tag :name, params[:name] %><br>

      <label for="value">Value of Session Attribute:</label>
      <%= text_field_tag :value, params[:value] %><br>

        <%= submit_tag "Add Session Data" %>
    <% end  %>
    <% form_tag "/session/home/cleardata" do %>
        <%= submit_tag "Clear Session Data" %>
    <% end %>
    <% form_tag "/session/home/index" do %>
        <%= submit_tag "Reload Page" %>
    <% end %>
    <B>Data retrieved from the HttpSession: </B>
    <%= @session_values %>

    The view dumps the property value retrieved from the servlet context in the action. Then it consists of some forms to enter the session name/value pairs, clear the session and reload the page. The application is now ready, lets configure it for WAR packaging.
  4. Generate a template "web.xml" and copy it to "config" directory as:

    ~/samples/jruby/session >~/tools/jruby/bin/jruby -S warble war:webxml
    mkdir -p tmp/war/WEB-INF
    ~/samples/jruby/session >cp tmp/war/WEB-INF/web.xml config/
    1. Edit "tmp/war/WEB-INF/web.xml" and change the first few lines from:

      <!DOCTYPE web-app PUBLIC
        "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"


      <web-app version="2.4" xmlns="" xmlns:xsi="" xsi:schemaLocation="">

      This is required because the element to be added next is introduced in the Servlet 2.4 specification.
    2. Add the following element:


      as the first element, right after "<web-app>". This element marks the web application to be distributable across multiple JVMs in a cluster.
  5. Generate and configure "warble/config.rb" as described in TOTD #87. This configuration is an important step otherwise you'll encounter JRUBY-3789. Create a WAR file as:

    ~/samples/jruby/session >~/tools/jruby/bin/jruby -S warble
    mkdir -p tmp/war/WEB-INF/gems/specifications
    cp /Users/arungupta/tools/jruby-1.3.0/lib/ruby/gems/1.8/specifications/rails-2.3.2.gemspec tmp/war/WEB-INF/gems/specifications/rails-2.3.2.gemspec

    . . .

    mkdir -p tmp/war/WEB-INF
    cp config/web.xml tmp/war/WEB-INF
    jar cf session.war  -C tmp/war .

  6. Download latest GlassFish v2.1.1, install/configure GlassFish and create/configure/start a cluster using the script described here. Make sure to change the download location and filename in the script. This script creates a cluster "wines" with two instances - "cabernet" runing on the port 58080 and "merlot" running on the port 58081.
  7. Deploy the application using the command:

    ~/samples/jruby/session >asadmin deploy --target wines --port 5048 --availabilityenabled=true session.war
Now, the screenshots from the two instances are shown and explained below. The two (or more) instances are front-ended by a load balancer so none of this is typically visible to the user but it helps to understand.
Here is a snapshot of this application deployed on "cabernet":

The instance name and the session id is highlighted in the red box. It also shows the time when the session was created in "Session Created" field.

And now the same application form "merlot":

Notice, the session id exactly matches the one from the "cabernet" instance. Similarly "Session Created" matches but "Last Accessed" does not because the same session session is accessed from a different instance.

Lets enter some session data in the "cabernet" instance and click on "Add Session Data" button as shown below:

The session attribute is "aaa" and value is "111". Also the "Last Accessed" time is updated. In the "merlot" page, click on the "Reload Page" button and the same session name/value pairs are retrieved as shown below:

Notice, the "Last Accessed" time is after the time showed in "cabernet" instance. The session information added in "cabernet" is automatically replicated to the "merlot" instance.

Now, lets add a new session name/value pair in "merlot" instance as shown below:

The "Last Accessed" is updated and the session name/value pair ("bbb"/"222") is shown in the page. Click on "Reload page" in "cabernet" instance as shown below:

This time the session information added to "merlot" is replicated to "cabernet".

So any session information added in "cabernet" is replicated to "merlot" and vice versa.

Now, lets stop "cabernet" instance as shown below:

and click on "Reload Page" in "merlot" instance to see the following:

Even though one instance from which the session data was added is stopped, the replicating instance continues to serve both the session values.

As explained earlier, these two instances are front-ended by a load-balancer typically running at port 80. So the user makes a request to port 80 and the correct session values are served even if one of the instance goes down and there by providing in-memory session replication.

Please leave suggestions on other TOTD that you'd like to see. A complete archive of all the tips is available here.

Technorati: totd glassfish clustering rubyonrails jruby highavailability loadbalancer

Sunday Aug 02, 2009

TOTD #88: How add pagination to Rails - will_paginate

This Tip Of The Day (TOTD) explains how to add pagination to your Rails application.
  1. Create a simple Rails scaffold as:

    ~/samples/jruby >~/tools/jruby/bin/jruby -S rails paginate
    ~/samples/jruby/paginate >~/tools/jruby/bin/jruby script/generate scaffold book title:string author:string
    ~/samples/jruby/paginate >sed s/'adapter: sqlite3'/'adapter: jdbcsqlite3'/ <config/database.yml >config/
    ~/samples/jruby/paginate >mv config/ config/database.yml
    ~/samples/jruby/paginate >~/tools/jruby/bin/jruby -S rake db:migrate

  2. Edit "test/fixtures/books.yml" and specify the content as:

    # Read about fixtures at

      title: Ultramarathon Man Confessions of an All-Night Runner
      author: Dean Karnazes

      title: My Life on the Run
      author: Bart Yasso

      title: 50/50 Secrets I Learned Running 50 Marathons in 50 Days
      author: Dean Karnazes

      title: Born to Run
      author: Christopher Mcdougall

      title: Four Months to a Four-hour Marathon
      author: Dave Kuehls

      title:  Galloway's Book on Running
      author: Jeff Galloway

      title: Marathoning for Mortals
      author: John Bingham and Jenny Hadfield

      title:  Marathon You Can Do It!
      author: Jeff Galloway

      title: Marathon The Ultimate Training Guide
      author: Hal Higdon

      title: Running for Mortals
      author: John Bingham and Jenny Hadfield

    and load the fixtures as:

    ~/samples/jruby/paginate >~/tools/jruby/bin/jruby -S rake db:fixtures:load
    (in /Users/arungupta/samples/jruby/paginate)

  3. Run the application as:

    ~/samples/jruby/paginate >~/tools/jruby/bin/jruby -S glassfish -l
    Starting GlassFish server at: in development environment...
    Writing log messages to: /Users/arungupta/samples/jruby/paginate/log/development.log.

    . . .

    Jul 29, 2009 2:06:44 PM com.sun.grizzly.scripting.pool.DynamicPool$1 run
    INFO: New instance created in 7,488 milliseconds

    The application is accessible at "http://localhost:3000/books" and looks like:

    The page shows 10 rows, all in one page.
  4. Lets add pagination to this simple sample.
    1. Install will_paginate gem as:

      /tools/jruby >./bin/jruby -S gem install will_paginate
      JRuby limited openssl loaded. gem install jruby-openssl for full support.
      Successfully installed will_paginate-2.2.2
      1 gem installed
      Installing ri documentation for will_paginate-2.2.2...
      Installing RDoc documentation for will_paginate-2.2.2...

      There are other methods of installation as well.
    2. Edit "config/environment.rb" and add

      require "will_paginate"

      as the last line.
    3. Edit the "index" action in "app/controllers/books_controller.rb" as:

      @books = Book.paginate(:page => params[:page], :per_page => 5)
      #@books = Book.all

      ":per_page" specifies the number of items to be displayed in each page.
    4. In "app/views/books/index.html.erb", add:

      <%= will_paginate @books %>

      right after "</table>".

      The output now looks like:

      and clicking on "Next" shows:

      The information is nicely split amongst 2 pages.
An important point to remember is that will_paginate only adds pagination to your Rails app. You are still required to display all the values.

But essentially replacing "@books = Book.all" with "@books = Book.paginate(:page => params[:page], :per_page => 5)" in the Controller and adding
"<%= will_paginate @books %>" did the trick for us.

Clean and simple!

Please leave suggestions on other TOTD (Tip Of The Day) that you'd like to see. A complete archive of all the tips is available here.

Technorati: jruby rubyonrails glassfish pagination will_paginate

profile image
Arun Gupta is a technology enthusiast, a passionate runner, author, and a community guy who works for Oracle Corp.

Java EE 7 Samples

Stay Connected


« February 2017