Monday Dec 24, 2007

Santa's Goodie Bag for Developers

Merry Christmas!

And guess what, Santa has been delivering gifts through out December:
Have you not tried any of these ?

And of course, you can get nightly builds for each of these technologies :)

Technorati: glassfish netbeans jruby ruby metro grizzly jaxb jmaki

Monday Aug 20, 2007

Ruby/JRuby Process Models Explained

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

Sunday Aug 12, 2007

First JRuby on Rails App in GlassFish V3

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 hello
      SUCCESS : 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/hello
    127.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

Tuesday Mar 20, 2007

Day 2 at Ajax World

After spending the evening at Times Square yesterday, I rolled early in the bed to attend the morning keynote at 7:30am. And I had to run before that :) So I attended three sessions before the Expo Floor opened.

Like yesterday, the opening keynote, scheduled for 7:30am, started at 7:45am. I've a 10am flight tomorrow morning so with this consistent delayed start, I might have to miss the keynote tomorrow although I'd very much like to attend it.

Jeremy said even though folks have been using Ajax-like technologies for years but without Google Maps and GMail, we wouldn't be in this room, not so many and not so fired up. There were approximately 300 people for this 7:30am session. This is nothing compared to JavaOne keynote which typically has between 8000 to 12000 people in the keynote but the overall attendance of this conference itself is around 800. So in terms of percentage, it's still decent.

The opening keynote was by Bret Taylor who founded and led Google Maps. He showed 5 lines of code to integrate Google Maps in a website and another 8 lines of code to integrate Google Search. The point was that it is really easy to work with Ajax, especially as compared with SOAP/WSDL stack. Then he explained some of the techniques used behind Google Maps and GMail to solve some of the common problems of Ajax.

Per him, the main reason that triggered the explosive growth of Ajax is that most of the major browsers (IE, Firefox, Safari, Opera) agreed to deal with DOM, XHR, hash/anchor encoding and such similar techniques that enable Ajax in a consistent manner. He then explained how technology/browsers are evolving, on a daily basis, to make it a more pleasant experience.

The second session was "Inside the U.S. Air Force: How AJAX Is Improving Communications and Quality of Life" - a joint talk by Tony Tran & Peggy Rackstraw. Tony Tran, Vice President of Roundarch who build the employee portal for Air Force explained how Air Force is adopting Ajax/RIA. Tony showed samples, using before and after comparison of clicks and page refreshes, of how adding RIA to the Air Force portal increased productivity of the employees by making the website easier to use. After a good success in their first phase, they worked with Laszlo systems to solve their distributed email system (higher TCO, multiple email servers/domains, basic editing capabilities) and IM within the team and friends & families. Then Peggy from Laszlo Systems demoed "Deployed Life" which had initial problems with Firefox but then worked with IE. IM was cool because it allowed a drag-and-drop of pictures/videos from your local machine.

The third session was "Enterprise Ajax Using Java" by Greg Murray. The talk was about newly launched Sun Web Developer Pack and how jMaki provides an extensible framework to develop your Ajax applications. The talk was full of demos making it more real. I talk about SWDP and jMaki on my blog anyway, so won't dwell in details here. And now I'm sitting at Sun pod.

At Sun pod, we are showing jMaki Charting, Theming, Glue, Mashups along with other cool features, Grizzly Comet demo, Phobos CRUD generator, RESTful Web services API and lots of other stuff. All of these technologies are available in recently released Sun Web Developer Pack that can be run on top of GlassFish v2. Come by and talk to us.

   

Tonight is Ajax on Hudson and I'm looking forward to that.

Technorati: ajaxworld sun swdp glassfish grizzly comet jmaki web2.0

Monday Mar 19, 2007

Day 1 - Reporting from Ajax World

I arrived in New York City yesterday early morning to show Sun's offerings at Ajax World. The Roosevelt Hotel reservation desk was courteous to allow me a really early check in (7am). After spending day with family & friends yesterday, I attended the opening keynote by Douglas Crockford this morning. After 20 minutes of delay Jeremy Geelan of SYS-CON, chair of the show, opened it and highlighted that they are neither vendors nor developers and they are here to listen and share with the community. I think that was an interesting statement considering there are multiple players involved in the game.

Doug started with a show of hands asking questions about Ajax awareness and finally asked "Who knows what does Web 2.0 mean?". And there were around approx 10 hands showed up. This term "Web 2.0" is fuzzy and any attempt to version the world wide web seems irrational. At Sun, we refer to this fuzzy term as "Next Generation Web Application" that allow to develop Rich Internet Applications. But you'll see Sun using "Web 2.0" sometimes because of a general adoption of this term.

Sun Web Developer Pack is one such toolkit that provides binaries, tutorial, documentation, samples (including source) to build your next generation Web applications and deploy them on industry-grade containers such as GlassFish and Sun Java System Web Server and others.

Most of Doug's slides were saying just few words and then he was talking through them. He introduced Ajax, it's history, different attempts at Rich Internet Application development, JavaScript, security in Ajax applications, Ajax in mobile applications, and competition (Adobe's Apollo and Microsoft's WPF).

Even though the keynote started late, but it finished slightly before time allowing me to attend Real World Web 2.0 Comet-based Applications by Jean Francois. There he gave an overview of the problem solved by Comet, different approaches of Comet, Grizzly Comet in GlassFish, and how to write a Comet application using GlassFish. In summary, Grizzly Comet solves reduce the latency and load on server but there is no standard way to for Comet-based applications so there is no interoperability between implementations. Please stop by at Sun's booth if you are interested in seeing a demo or talk more about Sun's offerings in this space.

A complete glimpse of schedule is available here and Sun sessions are listed here.

As a side note, I find it weird that there is no free internet connectivity at Ajax World. Isn't the conference about sharing, community and connectivity ?

Technorati: ajaxworld sun swdp glassfish grizzly comet

Tuesday Feb 27, 2007

jMaki, Phobos, Grizzly, and Toplink Essentials Aggregator

I built some more aggregators (mashing up feeds from Bloglines, Findory, Google Blog Search, Technorati, IceRocket) and here is the complete list:

Aggregator Search Term
Sun WSIT Bloggers All Sun WSIT Bloggers
GlassFish in Blogosphere glassfish
jMaki Aggregator jmaki
Phobos Aggregator phobos + scripting
Grizzly Aggregator grizzly + glassfish
Toplink Essentials Aggregator toplink + essentials

UPDATE: Found this great Yahoo! Pipes video tutorials.

Technorati: WSIT GlassFish YahooPipes Blogs jMaki Phobos Grizzly Toplink Essentials

About

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

Search

Archives
« July 2014
SunMonTueWedThuFriSat
  
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
  
       
Today