Firstly, let me state that I am not sure whether these are all glassfish gem issues or whether some pertain to upstream
glassfish issues. I'm not yet certain where one ends and the other begins! :-)
Having said that, here is what I had to do in order to get the glassfish gem working with a rails 3 beta installation
as a Rails application rather than a Rack application and working with concurrent requests:
1. Allow glassfish to detect that the application is a Rails application by adding the following tag to boot.rb:
# RAILS_ROOT #
(Probable upstream glassfish issue.)
2. Add glassfish gem to #{RAILS_ROOT}/Gemfile so that the jruby/rails_path.rb file is required. eg.
gem "glassfish", "1.0.3.dev"
3. Modify the jruby/rails_path.rb to work within Rails 3:
diff -r glassfish-1.0.3.dev-universal-java.orig/lib/jruby/rails_path.rb
glassfish-1.0.3.dev-universal-java/lib/jruby/rails_path.rb
1,6c1,22
< module Rails
< class Configuration
< def threadsafe?
< if(Rails::Configuration.instance_methods.include?'threadsafe!')
< if(Rails::Configuration.instance_methods.include?'preload_frameworks')
< preload_frameworks && cache_classes && !dependency_loading &&
action_controller.allow_concurrency
---
> if Module === Rails::Configuration
> # Rails 3
> module Rails
> class Application
> class Configuration
> def threadsafe?
> allow_concurrency
> end
> end
> end
> end
> else
> # Rails 2
> module Rails
> class Configuration
> def threadsafe?
> if(Rails::Configuration.instance_methods.include?'threadsafe!')
> if(Rails::Configuration.instance_methods.include?'preload_frameworks')
> preload_frameworks && cache_classes && !dependency_loading &&
action_controller.allow_concurrency
> else
> cache_classes && !dependency_loading && action_controller.allow_concurrency
> end
8c24
< cache_classes && !dependency_loading && action_controller.allow_concurrency
---
> false
10,11d25
< else
< false
4. Modify the rack/adapter/rails.rb file to operate with Rails 3:
diff -r glassfish-1.0.3.dev-universal-java.orig/lib/rack/adapter/rails.rb
glassfish-1.0.3.dev-universal-java/lib/rack/adapter/rails.rb
77,81c77,83
< @rails_app = if rack_based?
< ActionController::Dispatcher.new
< else
< CgiApp.new
< end
---
> @rails_app = if rails3?
> ::Rails.application
> elsif rack_based?
> ActionController::Dispatcher.new
> else
> CgiApp.new
> end
86a89,92
> def rails3?
> ::Rails.application.respond_to?(:call) rescue false
> end
>
99,101c105,108
< require 'dispatcher'
<
< setup_logger
---
> if !rails3?
> require 'dispatcher'
> end
> setup_logger
248,249c255,258
< class << ::RAILS_DEFAULT_LOGGER # Make these accessible to wire in the log device
< public :instance_variable_get, :instance_variable_set
---
> if !rails3?
> class << ::RAILS_DEFAULT_LOGGER # Make these accessible to wire in the log device
> public :instance_variable_get, :instance_variable_set
> end
Even though the Rails application did initially function as a Rack application, concurrent requests were not possible
with config.threadsafe! enabled in production mode and, to me, this is really a fundamental reason to use JRuby and
Glassfish to run a rails app!
Even with these modifications it is still not possible for the glassfish gem to host a rails application in daemonized
mode - it seems to spin up using JRubyRuntime rather than using the RackApplicationPoolFactory. I'm uncertain as to
why but perhaps, again, this is an upstream Glassfish issue as I seem to get a similar effect when using the full app
server.
Compare the following:
Daemonized:
INFO: Running testapp in production environment.
19-Feb-2010 13:26:48 org.glassfish.scripting.jruby.RackApplicationChooser detectRails
INFO: Rails application detected.
19-Feb-2010 13:26:48 org.glassfish.scripting.jruby.JRubyApplication <init>
INFO: Loading application alice at /
19-Feb-2010 13:26:48 com.sun.grizzly.jruby.RackGrizzlyAdapter <init>
INFO: JRuby version is: 1.4.0
19-Feb-2010 13:26:49 com.sun.grizzly.jruby.rack.JRubyRuntime <init>
INFO: New instance of JRuby runtime created in 88 milliseconds
(Requests always return the "please wait while your application is being started" page.)
Non-daemonized:
INFO: Running testapp in production environment.
19-Feb-2010 13:28:39 org.glassfish.scripting.jruby.RackApplicationChooser detectRails
INFO: Rails application detected.
19-Feb-2010 13:28:39 org.glassfish.scripting.jruby.JRubyApplication <init>
INFO: Loading application alice at /
19-Feb-2010 13:28:39 com.sun.grizzly.jruby.RackGrizzlyAdapter <init>
INFO: JRuby version is: 1.4.0
19-Feb-2010 13:28:45 com.sun.grizzly.jruby.rack.RackApplicationPoolFactory newApplication
INFO: New instance of rails created in 6,020 milliseconds
(Requests function as expected.)
Apologies if I've ended up filing bugs that are mainly related to upstream Glassfish issues - however, you are more
likely to have a good understanding of which issues are where than I! :-) |