Wednesday Nov 17, 2010

TOTD #150: Collection of GlassFish, NetBeans, JPA, JSF, JAX-WS, EJB, Jersey, MySQL, Rails, Eclipse, and OSGi tips

This is the 150th tip published on this blog so decided to make it a collection of all the previous ones. Here is a tag cloud (created from from title of all the tips:

As expected GlassFish is the most prominent topic. And then there are several entries on NetBeans, JRuby/Rails, several Java EE 6 technologies like JPA, JAX-WS, JAX-RS, EJB, and JSF, and more entries on Eclipse, OSGi and some other tecnhologies too. Here is a complete collection of all the tips published so far:

Just for fun, here is another tag cloud:

You can access all the tips here. And keep those suggestions coming!

Technorati: totd glassfish netbeans jpa jsf jaxws jersey mysql rails osgi eclipse

Tuesday Jan 12, 2010

TOTD #117: Invoke a JAX-WS Web service from a Rails app deployed in GlassFish

A user on GlassFish Forum tried invoking a JAX-WS Web service from a Rails application and faced some issues. This Tip Of The Day (TTOD) will discuss the different approaches and shows their current status.

A Rails app can be deployed on GlassFish in 3 different ways:

  1. Directory Deployment in GlassFish v3 Server - TOTD #72 explains how to deploy a trivial Rails application (with just a scaffold) on GlassFish v3 server. Even though the blog uses a Rails application, any Rack-based application can be deployed on the server. This server is also the Reference Implementation for Java EE 6 and can also run Grails and Django applications.
  2. Directory Deployment using light-weight GlassFish Gem - GlassFish Gem is a light-weight version of the full-blown server and is stripped to run, just like the server, any Rack-based application such as Merb, Rails, and Sinatra. TOTD #70 shows how to deploy the same application using GlassFish Gem.
  3. WAR file in GlassFish v2.x or v3 - TOTD #73 explains how to deploy a Rails application as WAR file on GlassFish v2. The JNDI connection pooling part of the blog may be skipped to simplify the steps but the concepts are still valid. TOTD #44 shows how to do JNDI connection pooling for GlassFish v3. As GlassFish v2 has in-built support for session replication, TOTD #92 demonstrate how Rails application can leverage that functionality.

Now lets get to the issue reported by the user using these 3 deployment models.

First, lets deploy a simple Web service endpoint and generate a JAR file of the client-side artifacts:

  1. This blog will use a simple Web service as defined in screencast #ws7. The Web service endpoint looks like:
    package server;
    import javax.jws.WebService;
     \* @author arungupta
    public class HelloService {
     public String sayHello(String name) {
     return "Hello " + name;

  2. Generate Web service client-side artifacts as:
    ~/samples/v3/rails/webservice/tmp >wsimport -keep http://localhost:8080/HelloWebService/HelloServiceService?wsdl
    parsing WSDL...
    generating code...
    compiling code...
  3. Create a Web service client jar file as:
    jar cvf wsclient.jar ./server

Now lets write a Rails application and invoke this Web service:

  1. Create a simple Rails application as:
    jruby -S rails webservice

    Optionally you may specify "-d mysql" to use MySQL database. Or better un-comment the following line:
    # config.frameworks -= [ :active_record, :active_resource, :action_mailer ]

    in "config/environment.rb" as no database interaction is required.
  2. Create a controller and view as:
    jruby script/generate controller home index
  3. Update the Controller in "app/controllers/home_controller.rb" as:
    include Java
    class HomeController < ApplicationController
     def index
     service =
     port = service.getHelloServicePort
     @result = port.sayHello("Duke")
  4. Change the View in "app/views/home/index.html.erb" as:
    <p>Find me in app/views/home/index.html.erb</p>
    <%= @result %>

Now lets deploy this Web service using the 3 different deployment models mentioned above.

GlassFish v3 allows a directory-based deployment of Rails applications. This application needs to locate the Web service client classes. The "wsclient.jar" can be copied to the "lib" directory of Rails application ("webservice/lib" in our case), "domains/domain1/lib/ext" or "JRUBY_HOME/lib". The library can also be passed during deployment using "--libraries" switch. None of this approach seem to work correctly as explained in issue# 11408. So for now, invoking a JAX-WS Web service from a Rails application deployed directly on GlassFish v3 is not possible, at least until the bug is fixed.

In order to deploy the same application using GlassFish Gem, you can copy "wsclient.jar" to the "lib" directory of your Rails application. And also add the following line to "app/controllers/home_controller.rb":

require 'lib/wsclient.jar'

Alternatively you can copy it to "JRUBY_HOME/lib" directory if this Web service client is accessed my multiple applications. In this case there is no need to add any "require" statement to your Controller. Anyway, running the application as:

jruby -S glassfish

and accessing "http://localhost:3000/home/index" shows the following output:

And finally as explained in TOTD #73, bundle up your original Rails application as WAR and then deploy on GlassFish v3 as:

asadmin deploy webservice.war

Make sure to copy "wsclient.jar" to the "lib" directory of your Rails application and then Warbler will copy it to "WEB-INF/lib" of the generated WAR file. The output is shown as below:

So if you want to invoke a Metro/JAX-WS Web service from a Rails application, then run your Rails application using GlassFish Gem or deploying as a WAR file. It'll work on GlassFish v3 server when issue# 11408 is fixed.

Here are some additional links:

  • TOTD #104 also shows how popular Rails applications such as Redmine, Typo, and Substruct can be easily deployed on GlassFish.
  • Rails applications can be easily clustered using Apache + mod_proxy or  nginx.

A complete archive of all the TOTDs is available here.

Technorati: totd glassfish v3 jruby rails webservice jax-ws metro

Wednesday Oct 07, 2009

TOTD #111: Rails Scaffold for a pre-existing table using Oracle and GlassFish

TOTD #110 explained how to create a brand new Rails application using Oracle database and run it using GlassFish v Gem. This Tip Of The Day explains how to create a scaffold for a sample schema that ships with Oracle database. Even though Rails Scaffold are good for, well, scaffolding but they do get you started easily. This blog will use the sample HR schema that comes along with Oracle database.

Lets get started!

  1. Copy the reverse_scaffold script in the "script" directory of your application created in TOTD #110. This script generates Model and Forms from a pre-existing database table. More details about this script are here.
  2. Edit "config/database.yml" and change the "development" section to:

    adapter: oracle_enhanced
    host: localhost
    database: orcl
    username: hr
    password: hr

    The changes are highlighted in bold, only the username and password values are changed to reflect the default values used with the sample database.
  3. Generate the models and forms for "departments" table as:
    ~/samples/v3/rails/oracle/bookstore >~/tools/jruby/bin/jruby script/reverse_scaffold departments department
    JRuby limited openssl loaded. gem install jruby-openssl for full support.
    JRuby limited openssl loaded. gem install jruby-openssl for full support.
     exists app/models/
     exists app/controllers/
     exists app/helpers/
     create app/views/departments
     exists app/views/layouts/
     exists test/functional/
     exists test/unit/
     create test/unit/helpers/
     exists public/stylesheets/
     create app/views/departments/index.html.erb
     create app/views/departments/show.html.erb
     create app/views/departments/new.html.erb
     create app/views/departments/edit.html.erb
     create app/views/layouts/departments.html.erb
     create public/stylesheets/scaffold.css
     create app/controllers/departments_controller.rb
     create test/functional/departments_controller_test.rb
     create app/helpers/departments_helper.rb
     create test/unit/helpers/departments_helper_test.rb
     route map.resources :departments
     dependency model
     exists app/models/
     exists test/unit/
     exists test/fixtures/
     create app/models/department.rb
     create test/unit/department_test.rb
     create test/fixtures/departments.yml
  4. Edit "app/models/department.rb" and specify the primary key to "department_id" column by adding:
    set_primary_key "department_id"

  5. Run the application as:
    ~/samples/v3/rails/oracle/bookstore >~/tools/jruby/bin/jruby -S glassfish -l
    Starting GlassFish server at: in development environment...
    Writing log messages to: /Users/arungupta/samples/v3/rails/oracle/bookstore/log/development.log.
    Press Ctrl+C to stop.
    Oct 6, 2009 2:14:19 PM start
    INFO: Listening on port 3000
    . . .

    The application is now accessible at "http://localhost:3000/departments" and looks like:
  6. Similarly, create the model and forms for "employees" table as:

    ~/samples/v3/rails/oracle/bookstore >~/tools/jruby/bin/jruby script/reverse_scaffold employees employee
    JRuby limited openssl loaded. gem install jruby-openssl for full support.
    JRuby limited openssl loaded. gem install jruby-openssl for full support.
     exists app/models/
     exists app/controllers/
     exists app/helpers/
     create app/views/employees
     exists app/views/layouts/
     exists test/functional/
     exists test/unit/
     exists test/unit/helpers/
     exists public/stylesheets/
     create app/views/employees/index.html.erb
     create app/views/employees/show.html.erb
     create app/views/employees/new.html.erb
     create app/views/employees/edit.html.erb
     create app/views/layouts/employees.html.erb
     identical public/stylesheets/scaffold.css
     create app/controllers/employees_controller.rb
     create test/functional/employees_controller_test.rb
     create app/helpers/employees_helper.rb
     create test/unit/helpers/employees_helper_test.rb
     route map.resources :employees
     dependency model
     exists app/models/
     exists test/unit/
     exists test/fixtures/
     create app/models/employee.rb
     create test/unit/employee_test.rb
     create test/fixtures/employees.yml

    Specify the primary key to "employee_id" by adding the following to "app/models/employee.rb" as:
    set_primary_key "employee_id"

    The scaffolded table is now available at "http://localhost:3000/employees" and looks like:

So we created a simple Rails CRUD application accessing information from a pre-existing table in the Oracle database server.

Thanks to @mediachk for all the help!

A complete archive of all the TOTDs is available here. The complete list of Rails blog entries are available here.

This and other similar applications will be demonstrated at the upcoming Oracle Open World.

Technorati: totd oracle database glassfish v3 jruby rails oow

Tuesday Oct 06, 2009

TOTD #110: JRuby on Rails application using Oracle on GlassFish

GlassFish v3 is the Reference Implementation for Java EE 6. Following the "extensibility" principle of Java EE 6, it also allows Ruby-on-Rails, Groovy and Grails and Python/Django applications to be seamlessly deployed as well, without any additional packaging. This blog has published multiple entries on deploying a Rails application on GlassFish as given below:

  • TOTD #105: Monitor Rails application using JavaScript
  • TOTD #104: Redmine, Typo, Substruct on GlassFish v3
  • TOTD #84: Apache + mod_proxy_balancer to load balance Rails applications on GlassFish
  • TOTD #81: nginx to load balance Rails applications on GlassFish Gem
  • TOTD #73: Deploying Rails application as WAR on GlassFish v2.1
  • TOTD #72: Deploying Rails application on GlassFish v3
  • TOTD #70: Deploying Rails application on GlassFish Gem

All the existing applications have used JavaDB, SQLite3, or MySQL as the database so far. In the process of getting ready for the upcoming Oracle Open World 2009, this Tip Of The Day will show how to use an Oracle database with a JRuby-on-Rails application deployed on GlassFish v3.

Lets get started!

  1. Install Oracle database as explained in TOTD #106.
  2. Configure JRuby/Rails in GlassFish v3 using one of the mechanisms explained in TOTD #104. Alternatively you can also install the GlassFish gem as:
    >./bin/jruby -S gem install glassfish
    JRuby limited openssl loaded. gem install jruby-openssl for full support.
    Successfully installed rack-1.0.0
    Successfully installed glassfish-0.9.5-universal-java
    2 gems installed
    Installing ri documentation for rack-1.0.0...
    Installing ri documentation for glassfish-0.9.5-universal-java...
    Installing RDoc documentation for rack-1.0.0...
    Installing RDoc documentation for glassfish-0.9.5-universal-java...

    This blog will use GlassFish Gem for running the application described below.
  3. Create a new database user and grant rights using SQL\*Plus as shown:
    Macintosh-187:~ oracle$ sqlplus "/ as sysdba"
    SQL\*Plus: Release - Production on Thu Oct 1 12:32:33 2009
    Copyright (c) 1982, 2007, Oracle.  All Rights Reserved.
    Connected to:
    Oracle Database 10g Release - Production
    SQL> CREATE USER glassfish IDENTIFIED BY glassfish DEFAULT tablespace users TEMPORARY tablespace temp;
    User created.
    SQL> GRANT CONNECT TO glassfish IDENTIFIED BY glassfish;
    Grant succeeded.
    Grant succeeded.
    Grant succeeded.
    Grant succeeded.
    SQL> exit
    Disconnected from Oracle Database 10g Release - Production
    The user name and password are chosen as "glassfish" for simplicity. This is not a recommended setting for production usage though.
  4. Copy Oracle JDBC drivers (odjc6.jar) in JRUBY_HOME/lib directory.
  5. Create a simple Rails application
    1. Make sure the following gems are pre-installed:
      rails (2.3.4)
      activerecord-jdbc-adapter (0.9.2)
      glassfish (0.9.5)

      If not, then install them as:
      jruby -S gem install rails activercord-jdbc-adapter glassfish
    2. Create a simple Rails application as:
      jruby -S rails bookstore -d oracle

    3. Using the normal "jdbc" adapter will give the following error later:

      ActionView::TemplateError (book_url failed to generate from {:controller=>"books", :action=>"show", :id=>#<Book id: #<BigDecimal:3feef1eb,'10000.0',1(8)>, title: "Ultramarathon Man", author: "Dean Karnazes", created_at: "2009-10-06 00:03:14", updated_at: "2009-10-06 00:03:14">}, expected: {:controller=>"books", :action=>"show"}, diff: {:id=>#<Book id: #<BigDecimal:459bdb65,'10000.0',1(8)>, title: "Ultramarathon Man", author: "Dean Karnazes", created_at: "2009-10-06 00:03:14", updated_at: "2009-10-06 00:03:14">}) on line #13 of app/views/books/index.html.erb:

      As evident, the "id" column is returned as BigDecimal where as it should be integer. Fortunately the fix is simple, install the "oracle_enhanced_adapter" (docs) as:

      bookstore >~/tools/jruby/bin/jruby -S gem install activerecord-oracle_enhanced-adapter
      JRuby limited openssl loaded. gem install jruby-openssl for full support.
      Successfully installed activerecord-oracle_enhanced-adapter-1.2.2
      1 gem installed
      Installing ri documentation for activerecord-oracle_enhanced-adapter-1.2.2...
      Installing RDoc documentation for activerecord-oracle_enhanced-adapter-1.2.2...

      Using this "enhanced adapter" is highly recommended for connecting with Oracle databases from Rails applications.
    4. Edit "config/database.yml" and change the "development" section to:
       adapter: oracle_enhanced
       host: localhost
       database: orcl
       username: glassfish
       password: glassfish

      Notice, the username and password values are the same as chosen in the SQL statements above.
    5. Generate a scaffold as:

      bookstore >~/tools/jruby/bin/jruby script/generate scaffold book title:string author:string
      JRuby limited openssl loaded. gem install jruby-openssl for full support.
       exists app/models/
       exists app/controllers/
       exists app/helpers/
       create app/views/books
       exists app/views/layouts/
       exists test/functional/
       exists test/unit/
       create test/unit/helpers/
       exists public/stylesheets/
       create app/views/books/index.html.erb
       create app/views/books/show.html.erb
       create app/views/books/new.html.erb
       create app/views/books/edit.html.erb
       create app/views/layouts/books.html.erb
       create public/stylesheets/scaffold.css
       create app/controllers/books_controller.rb
       create test/functional/books_controller_test.rb
       create app/helpers/books_helper.rb
       create test/unit/helpers/books_helper_test.rb
       route map.resources :books
       dependency model
       exists app/models/
       exists test/unit/
       exists test/fixtures/
       create app/models/book.rb
       create test/unit/book_test.rb
       create test/fixtures/books.yml
       create db/migrate
       create db/migrate/20091005233152_create_books.rb
    6. Prepare your application for JDBC as:
      bookstore >~/tools/jruby/bin/jruby script/generate jdbc
      JRuby limited openssl loaded. gem install jruby-openssl for full support.
       exists config/initializers
       create config/initializers/jdbc.rb
       exists lib/tasks
       create lib/tasks/jdbc.rake

    7. Migrate the database as:
      ~/samples/v3/rails/oracle/bookstore >~/tools/jruby/bin/jruby -S rake db:migrate
      (in /Users/arungupta/samples/v3/rails/oracle/bookstore)
      == CreateBooks: migrating ====================================================
      -- create_table(:books)
       -> 0.0740s
       -> 0 rows
      == CreateBooks: migrated (0.0750s) ===========================================

  6. Lets run the application as:
    ~/samples/v3/rails/oracle/bookstore >~/tools/jruby/bin/jruby -S glassfish -l
    Starting GlassFish server at: in development environment...
    Writing log messages to: /Users/arungupta/samples/v3/rails/oracle/bookstore/log/development.log.
    Press Ctrl+C to stop.
    Oct 6, 2009 9:45:51 AM start
    INFO: Listening on port 3000
    . . .

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

    Click on "New Book" and enter the values as shown:

    Click on "Create" to see the output as:

    Click on "Back" to see the main page as:

    After adding another book, this page looks like:

    And another book ...

So we created a brand new JRuby/Rails application and ran it using GlassFish and Oracle backend. A subsequent blog entry will show how to create a similar application using an existing database.

A complete archive of all the TOTDs is available here. The complete list of Rails blog entries are available here.

This and other similar applications will be demonstrated at the upcoming Oracle Open World.

Technorati: totd oracle database glassfish v3 jruby rails oow

Wednesday Sep 30, 2009

Running Summary Q3 2009 – 400 miles, 80% of running days

Here is the summary of my running logs from Q3 2009 (Jul - Sep):

Even though 3 days of less running than Q2, but the overall mileage was increased. Barely hit that 400 miles mark in Q3 and it did took some extra efforts to reach there ;-) But now tapering for the upcoming Rock-n-Roll 1/2 Marathon this weekend.

5 miles was the most favorite distance being run 17 times and 19.7 miles and 17.4 miles were run only once.

Would you like to generate similar charts for your running logs as well ?

This can be easily achieved using a Rails application or a Wicket application on GlassFish.

Technorati: rails wicket glassfish running rnrsj

Thursday Sep 24, 2009

Q&A Transcript from “Develop, Deploy, and Scale your Rails app with GlassFish” webinar

I delivered a "Develop, Deploy, and Scale your Rails app on GlassFish" webinar earlier today. There were over 300 unique attendees. A complete replay of the webinar is available at

Many thanks to all the attendees for showing their interest in the technology and the panelists who relentlessly answered all the questions. The demos shown are available at:

An edited transcript of the Q&A session is available below. All the names have been removed for privacy reasons.

Q: I took leave from office to attend ur seession..:)
A: Thanks a lot, hopefully you'll enjoy it :)

Q: Is Rails an abbreviation?

Q: can you explain the difference b/t jruby and ruby
A: Ruby is a language and it's original interpreter is written in C. JRuby is pure Java based Ruby interpreter.

Q: What are the added benefits of installing JRuby on Glassfish - in compared to having it always in Rails app WAR?
A: What you get is the Ruby way of developing apps, code-save-refresh or agile experience

Q: Is it true on GF v2.1 as well - since the Rails app will anyway have to be packaged in a war?
A: On glassfish v2.x only WAR style Rails deployment is supported.

Q: Can I run existing rails application on GlassFish?
A: Yes. sure.

Q: is there support for rails 2.3.2? having trouble getting glassfish to run anything higher than 2.2.x
A: Yes, it is there.
A: Please send an email to dev@glassfish with your issue, we would be happy to help you

Q: what additional config is rerquired to support rails?
A: checkout

Q: what I really was after is this: what is the difference of including JRuby (and dependent gems) inside your app war in compared to installing JRuby on GF and having only your own app in the war?
A: When you go in to production , you freeze your gems with app. The thing with glassfish v3 is that you can deploy rails app as WAR as well as directory deployment

Q: on jboss, i have to patch activerecord to use jndi style datasources. is that necessary on glassfish, too ?
A: No, you dont need to.

Q: do you have easy to follow lessons or tutorial for user to try a small real workable application to repeat what you are talking about from your website?
A: Check out checkout

Q: y glass fish used only in java
A: GlassFish is a Java EE App Server

Q: Does Glassfish still have the PermGem out of memory issue when you deploy and undeploy applications.
A: There is a reasonable default setting for PermGen in Glassfish but it depends on your app. You can always set the PermGen to higher value
A: We have run significant number of tests to address this issue. If you do run into it, please let us know by sending an email to dev@glassfish

Q: what is mean by rails

Q: what is jruby?
A: Pure Java based Ruby interpreter. Checkout

Q: what if i have glassfishv2 installed? is there any problem to install jruby gem glassfish?
A: GlassFish gem can be installed in an existing JRuby installation only. For GlassFish v2, Rails applications can only be deployed as WAR file.

Q: so the PermGen out of memory issue is supposedly fixed in Glassfish v3? Or should be fixed also in Glassfish v2.1?
A: when you start JVM there is PermGen space, scripting language interpreteres such as JRuby require higher perm gen. You just need to set it accordingly

Q: This may be a little off topic, but what are the Cons of using JRuby and glassfish? Because everything I've read is great
A: There might be some ruby gems that have native extensions that do not work on JRuby. Having said that, most of the ruby gems that we come across at work on JRuby just fine.

Q: on jboss, serveral jruby runtimes are added. same thing on glassfish ?
A: yes. you can configure the jruby runtime pool. See

Q: so why doesn't everyone use Jruyb? (over ruby MRI?)
A: Its a choice and really depends on personal preference. BTW as a datapoint, hosting company such as has jruby based Ruby/Rails hosting

Q: is this presentation only for mac users? I am a bit shocked with this OSX desktop. I was hoping seeing some Opensolaris etc.
A: No, it is not only for mac users

Q: does glassfish v3 already support cluster profiles?
A: glassfish v3 does not support clustering

Q: i always asked myself if the multiple jruby runtimes write to the same log file.
A: yes they do.

Q: so do you know when (in which release) will the clustering support be added to glassfish v3?
A: It is planned for glassfish v3.1.

Q: apart from glass fish any other server supports
A: mongrel, web rick work on jruby just fine.

Q: can we get support for jruby on jrails on glassfish?
A: Yes you can.
A: Sid, for details on GlassFish subscription support options, please email glassfish

Q: yeah I saw that, a great option I think. I'm just at a state where I can pick either Ruby or JRuby, and JRuby seems far superior and can't really see any of it's fautls
A: yeah, pick JRuby!

Q: Does Ruby create for us the basic GUI for each table?
A: It's Rails that is creating the basic GUI for each table.

Q: why doesn't glassfish support clustering
A: GlassFish v2.1 supports clustering and can be run in production environment.

Q: apart from glass fish any other server supports j2ee
A: Which version of EE are you talking about?

Q: 1.6
A: 1.6 is not final yet, so glassfish is the only implementation of EE6 right now

Q: can you please email me the presentaion slides?
A: Please see - the slides maybe there.

Q: i heard that apache and tomcat server not used for j2ee? is it so?
A: Tomcat implements a subset of the Java EE specifications. It is not a fully compliant Java EE server. GlassFish is fully compliant (it's the reference implementation)

Q: We've been having some issues running Capistrano under JRuby on cygwin -- it gets confused about whether it's in a Windows or Unix-like environment. Any tips?
A: Could be cygwin issue? If not please report with details to

Q: What is Rail Application
A: Check out for more details.

Q: sometimes, you might want to define a dedicated log file per deployed app. jboss logs everything to server.log by default. is it possible to define a dedicated log per app on glassfish
A: I dont have an answer to this, you may like to bring this question to
A: I still dont see why this would an issue. As long as your logs shifts correctly and there is no locking etc. it should be fine. BTw, in production you limit your log anyway to severe error for perf reasons.

Q: so what're the benefits of using the glassfish gem versus mongrel or thin?
A: High performance, jruby runtime pool, daemon mode etc.

Q: Is the v3 Glassfish gem considered to be production ready?
A: Many users that I know already use in production.

Q: nginx or apache is recommended? can glassfish act as the comlete server?
A: GlassFish v3 does not support clustering. It will be coming up in a future release. So you may like to use squid or nginx etc to scale your app

Q: this update is shown how it is updated on mac OSX?
A: Update Center works on all platforms

Q: i'm new to glass fish beacuse i'm just a student....any websites or links that which makes 2 gain more knowledge on it.....
A: can lead you to more details

Q: hey i missed the earlier part of this presentation..!
A: You can look at the recorded session later

Q: what is the built-in web server in glassfish used in the demo? wht would i use apache?
A: grizzly + v3 kernel+ jruby container. You can use Apache to front-end a bunch of GlassFish instances running at the backend.

Q: how to add extra gems in directrory-based deployment?
A: Just how you would use with any Rails app. gem install 'your gem'

Q: this is off the topic, is v3 glassfish going to implement directory based deployment for grails?
A: GlassFish embedded is in works and yes in will support grails directory deployment or 'grails run-app'

Q: Is there a major performance difference between the gem and the standalone war-style deployments?
A: Not much, With glassfish gem or glassfish v3 directory deployment, you are serving the requests at pretty low level. With war deployment its served by the web container

Q: in net beans only glassfish sever is implemented?if any other severs r there in net beans what are they.....
A: There are many other servers supported by NetBeans

Q: can i get the replay after the webinar?
A: Yes, the recorded session will be posted later at

Q: in my company, we use a jboss / jruby / oracle setup. we have issues with newer version activerecord-jdbcadapter (> 8.1.0). is this a known problem ?
A: No idea, consider switching to GlassFish as it works fine there :)

Q: ok, so how does glassfish handle updating the source for your rails app? will it fulfill existing requests and smoothly 'seesaw' to updated instances? ...or does it just drop everything, redeploy and start over?
A: The experience is what you will get on native/MRI Ruby/Rails. glassfish embeds jruby using its internal API and rest is all Rails.

Q: so are gems pre packages apps to deploy?
A: think of gem like packages for Ruby/JRuby platforms.

Q: Please send me a link where I can retrieve the replay of this audio and presentation coz the buffering is really disturbed out here..
A: - recording of this session will be made available

Q: Regarding java gc/memory flags, is there a recommended set of flags for optimal glassfish performance
A: has a White Paper that shows how to tune GF. Although if you get the supported version, you get an add-on called Enterprise manager that can tune the server automatically.

Q: where will jruby be located when I install Jruby glassfish admin web page?
A: glassfish-install-dir/glassfish/jruby

Q: can I use Netbeans to set up my JRuby on Rails app and Glassfish server, but then use another editor or cmd prompt to edit/add to my app?
A: yes you can, although NetBeans provide a functionally complete IDE and serves all your needs.

Q: You are assuming that your server can access the internet. For example, to get the glassfish and Ruby and all upgrades and updates your update program gets the items from your server there on the internet. A secure vault does not have access to the intern
A: True. But you can prepackage everything.

A: GlassFish runs on java.

Q: is it possible to somehow change the rails.env setting _after_ a WAR has been generated? Or does it always require re-warblerizing?
A: warble config; edit config/warble.config to change. Otherwise export RAILS_ENV=production

Q: How would you debug if you packaged the Rails app as a warfile?
A: Thats an issue with the WAR based deployment. You should use directory deployment, specially for your development.

Q: all the server and application for jruby, integration also work on Windows XP professional?
A: Yes, it should work on Windows XP

Q: so jruby is really ready for primetime? good compatibility with existing gems and plugins?
A: yes it is.

Q: A different take on my blog post of the same topic
A: thanks!

Q: Who is the best person to talk to about Grizzly failing to handle multi-part posts in a jruby rails app?
A: Please send email to dev@glassfish. Vivek Pandey is the lead for scripting in GlassFish

Q: are there any supports for pre-compiling ruby code to java byte code?
It would be great if I can hide my ruby code when I release my apps as war.
A: I know there is some jruby option that lets you do it. Either check on or post it to users@jruby or #jruby on irc

Q: while we are using netbeans no problem because servers are inbuilt in the netbeans itself while we usin the ordinary notepad how the servers are to be implemented
A: I do not understand what you mean by implementing a server. A server implemention is implementing to the JavaEE spec. I assume you mean deploying on a server

Q: can anyother scripts can be used instead of javascript
A: Not yet. Ruby and groovy will be coming out in a future release

Q: is it possible to get access to the glassfish admin console using the gem?
A: Sorry, not yet.

Q: so NewRelic is jruby and glassfish compatible?
A: yep

Q: is there any way I can monitor server.log in glassfish admin web interface?
A: - See bottom of URL.

Q: what is the preferred hardware for jruby and rails ? our experience is: sparc is slow and 86based sun hardware is fast for jruby
A: Not required but dual core or higher means better performance

Q: it is possible to implemet content management and ERP application with glassfish and has SUN such applications?
A: We know users deploying Ruby/Rails apps in OpenESB or in SOA env. For ERP or other content management system, as long as you can run these on Glassfish you can surely host Ruby aps there as well

Q: do you have the recommendation for jruby on rails book and good glassfish book?
A: There are several GlassFish books as listed at: Practical JRuby on Rails is a nice book as well (

Q: Does Eclipse incorporate Ruby as NetNeans?
A: Both Eclipse and NetBeans are IDEs. Both support ruby development

Q: any other new servers r gonna compatible with glassfish
A: Once EE6 is final many other application servers will work towards being compatible with EE6

Q: what is the difference in case of performance between standlone war style deployement and gem deployement
A: Not much. gem will give you faster development cycle, easier deployment beside being very light weight (4MB) vs for WAR you need full server.

Q: is there any other IDE which supports ruby dev
A: Not integrated deployment and server side debugging. You can develop Ruby app on IDEA/Aptna studio etc. Typicaly you just need vi or text mate etc.

Q: why can't i run a project developed in netbeans 6.1 on netbeans 6.5
A: Please send an email to the netbeans forum

Q: can I deploy any ruby app I find on jruby?
A: JRuby 1.3.1 is 1.8.6 compliant and going to be using 1.8.7 as the baseline for upcoming JRuby 1.4. The JRuby team is also working on adding Ruby 1.9 compatibility.

Q: i've seen in netbeans at the end of netbeans it is end with IDE what is meant by IDE
A: IDE = "Integrated Development Environment"
A: There is a JRuby-specific distribution of NetBeans IDE

Q: why can't i run a project developed in netbeans 6.1 on netbeans 6.5?
A: You should be able to. If not, try posting to the Netbeans User's alias.

Q: We've been using JRuby on Windows, and are deploying to Solaris using Capistrano. We get mysterious problems establishing an ssh connection that we don't get when we use native Ruby. Any ideas on this?
A: Please send more details to
A: I guess I would need more details on this. you may like to post more info to users@jruby or #jruby irc
A: Paul: if you have purchased support - go through the support channel to address the issue quickly.

Q: Programming wise: are there any differences between ruby and jruby? b/c i think I'm now set on using glassfish, but I'd like to follow a lot of the tutorials out there, but almost all are for ruby
A: JRuby can run any Ruby application 1.8.7 and even 1.9

Q: are there any good books on the topic ?
A: There are several GlassFish books as listed at: Practical JRuby on Rails is a nice book as well (

Q: the ide was complaining that some of the 'items' in the project are missing, how do i do it - netbeans 6.1 to 6.5
A: Sounds like a question that should be posted to the Netbeans email aliases. Sorry, the folks chatting away are GlassFish-centric.

Q: how i can more info about the EE6 and about the jruby
A: EE6 can be obtained from

Q: can JRuby run on Windows 7 and Windows Server 2008?
A: The only requirement for JRuby is JDK which is supported on those platforms, so yes JRuby should work there too.

Q: thanks! I was about to release my Jruby on rails glassfish in production. it encouraged me a lot!
A: Good to know, please send feedback to

Q: opensource+jruby+glassfish resources on the web?
A: for JRuby, for GlassFish.

Q: so again there's full support for rails edge (2.3.2+) with the glassfish v2 server?
A: yes, you need to use warbler gem

Q: so since we already have a support contract with Sun we can also call you and ask about how to best deploy into production?
A: please email and we will immediately reply with a call or answers to your questions.

Q: Is jruby compatible with all its older versions
A: They do maintain backwards compatibility. Ask this question at for a normative answer.

Q: does dun provide jruby training?
A: "Ruby, JRuby, and Rails development Development (with Passion!)" is a free course that offers that training. More details at:

Q: can we deploy EAR on glassfish?????
A: Yes, GlassFish is a Java EE compliant app server so any standard EE artifact, such as EAR, can be easily deployed.

Q: would purchased support require us to deploy on v2?
A: No, you can choose the version of GlassFish you would like to deploy

Q: Can i build complex web system with glass fish, using such things as corba?
A: Very much, feel free to ask detailed question at

Q: I would like to know what would be best platform to use Glassfish on?
A: Being Sun, we prefer Solaris or OpenSolaris, but GlassFish also works well on Linux and Windows.

Q: how does jruby compare to ruby 1.9?
A: JRuby team is working on improving compatibility with Ruby 1.9. Ask your specific question to

Q: Great job guys! I am excited to use this.
A: Thanks, let us know your feedback on

Q: can glassfish be installed on amazon ec2?
A: Yes. There is an AMI with GlassFish, OpenSolaris, and MySQL

Q: is it very easy to deploy on glassfish
A: asadmin deploy yourrailsapp-dir/

Q: So what is the real advantage using ruby? Why not just use java script or some existing language, and what does the Rails part refer to?
A: Its Rails that makes it interesting. Rails is a complete MVC framework

Q: from where could i got jruby
A: JRuby can be downloaded form

Interested in watching a replay of the webinar ? Go to for all the details.

Technorati: glassfish rubyonrails jruby webinar netbeans

Tuesday Sep 22, 2009

TOTD #105: GlassFish v3 Monitoring – How to monitor a Rails app using asadmin, JavaScript, jConsole, REST ?

Monitoring infrastructure in GlassFish v3 is getting an extreme makeover. Prashanth defines it very nicely in his detailed introduction:

We provide a way to dynamically and non-intrusively generate monitoring events from any of the GlassFish runtime classes, the ability to listen to these events, collect the statistics and expose these statistics through various standard clients.

The "dynamic" nature indicates that monitoring can be turned ON or OFF in a GlassFish instance running in production environment. It also means the granularity to which the monitoring information can be generated. This information can be generated for not only a traditional Java EE applications, but Rails, Django and other type of applications that can be easily deployed on GlassFish v3. And that is extensible for other pluggable containers too. The data can be accessed using multiple mechanisms providing the administrator a wide variety of choice for tools, e.g. DTrace, JMX, REST, asadmin CLI, and Admin Console and thus another point in favor of "dynamic".

The "non-intrusive" behavior means that monitoring can be used in production environment with minimal overhead. It also means that there is no overhead when monitoring is not enabled. Anyway, monitoring needs to be explicitly enabled as explained below.

As mentioned above, there are multiple ways to access the monitoring data. The different ways to access the monitoring data are:

  1. DTrace scripts (only on Solaris)
  2. asadmin CLI
  3. Admin Console
  4. JMX/jConsole
  5. REST
  6. Custom client using a 3rd party scripting language (available as value-add feature to paid customers only)

This Tip Of The Day will describe how to access the monitoring data using asadmin CLI and a JavaScript client. Note that the JavaScript client feature is available as a value-add to the community version of GlassFish and available only to the paid customers.

This tip will use a pre-deployed Rails application as (Redmine as described in TOTD #104) on a nightly GlassFish v3 build (CI, nightly, or promoted) and explains how to monitor this application.

Using the terminology defined in Monitoring in GlassFish v3 blog, the JRuby subsystem in GlassFish has multiple probe providers and each provider has multiple probes. The JRuby subsystem also provides multiple stats providers with probe listeners. All of these elements are linked using the monitoring infrastructure in GlassFish.

Lets monitor our Rails application

Monitoring using asadmin CLI

By default the monitoring is turned OFF for all the components. Lets enable monitoring for the JRuby container as:

asadmin enable-monitoring --level jruby-container=HIGH

The other possible values are "LOW" and "OFF". All the probes publishing monitoring data can be listed as:

~/tools/glassfish/v3/9-18/glassfishv3 >./bin/asadmin list --monitor=true "\*"

Command list executed successfully.

A snapshot of the monitoring data can be obtained as:

~/tools/glassfish/v3/9-18/glassfishv3 >./bin/asadmin get --monitor=true "\*jruby\*"
server.containers.jruby.applications.activerubyapplications.redmine-0.8.5-appName = redmine-0.8.5
server.containers.jruby.applications.activerubyapplications.redmine-0.8.5-description =
 server.containers.jruby.applications.activerubyapplications.redmine-0.8.5-environment = development
server.containers.jruby.applications.activerubyapplications.redmine-0.8.5-jrubyVersion = 1.3.0
server.containers.jruby.applications.activerubyapplications.redmine-0.8.5-lastsampletime = 1253322280437
server.containers.jruby.applications.activerubyapplications.redmine-0.8.5-name = redmine-0.8.5
server.containers.jruby.applications.activerubyapplications.redmine-0.8.5-rubyFramework = rails
server.containers.jruby.applications.activerubyapplications.redmine-0.8.5-starttime = 1253322280437
server.containers.jruby.applications.activerubyapplications.redmine-0.8.5-unit =
server.containers.jruby.applications.activerubyappscount-count = 1
server.containers.jruby.applications.activerubyappscount-description = Number of currently loaded Ruby applications
server.containers.jruby.applications.activerubyappscount-lastsampletime = 1253322279921
server.containers.jruby.applications.activerubyappscount-name = ActiveRubyApplications
server.containers.jruby.applications.activerubyappscount-starttime = 1253322279922
server.containers.jruby.applications.activerubyappscount-unit = count
server.containers.jruby.http.redmine-0.8.5.address = null
server.containers.jruby.http.redmine-0.8.5.averageprocessingtime = 0
server.containers.jruby.http.redmine-0.8.5.count200-count = 0
server.containers.jruby.http.redmine-0.8.5.count200-description = Number of responses with a status code equal to 200
server.containers.jruby.http.redmine-0.8.5.count200-lastsampletime = 1253322280245
server.containers.jruby.http.redmine-0.8.5.count200-name = Count200
server.containers.jruby.http.redmine-0.8.5.count200-starttime = 1253322280245
server.containers.jruby.http.redmine-0.8.5.count200-unit = count
server.containers.jruby.http.redmine-0.8.5.count2xx-count = 0
server.containers.jruby.http.redmine-0.8.5.count2xx-description = Number of responses with a status code in the 2xx range
server.containers.jruby.http.redmine-0.8.5.count2xx-lastsampletime = 1253322280245
server.containers.jruby.http.redmine-0.8.5.count2xx-name = Count2xx
server.containers.jruby.http.redmine-0.8.5.count2xx-starttime = 1253322280245
server.containers.jruby.http.redmine-0.8.5.count2xx-unit = count
server.containers.jruby.http.redmine-0.8.5.count302-count = 0
server.containers.jruby.http.redmine-0.8.5.count302-description = Number of responses with a status code equal to 302
server.containers.jruby.http.redmine-0.8.5.count302-lastsampletime = 1253322280245
server.containers.jruby.http.redmine-0.8.5.count302-name = Count302
server.containers.jruby.http.redmine-0.8.5.count302-starttime = 1253322280245
server.containers.jruby.http.redmine-0.8.5.count302-unit = count
server.containers.jruby.http.redmine-0.8.5.count304-count = 0
server.containers.jruby.http.redmine-0.8.5.count304-description = Number of responses with a status code equal to 304
server.containers.jruby.http.redmine-0.8.5.count304-lastsampletime = 1253322280245
server.containers.jruby.http.redmine-0.8.5.count304-name = Count304
server.containers.jruby.http.redmine-0.8.5.count304-starttime = 1253322280245
server.containers.jruby.http.redmine-0.8.5.count304-unit = count
server.containers.jruby.http.redmine-0.8.5.count3xx-count = 0
server.containers.jruby.http.redmine-0.8.5.count3xx-description = Number of responses with a status code in the 3xx range
server.containers.jruby.http.redmine-0.8.5.count3xx-lastsampletime = 1253322280245
server.containers.jruby.http.redmine-0.8.5.count3xx-name = Count3xx
server.containers.jruby.http.redmine-0.8.5.count3xx-starttime = 1253322280245
server.containers.jruby.http.redmine-0.8.5.count3xx-unit = count
server.containers.jruby.http.redmine-0.8.5.count400-count = 0
server.containers.jruby.http.redmine-0.8.5.count400-description = Number of responses with a status code equal to 400
server.containers.jruby.http.redmine-0.8.5.count400-lastsampletime = 1253322280245
server.containers.jruby.http.redmine-0.8.5.count400-name = Count400
server.containers.jruby.http.redmine-0.8.5.count400-starttime = 1253322280245
server.containers.jruby.http.redmine-0.8.5.count400-unit = count
server.containers.jruby.http.redmine-0.8.5.count401-count = 0
server.containers.jruby.http.redmine-0.8.5.count401-description = Number of responses with a status code equal to 401
server.containers.jruby.http.redmine-0.8.5.count401-lastsampletime = 1253322280245
server.containers.jruby.http.redmine-0.8.5.count401-name = Count401
server.containers.jruby.http.redmine-0.8.5.count401-starttime = 1253322280245
server.containers.jruby.http.redmine-0.8.5.count401-unit = count
server.containers.jruby.http.redmine-0.8.5.count403-count = 0
server.containers.jruby.http.redmine-0.8.5.count403-description = Number of responses with a status code equal to 403
server.containers.jruby.http.redmine-0.8.5.count403-lastsampletime = 1253322280245
server.containers.jruby.http.redmine-0.8.5.count403-name = Count403
server.containers.jruby.http.redmine-0.8.5.count403-starttime = 1253322280245
server.containers.jruby.http.redmine-0.8.5.count403-unit = count
server.containers.jruby.http.redmine-0.8.5.count404-count = 0
server.containers.jruby.http.redmine-0.8.5.count404-description = Number of responses with a status code equal to 404
server.containers.jruby.http.redmine-0.8.5.count404-lastsampletime = 1253322280245
server.containers.jruby.http.redmine-0.8.5.count404-name = Count404
server.containers.jruby.http.redmine-0.8.5.count404-starttime = 1253322280245
server.containers.jruby.http.redmine-0.8.5.count404-unit = count
server.containers.jruby.http.redmine-0.8.5.count4xx-count = 0
server.containers.jruby.http.redmine-0.8.5.count4xx-description = Number of responses with a status code in the 4xx range
server.containers.jruby.http.redmine-0.8.5.count4xx-lastsampletime = 1253322280245
server.containers.jruby.http.redmine-0.8.5.count4xx-name = Count4xx
server.containers.jruby.http.redmine-0.8.5.count4xx-starttime = 1253322280245
server.containers.jruby.http.redmine-0.8.5.count4xx-unit = count
server.containers.jruby.http.redmine-0.8.5.count503-count = 0
server.containers.jruby.http.redmine-0.8.5.count503-description = Number of responses with a status code equal to 503
server.containers.jruby.http.redmine-0.8.5.count503-lastsampletime = 1253322280245
server.containers.jruby.http.redmine-0.8.5.count503-name = Count503
server.containers.jruby.http.redmine-0.8.5.count503-starttime = 1253322280245
server.containers.jruby.http.redmine-0.8.5.count503-unit = count
server.containers.jruby.http.redmine-0.8.5.count5xx-count = 0
server.containers.jruby.http.redmine-0.8.5.count5xx-description = Number of responses with a status code in the 5xx range
server.containers.jruby.http.redmine-0.8.5.count5xx-lastsampletime = 1253322280245
server.containers.jruby.http.redmine-0.8.5.count5xx-name = Count5xx
server.containers.jruby.http.redmine-0.8.5.count5xx-starttime = 1253322280245
server.containers.jruby.http.redmine-0.8.5.count5xx-unit = count
server.containers.jruby.http.redmine-0.8.5.countother-count = 0
server.containers.jruby.http.redmine-0.8.5.countother-description = Number of responses with other status codes
server.containers.jruby.http.redmine-0.8.5.countother-lastsampletime = 1253322280245
server.containers.jruby.http.redmine-0.8.5.countother-name = CountOther
server.containers.jruby.http.redmine-0.8.5.countother-starttime = 1253322280245
server.containers.jruby.http.redmine-0.8.5.countother-unit = count
server.containers.jruby.http.redmine-0.8.5.errorcount-count = 0
server.containers.jruby.http.redmine-0.8.5.errorcount-description = Number of responses with a status code greater than 400
server.containers.jruby.http.redmine-0.8.5.errorcount-lastsampletime = 1253322280245
server.containers.jruby.http.redmine-0.8.5.errorcount-name = ErrorCount
server.containers.jruby.http.redmine-0.8.5.errorcount-starttime = 1253322280245
server.containers.jruby.http.redmine-0.8.5.errorcount-unit = count
server.containers.jruby.http.redmine-0.8.5.requestcount-count = 0
server.containers.jruby.http.redmine-0.8.5.requestcount-description = Number of HTTP requests received
server.containers.jruby.http.redmine-0.8.5.requestcount-lastsampletime = 1253322280243
server.containers.jruby.http.redmine-0.8.5.requestcount-name = RequestCounter
server.containers.jruby.http.redmine-0.8.5.requestcount-starttime = 1253322280243
server.containers.jruby.http.redmine-0.8.5.requestcount-unit = count
server.containers.jruby.http.redmine-0.8.5.requestpersecond = null
server.containers.jruby.runtime-pool.redmine-0.8.5.activeruntimes-count = 1
server.containers.jruby.runtime-pool.redmine-0.8.5.activeruntimes-description = Currently active runtimes
server.containers.jruby.runtime-pool.redmine-0.8.5.activeruntimes-lastsampletime = 1253322280241
server.containers.jruby.runtime-pool.redmine-0.8.5.activeruntimes-name = activeRuntimes
server.containers.jruby.runtime-pool.redmine-0.8.5.activeruntimes-starttime = 1253322280241
server.containers.jruby.runtime-pool.redmine-0.8.5.activeruntimes-unit = count
server.containers.jruby.runtime-pool.redmine-0.8.5.applicationname = redmine-0.8.5
server.containers.jruby.runtime-pool.redmine-0.8.5.contextpath = /redmine-0.8.5
server.containers.jruby.runtime-pool.redmine-0.8.5.hardmaximum-count = 1
server.containers.jruby.runtime-pool.redmine-0.8.5.hardmaximum-description = Maximum active runtimes
server.containers.jruby.runtime-pool.redmine-0.8.5.hardmaximum-lastsampletime = 1253322280241
server.containers.jruby.runtime-pool.redmine-0.8.5.hardmaximum-name = hardMaximum
server.containers.jruby.runtime-pool.redmine-0.8.5.hardmaximum-starttime = 1253322280241
server.containers.jruby.runtime-pool.redmine-0.8.5.hardmaximum-unit = count
server.containers.jruby.runtime-pool.redmine-0.8.5.hardmminimum-count = 1
server.containers.jruby.runtime-pool.redmine-0.8.5.hardmminimum-description = Minimum active runtimes
server.containers.jruby.runtime-pool.redmine-0.8.5.hardmminimum-lastsampletime = 1253322280241
server.containers.jruby.runtime-pool.redmine-0.8.5.hardmminimum-name = hardMinimum
server.containers.jruby.runtime-pool.redmine-0.8.5.hardmminimum-starttime = 1253322280241
server.containers.jruby.runtime-pool.redmine-0.8.5.hardmminimum-unit = count

Command get executed successfully.

The command asadmin get --monitor=true "\*jruby\*" dumps a snapshot of the monitoring data such as the number of Ruby currently applications loaded, application name, JRuby version, environment (development / test / production), currently active runtimes, min/max runtimes, number of HTTP requests / responses with a certain HTTP code and much more information. It basically dumps all the JRuby monitoring information captured so far.

An alternate regular expression may be specified such as:

asadmin get --monitor=true "\*jruby\*runtime-pool\*"

to gather only the runtime pool specific values.

Monitoring using JavaScript client

Third-party scripting client are a value-add to the community versions. Just like Enterprise Manager, the value-add will be available as a patch to the users who purchase commercial support. Lets see what can be done with it though.

First of all you can type the command "list-probes" to see a list of all the probes that are available. A typical output will look like:

~/tools/glassfish/v3/9-18/glassfishv3 >./bin/asadmin list-probes
glassfish:kernel:connections-keep-alive:decrementCountConnectionsEvent decrementCountConnectionsEvent(java.lang.String)
glassfish:web:web-module:webModuleStoppedEvent webModuleStoppedEvent(java.lang.String, java.lang.String)
glassfish:jca:connection-pool:connectionValidationFailedEvent connectionValidationFailedEvent(java.lang.String, int)
glassfish:jca:work-management:workWaitedFor workWaitedFor(java.lang.String, long)
glassfish:jdbc:connection-pool:connectionTimedOutEvent connectionTimedOutEvent(java.lang.String)
glassfish:security:ejbpolicy:ejbPCCreationEvent ejbPCCreationEvent(java.lang.String)
glassfish:kernel:thread-pool:threadReturnedToPoolEvent threadReturnedToPoolEvent(java.lang.String, java.lang.String)
glassfish:web:session:sessionPersistedEndEvent sessionPersistedEndEvent(java.lang.String, java.lang.String, java.lang.String)
glassfish:web:http-service:requestStartEvent requestStartEvent(java.lang.String, java.lang.String, java.lang.String, int, java.lang.String, java.lang.String)
glassfish:jdbc:connection-pool:connectionsFreedEvent connectionsFreedEvent(java.lang.String, int)
glassfish:jdbc:connection-pool:toString toString(java.lang.String, java.lang.StringBuffer)
glassfish:jca:connection-pool:decrementFreeConnectionsSizeEvent decrementFreeConnectionsSizeEvent(java.lang.String, int)
glassfish:kernel:connections-keep-alive:incrementCountFlushesEvent incrementCountFlushesEvent(java.lang.String)
glassfish:webservices:109:deploy deploy(com.sun.enterprise.deployment.Application, com.sun.enterprise.deployment.WebServiceEndpoint)
glassfish:jca:connection-pool:connectionAcquiredEvent connectionAcquiredEvent(java.lang.String)
glassfish:web:http-service:requestEndEvent requestEndEvent(java.lang.String, java.lang.String, java.lang.String, int, java.lang.String, java.lang.String, int)
glassfish:kernel:connections-keep-alive:incrementCountRefusalsEvent incrementCountRefusalsEvent(java.lang.String)
glassfish:kernel:connections:connectionConnectedEvent connectionConnectedEvent(java.lang.String, int)
glassfish:kernel:file-cache:addHeapSizeEvent addHeapSizeEvent(java.lang.String, long)
glassfish:jruby:runtime-pool:runtimePoolUpdateEvent runtimePoolUpdateEvent(java.lang.String, int, int, int, int, int)
glassfish:security:web:securityManagerCreationEvent securityManagerCreationEvent(java.lang.String)
glassfish:security:web:securityManagerDestructionEvent securityManagerDestructionEvent(java.lang.String)
glassfish:webservices:ri:undeploy undeploy(
glassfish:web:session:sessionPersistedStartEvent sessionPersistedStartEvent(java.lang.String, java.lang.String, java.lang.String)
glassfish:ejb:pool:objectAddedEvent ejbObjectAddedEvent()
glassfish:ejb:bean:methodStartEvent ejbMethodStartEvent(java.lang.String, java.lang.String, java.lang.String, java.lang.reflect.Method)
glassfish:jdbc:connection-pool:connectionRequestServedEvent connectionRequestServedEvent(java.lang.String, long)

All the JRuby probes can be easily listed as:

~/tools/glassfish/v3/9-18/glassfishv3 >./bin/asadmin list-probes | grep jruby
glassfish:jruby:runtime-pool:runtimePoolUpdateEvent runtimePoolUpdateEvent(java.lang.String, int, int, int, int, int)
glassfish:jruby:http:requestStartEvent requestStartEvent(java.lang.String, java.lang.String, int)
glassfish:jruby:jruby-container:jrubyModuleStartedEvent jrubyModuleStartedEvent(java.lang.String, java.lang.String, java.lang.String, java.lang.String)
glassfish:jruby:jruby-container:jrubyModuleStoppedEvent jrubyModuleStoppedEvent(java.lang.String, java.lang.String, java.lang.String)
glassfish:jruby:http:requestEndEvent requestEndEvent(java.lang.String, int)
glassfish:jruby:runtime-pool:runtimePoolStartEvent runtimePoolStartEvent(java.lang.String, int, int, int, int, int, int, int)

More detailed information about each probe can be easily found by giving the command:

~/tools/glassfish/v3/9-18/glassfishv3 >./bin/asadmin list-probes --manpage=true glassfish:jruby:runtime-pool:runtimePoolUpdateEvent

This will show the detailed information ("man" pages) about the specific probe. A JavaScript client to monitor the deployed Rails application and gather the relevant statistics can be written using these pages as shown below:

moduleStarted = function(appName, appType, env, jruby) {
    client.print( '\\n log> Deployed a \\'' + appType + '\\' app named \\'' + appName + '\\' in \\'' + env + '\\' environment with JRuby \\'' + jruby + '\\'.');

moduleStopped = function(appName, appType, env) {
    client.print( '\\n log> Undeployed a \\'' + appType + '\\' app named \\'' + appName + '\\' in \\'' + env + '\\' environment.');

requestStarted = function(contextPath, serverName, port) {
    client.print( '\\n log> Request started at \\'' + contextPath + '\\' hosted on \\'' + serverName + ':' + port + '\\'');

requestEnded = function(contextPath, statusCode) {
    client.print( '\\n log> Request stopped at \\'' + contextPath + '\\' with status code \\'' + statusCode + '\\'');

runtimePoolStart = function(appName, activeRuntimes, queueSize) {
   client.print( '\\n log> JRuby runtime pool started for the app \\'' + appName + '\\': active runtime - ' + activeRuntimes + ', queue size - ' + queueSize);

runtimePoolUpdate = function(appName, activeRuntimes, queueSize) {
   client.print( '\\n log> JRuby runtime pool updated for the app \\'' + appName + '\\': active runtime - ' + activeRuntimes + ', queue size - ' + queueSize);

moduleStartedParams = java.lang.reflect.Array.newInstance(java.lang.String, 4);
scriptContainer.registerListener('glassfish:jruby:jruby-container:jrubyModuleStartedEvent', moduleStartedParams, 'moduleStarted');

moduleStoppedParams = java.lang.reflect.Array.newInstance(java.lang.String, 3);
scriptContainer.registerListener('glassfish:jruby:jruby-container:jrubyModuleStoppedEvent', moduleStoppedParams, 'moduleStopped');

requestStartParams = java.lang.reflect.Array.newInstance(java.lang.String, 3);
scriptContainer.registerListener('glassfish:jruby:http:requestStartEvent', requestStartParams, 'requestStarted');

requestEndParams = java.lang.reflect.Array.newInstance(java.lang.String, 2);
scriptContainer.registerListener('glassfish:jruby:http:requestEndEvent', requestEndParams, 'requestEnded');

runtimePoolParams = java.lang.reflect.Array.newInstance(java.lang.String, 3);
scriptContainer.registerListener('glassfish:jruby:runtime-pool:runtimePoolStartEvent', runtimePoolParams, 'runtimePoolStart');
scriptContainer.registerListener('glassfish:jruby:runtime-pool:runtimePoolUpdateEvent', runtimePoolParams, 'runtimePoolUpdate');

This script register listeners for different probe events, pass a set of parameters that need to be captured, and print the information in a callback method specified during registration. The number of listeners and parameters / listener may be altered to meet your data capturing needs.

This script is stored in a file "monitor-rails.js" and used as described below. As a Rails application is deployed, requests invoked, and undeployed, the following messages are printed on the console:

~/tools/glassfish/v3/9-18/glassfishv3 >./bin/asadmin run-script monitor-rails.js

 log> Deployed a 'rails' app named 'redmine-0.8.5' in 'development' environment with JRuby '1.3.0'.
 log> JRuby runtime pool started for the app 'redmine-0.8.5': active runtime - 1, queue size - 0
 log> Request started at '/redmine-0.8.5' hosted on 'localhost:8080'
 log> Request stopped at '/redmine-0.8.5' with status code '200'
 log> Request started at '/redmine-0.8.5' hosted on 'localhost:8080'
 log> Request stopped at '/redmine-0.8.5' with status code '200'
 log> Undeployed a 'rails' app named 'redmine-0.8.5' in 'development' environment.

Note "run-script" is the command that comes as part of the value-add. As described earlier, a snapshot of the monitoring information can be easily captured using asadmin as:

~/tools/glassfish/v3/9-18/glassfishv3 >./bin/asadmin get --monitor=true "\*jruby\*request\*"
server.containers.jruby.http.redmine-0.8.5.requestcount-count = 2
server.containers.jruby.http.redmine-0.8.5.requestcount-description = Number of HTTP requests received
server.containers.jruby.http.redmine-0.8.5.requestcount-lastsampletime = 1253638362651
server.containers.jruby.http.redmine-0.8.5.requestcount-name = RequestCounter
server.containers.jruby.http.redmine-0.8.5.requestcount-starttime = 1253638362651
server.containers.jruby.http.redmine-0.8.5.requestcount-unit = count
server.containers.jruby.http.redmine-0.8.5.requestpersecond = 1

Command get executed successfully.

As you can see, the total number of requests is shown as "2".

Just for fun, I ran Apache ab with 20 requests and 4 concurrency ("-n 20 -c 4") on "http://localhost:8080/redmine-0.8.5" and saw the following results:

Monitoring OFF
(no data printed)
(data printed)
Time taken for requests (secs) 26.231 26.997 26.665
Requests per second 0.76 0.74 0.75
Time per request (ms) 1311.574 1349.859 1333.239

The server was restarted between each run. These numbers were generated on my development machine so they are most likely skewed. But as a development benchmark the numbers do indicate that GlassFish v3 monitoring is truly non-intrusive. The total time taken for requests, requests/second, and time/request is pretty much identical.

Future blogs will cover how to access this data using web-based DTrace scripts, web-based Admin Console, jConsole, and REST interface.

A complete archive of all the tips is available here.

Technorati: totd glassfish v3 monitoring asadmin javascript jruby rails redmine

Friday Dec 21, 2007

JRuby 1.0.3 + Rails 2.0 Hello World - Additional Steps Required

JRuby 1.0.3
was recently released and so was Rails 2.0. I decided to try JRuby 1.0.3 + Rails 2.0 and realized that a few additional steps (because of Rails 2.0) are required to get a trivial Hello World applcation up and running. Here are the steps:

  1. Unzip JRuby 1.0.3.
    1. Make sure to set JAVA_HOME and JRUBY_HOME.
    2. Also include JAVA_HOME/bin and JRUBY_HOME/bin in PATH for convenience.
  2. Install Rails 2.0 as shown below:

    ~/samples/jruby arungupta$ jruby -S gem install rails --include-dependencies --no-ri --no-rdoc
    Bulk updating Gem source index for:
    Successfully installed rails-2.0.2
    Successfully installed activesupport-2.0.2
    Successfully installed activerecord-2.0.2
    Successfully installed actionpack-2.0.2
    Successfully installed actionmailer-2.0.2
    Successfully installed activeresource-2.0.2
  3. Create a simple app using the following steps
    1. Create a template app as:

      jruby -S rails --database mysql hello or jruby -S rails -d mysql hello

      It's important to specify --database mysql otherwise Rails 2.0 uses sqlite3 as the default database.
    2. Add a Controller and View as:

      cd hello
      jruby script/generate controller say hello
    3. Edit the controller as:

      vi app/controllers/say_controller.rb

      and add the following variable in "hello" helper method:

      @hello_string = ""
    4. Edit the View as:

      vi app/views/say/hello.html.erb

      and add the following as last line:

      <%= @hello_string %>

      Notice, the view extension is .html.erb instead of .rhtml.
  4. Download, Install and Configure MySQL (additional step for Rails 2.0)
    1. Mac OS comes pre-installed with MySQL in /usr/local/mysql directory. Start the server as:

      sudo ./bin/mysqld_safe

      Alternatively, you can download and install MySQL Universal server (only .dmg format, not tar.gz format as specified here).
    2. Create a database as:

      sudo ./bin/mysqladmin create hello_development
  5. Start the WEBrick server (in hello directory) as:

    jruby script/server
That's it, now your trivial Hello World application is deployed using JRuby 1.0.3 + Rails 2.0 and displays the output in a browser window as:

JRuby 1.0.3 + Rails 2.0 Hello World

Want to try this application on GlassFish v3 gem (download or build your own - now down to 2.4 MB) ?

Technorati: ruby jruby rails mysql glassfish v3 gem

Sunday Dec 16, 2007

JRuby-on-GlassFish Update Center Module - Now Updated with JRuby 1.0.2

Pramod updated the JRuby-on-GlassFish module on the GlassFish Update Center with JRuby 1.0.2, Rails 1.2.6 and Goldspike revision 808.

I created a standalone (self-contained with all the libraries, gems & plug-ins) and shared (contains only web.xml and libraries are loaded from the Application Server instance) WAR image for the bundled Hello World sample. The screencast #web9 provide detail instructions on how to create standalone and shared images. The difference in the image size is pretty significant:

Shared Image 226, 977 bytes
Standalone Image 11,039,883 bytes (48 x)

If you have multiple such applications and each application has one or more plug-ins then this size grows up pretty fast. The war:shared:create rake target in Goldspike is buggy and serves the same purpose as war:standalone:create (#13265).

Loading shared libraries from GlassFish Application Server instance to keep your Rails application size to a minimum is another reason to consider using GlassFish for deploying your JRuby-on-Rails application.

Technorati: glassfish ruby jruby rails goldspike


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


« April 2014