1. Using JRuby on Rails With Sun GlassFish Enterprise Server
Introduction to JRuby and Rails on Sun GlassFish Enterprise Server
JRuby on Rails, the Sun GlassFish Enterprise Server v3, and the GlassFish v3 Gem
Installation and Configuration of JRuby
To Install JRuby and Rails from Update Center
To Install JRuby as Standalone
Enterprise Server v3 JRuby Container Configuration
Configuring JRuby Container Through Asadmin CLI
Configuring JRuby Runtime Pool
Creating a Simple Rails Application
To Create the hello Application
To Create the Controller and the View
To Pass Data From the Controller to the View
To Use Rails Without a Database
Deploying and Running a Rails Application
To Deploy the Rails Application as a Directory
Accessing a Database From a Rails Application
To Set Up the MySQL Database Server
To Create a Database-Backed Rails Application
Accessing Java Libraries From a Rails Application
To Create the Rails Application That Accesses Java Libraries
To Create the Views That Display the Images Generated by Java2D Code
To Add Java2D Code to a Rails Controller
To Run a Rails Application That Uses Java 2D Code
Monitor Rails Applications on Enterprise Server v3
Monitoring for JRuby Container
Viewing JRuby Container Statistics
To Install the GlassFish v3 Gem
To Run a Rails Application on GlassFish v3 Gem
To Deploy and Run the Database-Backed Web Application
Creating and Deploying a Simple Rails Application with Warbler
The Sun GlassFish Enterprise Server v3 provides the following ways to configure the installed JRuby container.
Asadmin CLI
Administration Console
The asadmin CLI now provides options to configure the JRuby container. The command execution is reflected in changes to the JRuby container configuration section of the domain.xml file which makes them persistent.
The following JRuby container properties can be configured through the asdmin command.
configure-jruby-container [--help] [--monitoring={false|true}] [--jruby-home jruby-home] [--jruby-runtime jruby-runtime] [--jruby-runtime-min jruby-runtime-min] [--jruby-runtime-max jruby-runtime-max] [--show={true|false}]
Use the following asadmin command syntax to configure these values:
asadmin configure-jruby-container --<property>=<value>
For example, the following command is used to set the JRuby home if JRuby instance is installed as standalone:
asadmin configure-jruby-container --jruby.home=/<jruby-install-location>
You can also change the deployment specific options to the JRuby application through the following command syntax:
asadmin deploy --property <name>=<value>[:<name>=<value>]
For example, the following command uses a JRuby instance to deploy your application which is different from the one configured with the Enterprise Server:
asadmin deploy --property jruby.home=/<latest-jruby-install> <application>
For a detailed description of these options, see configure-jruby-container(1).
The JRuby container runtime pool options are discussed in the next section.
The Sun GlassFish Enterprise Server v3 provides a JRuby runtime pool to allow servicing of multiple concurrent requests. However Rails is not currently thread-safe, and while JRuby is able to take advantage of Java's native threading, Rails cannot benefit from it. Each JRuby runtime runs a single instance of Rails, and requests are handed off to whichever instance happens to be available at the time of the request.
The JRuby properties in the above configuration are explained as follows:
jruby.runtime property sets the initial number of JRuby runtimes that Enterprise Server starts with. The default value is one. This represents the highest value that GlassFish Server accepts as minimum runtimes, and the lowest value that GlassFish can use as maximum runtimes.
jruby.runtime.min property sets the minimum number of JRuby runtimes that will be available in the pool. The default value is one. The pool will always be at least this large, but can be larger than this.
jruby.runtime.max property sets the maximum number of JRuby runtimes that might be available in the pool. The default value is two. Setting Too high values for this property might result in OutOfMemory errors, either in the heap or in the PermGen.
The dynamic runtime pool maintains itself with the minimum number of runtimes possible, to allow consistent and fast runtime access for the requesting application. The pool may take a initial runtime value, but that value is not used after pool creation.
The JRuby runtime pool values can be set either at container level or at deploy time. To set the runtime pool values at container level, use the following asadmin command:
asadmin configure-jruby-container --jruby-runtime=2 --jruby-runtime-min=1 --jruby-runtime-max=3
Note that each of the above properties can be set separately at a time. To set the runtime pool values at deploy time use the following asadmin command:
asadmin deploy --property jruby-runtime=2:jruby-runtime-min=1:jruby-runtime-max=3
Each of the above properties also can be set at a time or at the same time. If both settings are used, deploy time settings take precedence over container runtime settings.
The JRuby container values can be set from Enterprise Server Administration Console. For
details on Administration Console, see Administration Console in Sun GlassFish Enterprise Server v3 Administration Guide.
You can set the following container properties from the Administration Console:
JRuby Home
Initial Pool Size
Minimum Pool Size
Maximum Pool Size
Use the following steps to access JRuby Container from Administration Console.
Access the Enterprise Server Administration Console from web browser. For example:
http://localhost:4848
Login to the Administration Consoleif configured for secure login.
Select Common Tasks->Configuration->JRuby Container on the left-hand tree panel.
Change JRuby Container values from the details panel.