Miles to go …

August 20, 2007

Ruby/JRuby Process Models Explained

Filed under: web2.0 — arungupta @ 8:02 am

In the JRuby Hackday, Nick Sieger described the process models of a Rails application deployed using

In this blog entry I’m capturing a brain dump from him after the event. The images below shows process models in each of the above mentioned approaches. The containment of boxes in each image is shown in terms of the application logic instead of the process. The legend followed in the images is as follows:

In the first approach, a C-based Ruby on Rails application is front-ended by an HTTP library – Mongrel. The typical app will be deployed on a cluster of Mongrel servers – provided by Mongrel_cluster plug-in.

This plug-in configure and control the several Mongrel servers. Mongrel is largely written in Ruby and uses native C for HTTP request parsing. Each instance of Mongrel starts a Ruby interpreter that listens on a server socket. The Ruby script has a Mongrel handler that queues up multiple requests from the client and passes the state, one at a time, to a Rails instance (that is by design single threaded).

For a Mongrel cluster, multiple Ruby interpreters are started as an OS process.

The second approach shows how a Rails application may be deployed using JRuby. This is a transition approach between traditional C-based Ruby on Mongrel deployment and JRuby-based deployment on GlassFish.

Mongrel JCluster is an update to Mongrel_cluster that only runs in JRuby. The biggest difference is that it starts only one Java Virtual Machine (JVM) that starts several Mongrels in the same JVM by spawning multiple JRuby processes, one in each thread. As in traditional approach, each Mongrel listens to the request on a server socket and passes the request state to Rails.

For a Mongrel JCluster, only one JVM is started as an OS process.

The last approach shows how a JRuby application may be deployed on GlassFish. With this approach, there are two modes to deploy an application.

In the first case, Goldspike plug-in is installed in a standard Rails application. This plug-in adds the "war:*" rake targets to a Rails project. Invoking "war:standalone:create" rake target creates a WAR file containing all the dependent JRuby and Rails libraries. This WAR file can then be deployed in GlassFish. The "web.xml" in this WAR file contains a Servlet (org.jruby.webapp.RailsServlet) that translates data from Servlet request to Rails dispatcher.
In the second case, the Grizzly connector understands the request format and dispatch it directly to a pre-configured JRuby installation (updated with the Rails gem). In both the cases, there is only one JVM running as the OS process for GlassFish. The main advantage of the second approach is that it by-passes the web application processing and delegate the request directly to the Rails framework.

A detailed screencast of the first GlassFish case (Goldspike/JRuby) is available here and for the second case (Grizzly/JRuby) is documented here.

Technorati: ruby jruby jrubyonglassfish glassfish grizzly goldspike rubyonrails ror

Share and Enjoy:
  • Print
  • Digg
  • Sphinn
  • del.icio.us
  • Facebook
  • Google Bookmarks
  • DZone
  • email
  • StumbleUpon
  • Technorati
  • Twitter
  • Slashdot

August 19, 2007

TOTD #3: Using JavaDB with JRuby on Rails

Filed under: web2.0 — arungupta @ 11:00 pm

In a previous screencast, I showed how to develop a Rails application fetching data from the MySQL database and deploy it in GlassFish. GlassFish comes pre-bundled with JavaDB. Based upon a user request, this TOTD shows to use JavaDB database instead of MySQL.

Here are the steps required to replace MySQL database configuration with JavaDB. You can either mix these steps with the existing screencast or follow these steps altogether after the original app is created using MySQL.

  1. Copy "GLASSFISH_HOME/javadb/lib/derbyclient.jar" to "C:\Program Files\NetBeans 6.0M10\ruby1\jruby-1.0\lib" (or the directory location where JRuby for NetBeans 6 is installed). Make sure NetBeans IDE is restarted after the jar file is copied.
  2. In your application, change development database configuration in "database.yml" from:

    development:
      adapter: mysql
      database: glassfishrocks_development
      username: root
      password:
      host: localhost

    to

    development:
      adapter: jdbc
      driver: org.apache.derby.jdbc.ClientDriver
      url: jdbc:derby://localhost:1527/sample
      username: app
      password: app

    The NetBeans IDE comes pre-configured with the database URL, username and password used in this configuration.

  3. Start JavaDB using "asadmin start-database" command.
  4. Invoke db:migrate rake target to create the database required by the application. The development database configuration is used to create the database tables. If you followed the screencast, then a new table "greetings" is created in the database "sample".

  5. Change production database configuration in "database.yml" from:

    production:
      adapter: mysql
      database: glassfishrocks_production
      username: root
      password:
      host: localhost

    to

    production:
      adapter: jdbc
      driver: org.apache.derby.jdbc.ClientDriver
      url: jdbc:derby://localhost:1527/sample
      username: app
      password: app

    This new database configuration is exactly the same as for the development configuration. The production configuration is used by the WAR file.

  6. Insert value into the newly create database as "insert into GREETINGS values (1, 'Hello from JavaDB');".

  7. Create the WAR file using war:standalone:create rake target.
  8. Deploy the WAR file in the "GLASSFISH_HOME/domains/domain/autodeploy" directory.

You can also check out an early version of a tutorial that is being written about installing and configuring Ruby support in the NetBeans IDE. If you would like to get early access to Ruby documentation, learn more here.

Please leave suggestions on the TOTD that you’d like to see. A complete archive is available here.

Technorati: totd jrubyonglassfish jruby rubyonrails javadb glassfish ror ruby

Share and Enjoy:
  • Print
  • Digg
  • Sphinn
  • del.icio.us
  • Facebook
  • Google Bookmarks
  • DZone
  • email
  • StumbleUpon
  • Technorati
  • Twitter
  • Slashdot

August 17, 2007

Getting Started with Ruby-on-Rails, GlassFish and NetBeans

Filed under: web2.0 — arungupta @ 1:20 pm

Here are few pointers to get you started on Ruby-on-Rails in GlassFish and NetBeans:

Technorati: ruby jruby glassfish netbeans rubyonrails ror

Share and Enjoy:
  • Print
  • Digg
  • Sphinn
  • del.icio.us
  • Facebook
  • Google Bookmarks
  • DZone
  • email
  • StumbleUpon
  • Technorati
  • Twitter
  • Slashdot

TOTD #2: Change the endpoint address on a pre-generated Web services Stub

Filed under: webservices — arungupta @ 12:02 am

The client-side stubs generated by JAX-WS (part of Metro) are pre-configured with the endpoint address specified in the WSDL. This allows you to invoke the endpoint directly without any additional configuration. However there may be a need to send the exact same Web service request to an endpoint hosted at a different address. For example, the stubs may be generated from a WSDL hosted in the test environment and the request needs to be sent to an endpoint hosted in production environment that is very likely to be on a different machine.

This tip tells you how to change the endpoint address on a pre-generated stub so that it invokes a different endpoint.

The code to invoke a pre-configured stub (using the endpoint address from the WSDL) looks like:

Hello port = new HelloService().getHelloPort();
String result = port.sayHello("Duke!");

As per the JAX-WS 2.1 specification, each proxy implements javax.xml.ws.BindingProvider interface. In order to invoke an endpoint whose address is different from the one specified in the WSDL, you need to insert the following line between the two lines shown above:

((javax.xml.ws.BindingProvider)port).getRequestContext().put(javax.xml.ws.BindingProvider.ENDPOINT_ADDRESS_PROPERTY, "NEW_ADDRESS_HERE");

Just replace NEW_ADDRESS_HERE with your new endpoint address and the exact same request will be directed to the new endpoint. The WSDL contract must be exactly same though otherwise you may get an exception back.

Please leave suggestions on TOTD that you’d like to see. A complete archive is available here.

Technorati: totd webservices metro soap glassfish

Share and Enjoy:
  • Print
  • Digg
  • Sphinn
  • del.icio.us
  • Facebook
  • Google Bookmarks
  • DZone
  • email
  • StumbleUpon
  • Technorati
  • Twitter
  • Slashdot

August 16, 2007

Sun and Microsoft: Interoperability Now – New Article

Filed under: webservices — arungupta @ 4:37 pm

Sun and Microsoft: Interoperability Now is a new article released from Sun Inner Circle. This is a follow up to Sun Net Talk where Greg Papadopoulos and Harold Carr provided a detailed overview of Project Tango. This article provides an update on how the 10-year collaborative agreement between Sun and Microsoft is reaping benefits for the customers.

Read more about Project Tango (part of Metro) in this 26-page article.

Sun Inner Circle is a monthly newsletter for IT professions and is available in 18 versions worldwide. A complete archive of the previous articles is available heree.

Technorati: webservices innercircle metro glassfish interoperability sun microsoft

Share and Enjoy:
  • Print
  • Digg
  • Sphinn
  • del.icio.us
  • Facebook
  • Google Bookmarks
  • DZone
  • email
  • StumbleUpon
  • Technorati
  • Twitter
  • Slashdot

TOTD #1: SOAP Messaging Logging in Metro

Filed under: webservices — arungupta @ 11:17 am

I’m starting a new series today called Tip Of The Day. In this series I’ll respond to technical questions asked directly to me, on forums or other aliases. These questions might have been answered else where and this will be a summary of such tips in that case.

This tip tells how to monitor SOAP messages in Metro (the Web services stack in GlassFish). There are couple of ways to monitor SOAP messages:

  1. For client-side message logging, set system property com.sun.xml.ws.transport.http.client.HttpTransportPipe.dump=true. For server-side message logging, set system property com.sun.xml.ws.transport.http.HttpAdapter.dump=true.

  2. If you want more fine-grained logging, then consider using the logging properties defined here.

Another option is to use wsmonitor.

How do you monitor SOAP messages ?

Technorati: totd webservices metro soap glassfish

Share and Enjoy:
  • Print
  • Digg
  • Sphinn
  • del.icio.us
  • Facebook
  • Google Bookmarks
  • DZone
  • email
  • StumbleUpon
  • Technorati
  • Twitter
  • Slashdot

August 15, 2007

60th Birthday of India

Filed under: General — arungupta @ 12:18 pm

Happy Birthday India!

Also check out India Poised.

Share and Enjoy:
  • Print
  • Digg
  • Sphinn
  • del.icio.us
  • Facebook
  • Google Bookmarks
  • DZone
  • email
  • StumbleUpon
  • Technorati
  • Twitter
  • Slashdot

August 13, 2007

Sun’s “dramatically improved” app server

Filed under: webservices — arungupta @ 3:00 pm

Here are some quotes from a recent report by Forrester Wave on the "Application Server Platforms"

Among major vendors, Sun Microsystems Inc., has dramatically improved its standing in this year’s evaluation of applications servers for service-oriented architecture (SOA) and business process management (BPM) by Forrester Research Inc.

Sun trailed the field in Forrester’s 2004 evaluation of application server platforms but emerged as a "strong performer" in this year’s evaluation.

Sun’s platform grew substantially with its acquisition of SeeBeyond, and the company has spent about a year integrating those products with its Java Enterprise System (ES) modules. The SeeBeyond products, now called the Sun Java Composite Application Platform Suite (CAPS), provide very strong SOA, integration, and business process management (BPM) features relative to the competition.

The analyst firm rate Sun Web server and directory server on a par with what IBM and BEA offer in those categories.

The full report costs $379 but excerpts are available here.

If you want to download any of the above mentioned platforms, they are available at:

GlassFish V2 will be released final in the next few weeks. And the associated product, Sun Java System Application Server 9.1, will be released along with it as well.

Technorati: glassfish javacaps forrester

Share and Enjoy:
  • Print
  • Digg
  • Sphinn
  • del.icio.us
  • Facebook
  • Google Bookmarks
  • DZone
  • email
  • StumbleUpon
  • Technorati
  • Twitter
  • Slashdot

First JRuby on Rails App in GlassFish V3

Filed under: web2.0 — arungupta @ 12:02 am

In a previous screencast, I showed how a Rails application can be deployed as WAR file on GlassFish V2. In GlassFish V3, the Grizzly connector by-passes the need to bundle a Rails application as WAR. Instead it directly invokes JRuby interpreter and deploys a Rails application without any modification.

This blog entry describes the exact steps to deploy your first JRuby application in GlassFish V3 Technology Preview builds.

  1. Download, Install and Configure JRuby
    1. If you already have downloaded JRuby1.0, then skip this step. Otherwise download and install JRuby1.0 in a directory, say ‘c:\jruby-bin-1.0‘ (lets say JRUBY_HOME).
    2. Add "JRUBY_HOME\bin" in your environment PATH.
    3. If you have already configured Rails in your JRuby installation, then skip this step. Otherwise install Rails by giving the command:

      jruby -S gem install rails -y --no-rdoc

      "-S" switch instructs JRuby to run the command in it’s "bin" directory. The output of the command looks like:

      C:\jruby-bin-1.0>gem install rails -y --no-rdoc
      Bulk updating Gem source index for: http://gems.rubyforge.org
      Successfully installed rails-1.2.3
      Successfully installed activesupport-1.4.2
      Successfully installed activerecord-1.15.3
      Successfully installed actionpack-1.13.3
      Successfully installed actionmailer-1.3.3
      Successfully installed actionwebservice-1.2.3
      Installing ri documentation for activesupport-1.4.2...
      Installing ri documentation for activerecord-1.15.3...
      Installing ri documentation for actionpack-1.13.3...
      While generating documentation for actionpack-1.13.3
      ... MESSAGE: java.lang.ArrayIndexOutOfBoundsException: null
      ... RDOC args: --ri --op C://jruby-bin-1.0/lib/ruby/gems/1.8/doc/actionpack-1.13.3/ri --quiet lib
      (continuing with the rest of the installation)
      Installing ri documentation for actionmailer-1.3.3...
      Installing ri documentation for actionwebservice-1.2.3...
  2. Download, Install and Configure GlassFish V3
    1. Download GlassFish V3 Technology Preview 1, Build 2.
    2. Install by giving the command:
      java -jar glassfish-installer-v3-preview1-b2.jar

      This will create a new directory by the name "glassfish" in your current directory.

    3. Add "GLASSFISH_HOME\bin" in your environment PATH.
    4. Edit "config\asenv.bat" and add "set JRUBY_HOME=C:\jruby-bin-1.0" as the last line. Make sure to change the directory location to match your JRUBY_HOME.
  3. Create a Rails application
    1. Create a standard Rails application by giving the command:
      jruby -S rails hello

      This creates a new directory "hello" in your current directory. The output of the command looks like:

      create
      create app/controllers
      create app/helpers
      create app/models
      create app/views/layouts
      create config/environments
      create components
      create db
      create doc
      create lib
      create lib/tasks
      create log
      create public/images
      create public/javascripts
      create public/stylesheets
      create script/performance
      create script/process
      create test/fixtures
      create test/functional
      create test/integration
      create test/mocks/development
      create test/mocks/test
      create test/unit
      create vendor
      create vendor/plugins
      create tmp/sessions
      create tmp/sockets
      create tmp/cache
      create tmp/pids
      create Rakefile
      create README
      create app/controllers/application.rb
      create app/helpers/application_helper.rb
      create test/test_helper.rb
      create config/database.yml
      create config/routes.rb
      create public/.htaccess
      create config/boot.rb
      create config/environment.rb
      create config/environments/production.rb
      create config/environments/development.rb
      create config/environments/test.rb
      create script/about
      create script/breakpointer
      create script/console
      create script/destroy
      create script/generate
      create script/performance/benchmarker
      create script/performance/profiler
      create script/process/reaper
      create script/process/spawner
      create script/process/inspector
      create script/runner
      create script/server
      create script/plugin
      create public/dispatch.rb
      create public/dispatch.cgi
      create public/dispatch.fcgi
      create public/404.html
      create public/500.html
      create public/index.html
      create public/favicon.ico
      create public/robots.txt
      create public/images/rails.png
      create public/javascripts/prototype.js
      create public/javascripts/effects.js
      create public/javascripts/dragdrop.js
      create public/javascripts/controls.js
      create public/javascripts/application.js
      create doc/README_FOR_APP
      create log/server.log
      create log/production.log
      create log/development.log
      create log/test.log
      
    2. Add a controller to the application by changing to the directory "hello" and giving the command:
      jruby script/generate controller say hello

      The output of the command looks like:

      exists app/controllers/
      exists app/helpers/
      create app/views/say
      exists test/functional/
      create app/controllers/say_controller.rb
      create test/functional/say_controller_test.rb
      create app/helpers/say_helper.rb
      create app/views/say/hello.rhtml
    3. In hello\app\views\say directory, edit "hello.rhtml" such that it looks like:
      <h1>Say#hello</h1>
      <p>Find me in app/views/say/hello.rhtml</p>
      <%= @hello_string %>
    4. In hello\app\controllers directory, edit "say_controller.rb" such that it looks like:
      class SayController < ApplicationController
        def hello
          @hello_string = "Hello from Controller!"
        end
      end
  4. Run the application in GlassFish V3
    1. In GLASSFISH_HOME, start V3 container by giving the command:
      java -jar lib\glassfish-10.0-SNAPSHOT.jar

      The output of the command looks like:

      [#|2007-08-10T15:00:52.551-0700|INFO|GlassFish10.0|javax.enterprise.system.core|_ThreadID=10;_ThreadName=Thread-2;|Listening on port 8080|#]
      [#|2007-08-10T15:00:52.736-0700|INFO|GlassFish10.0|javax.enterprise.system.core|_ThreadID=10;_ThreadName=Thread-2;|Supported containers : phobos,web,jruby,php|#]
      [#|2007-08-10T15:00:52.753-0700|INFO|GlassFish10.0|javax.enterprise.system.core|_ThreadID=10;_ThreadName=Thread-2;|Glassfish v3 started in 802 ms|#]
    2. In the parent directory of "hello", deploy the application by giving the following command:
      asadmin deploy --path hello
    3. The output of the command looks like:

      C:\workarea\samples\gfv3>java -jar C:\testbed\v3-p1-v2\glassfish\bin\\..\lib\admin-cli-10.0-SNAPSHOT.jar
      deploy --path helloSUCCESS : Application hello deployed successfully

      The GlassFish console shows the following entry:

      [#|2007-08-10T15:01:53.833-0700|INFO|GlassFish10.0|GRIZZLY|_ThreadID=11;_ThreadName=httpWorkerThread-8080-0;|New Servicing page from: C:\workarea\samples\gfv3\hello\public|#]
      C:/testbed/v3-p1-v2/glassfish/lib/jruby/lib/ruby/gems/1.8/gems/actionmailer-1.3.3/lib/action_mailer.rb:49 warning: already initialized constant MAX_LINE_LEN
      [#|2007-08-10T15:02:15.740-0700|INFO|GlassFish10.0|javax.enterprise.system.tools.deployment|_ThreadID=11;_ThreadName=httpWorkerThread-8080-0;|hello jruby application loaded in 22083 ms|#]
    4. The application can now be accessed at "http://localhost:8080/hello/say/hello". The GlassFish console shows the following entry:
      /hello/say/hello
      [#|2007-08-10T15:03:22.222-0700|INFO|GlassFish10.0|GRIZZLY|_ThreadID=12;_ThreadName=httpWorkerThread-8080-1;|
      Processing SayController#hello (for 127.0.0.1 at 2007-08-10 15:03:22) [GET]
      |#]
      [#|2007-08-10T15:03:22.225-0700|INFO|GlassFish10.0|GRIZZLY|_ThreadID=12;_ThreadName=httpWorkerThread-8080-1;| Session ID: a78627d02071347f6fb5f0268fa47f18
      |#]
      [#|2007-08-10T15:03:22.227-0700|INFO|GlassFish10.0|GRIZZLY|_ThreadID=12;_ThreadName=httpWorkerThread-8080-1;| Parameters: {"action"=>"hello", "controller"=>"say"}
      |#]
      [#|2007-08-10T15:03:22.253-0700|INFO|GlassFish10.0|GRIZZLY|_ThreadID=12;_ThreadName=httpWorkerThread-8080-1;|Rendering say/hello
      |#]
      [#|2007-08-10T15:03:22.295-0700|INFO|GlassFish10.0|GRIZZLY|_ThreadID=12;_ThreadName=httpWorkerThread-8080-1;|Completed in 0.06500 (15 reqs/sec) | Rendering: 0.0 6300 (96%) | 200 OK [http://localhost/hello/say/hello]
      |#]

      The main point to notice here is that the Rails application request is served directly by the Grizzly connector.

This concludes all the steps required to run a simple JRuby on Rails application on GlassFish. If you want to run the same application using the WEBrick container, then follow the additional steps given below:

  1. In the directory "hello", start WEBrick by giving the command:

    jruby script/server

    The output of the command looks like:

    => Booting WEBrick...=> Rails application started on http://0.0.0.0:3000=> Ctrl-C to shutdown server; call with --help for options[2007-08-10 14:14:26] INFO WEBrick 1.3.1[2007-08-10 14:14:26] INFO ruby 1.8.5 (2007-06-07) [java][2007-08-10 14:14:26] INFO WEBrick::HTTPServer#start: pid=6336176 port=3000
  2. Open "http://localhost:3000/say/hello" in a browser window and it shows the message:

    Hello from Controller!

    The WEBrick console shows the following output:

    127.0.0.1 - - [10/Aug/2007:14:15:25 PDT] "GET /say/hello HTTP/1.1" 200 89- -> /say/hello127.0.0.1 - - [10/Aug/2007:14:15:27 PDT] "GET /favicon.ico HTTP/1.1" 200 0- -> /favicon.ico

In the process, I found Ruby on Rails Cheatsheet very handy for a quick summary of commands.

The NetBeans IDE provides a comprehensive support for Ruby code completion, refactoring, debugging, Rails support, support for RHTML files, code templates, unit test execution, shortcuts, and much more.

Technorati: jruby ruby glassfish grizzly jrubyonglassfish netbeans rubyonrails

Share and Enjoy:
  • Print
  • Digg
  • Sphinn
  • del.icio.us
  • Facebook
  • Google Bookmarks
  • DZone
  • email
  • StumbleUpon
  • Technorati
  • Twitter
  • Slashdot

August 12, 2007

Rancho PG&E Uphill Running

Filed under: Running — arungupta @ 9:18 am

Yesterday, I ran Rancho PG&E uphill starting from the first parking lot and I ran all the way up with just one short 15-secs break. At previous instances (here, here and here) I had to take multiple walk breaks and have been dreaming of running all the way uphill without any break. It seems like that dream is now coming close to a reality :)

It took me 47:24 for the uphill run (same as here, 2:14 slower than my PR on PG&E) but this run had an endurance goal instead of a time goal. I think couple of more tries and I’ll be able to accomplish this long dream of mine.

Do you know of any other similar uphill runs in the bay area ?

Technorati: running uphill

Share and Enjoy:
  • Print
  • Digg
  • Sphinn
  • del.icio.us
  • Facebook
  • Google Bookmarks
  • DZone
  • email
  • StumbleUpon
  • Technorati
  • Twitter
  • Slashdot
« Newer PostsOlder Posts »

The views expressed on this blog are my own and do not necessarily reflect the views of Oracle.
Powered by WordPress