Managing (start/stop) a JRuby application from a Servlet

View: New views
6 Messages — Rating Filter:   Alert me  

Managing (start/stop) a JRuby application from a Servlet

by ben.christenson :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

After playing around with JRuby Embed and RAWR (and my ruby application require statements), I still don't have a good solution for managing a process written in Ruby from a Java Servlet.  For some background, we are developing a "next generation" suite of tools for our products (Java based) in Ruby and working to deploy them as part of our existing applications.  One of these is a simple poller written in Ruby that we would like to be able to manage from our existing web management console.

Currently, we are doing this via a RAWRed executable jar file that is triggered to execute on initialization of a loader Servlet.  This works fine, but prevents us from passing information back and forth (such as the desire to cleanly halt after the current poll process).  I dug into JRuby Embed a bit (the interface examples specifically) and came up with a small manager/worker thread example that seemed to work pretty well.  However when I went to implement the worker thread to load up my rawred library, I found myself in a load path spiderweb that I was unable to untangle.  Specifically, the _FILE_ constant in my loader file was not evaluating properly in precompiled files.

Does JRuby Embed support precompiled Jruby?  IE can I jrubyc my ruby application and then have a single uncompiled ruby manager class that is loaded via JRuby Embed?

Am I missing something easy on how to implement starting and stopping of a ruby polling process from a Java Servlet?

Thanks,
Ben Christenson
Developer/Analyst

Kinetic Data, Inc.

"Building a Better Service Experience"


651.556.0937
  I  www.kineticdata.com


Re: Managing (start/stop) a JRuby application from a Servlet

by Charles Oliver Nutter-4 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Can you describe what you need to accomplish in the other "process" in
a little more detail? I'm not sure if there's a perfect solution, but
maybe we can work together to come up with something that fits your
needs...

2009/9/9 Benjamin Christenson <ben.christenson@...>:

> After playing around with JRuby Embed and RAWR (and my ruby application require statements), I still don't have a good solution for managing a process written in Ruby from a Java Servlet.  For some background, we are developing a "next generation" suite of tools for our products (Java based) in Ruby and working to deploy them as part of our existing applications.  One of these is a simple poller written in Ruby that we would like to be able to manage from our existing web management console.
>
> Currently, we are doing this via a RAWRed executable jar file that is triggered to execute on initialization of a loader Servlet.  This works fine, but prevents us from passing information back and forth (such as the desire to cleanly halt after the current poll process).  I dug into JRuby Embed a bit (the interface examples specifically) and came up with a small manager/worker thread example that seemed to work pretty well.  However when I went to implement the worker thread to load up my rawred library, I found myself in a load path spiderweb that I was unable to untangle.  Specifically, the _FILE_ constant in my loader file was not evaluating properly in precompiled files.
>
> Does JRuby Embed support precompiled Jruby?  IE can I jrubyc my ruby application and then have a single uncompiled ruby manager class that is loaded via JRuby Embed?
>
> Am I missing something easy on how to implement starting and stopping of a ruby polling process from a Java Servlet?
>
> Thanks,
> Ben Christenson
> Developer/Analyst
>
> Kinetic Data, Inc.
> "Building a Better Service Experience"
>
> 651.556.0937  I  www.kineticdata.com
>

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email



Re: Managing (start/stop) a JRuby application from a Servlet

by ben.christenson :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Sure.  We have a simple ruby DSL built up that represents a tree of dependent actions.  Each action is built up of an xml description and a ruby class that gets called when it is its turn to execute.  Managing this process is a simple driver program that loads up the application:

FILE: kinetic_task.rb (this is our loader script)
  # Require ruby standard libraries
  require 'erb'
  require 'rexml/document'
  ...
  # Require gems
  require 'uuidtools'
  require 'xmlsimple'
  ...
  # Require the DSL files (either ruby source or precompiled)
  Dir[File.join(File.dirname(__FILE__), 'dsl', '**', '*.{rb,class}')].each do |lib|
    require File.expand_path(lib.chomp('.class'))
  end

FILE: driver.rb
  # Require our application
  require 'kinetic_task'
  # Process the configuration
  ...
  # Start the polling process
  engine = DSL::Engine.new(:config => {...})
  engine.start

The start method queries the database for records indicating an action is ready and then executes them (once by default, or loops continually sleeping for x seconds if configured to run as a continual process).

Currently, we have our entire application packaged with RAWR and just pass in a configuration item so that the engine loops infinitely.  What we would like to do is be able to call Engine.start or Engine.stop from a Servlet so that we can control the process from our web interface (and allow for safe termination of the polling process).  I think we can do this if we package the plaintext ruby files into our web application, but we want to be able to deploy this package as a jar file.

I was able to successfully write a manager ruby class that supported start/stop control of a worker thread (that just did a puts statement and slept for x seconds) and then manage the starting/stoping from a Servlet.  However, when I attempted to replace the puts with actual code (requiring our application from the RAWRed jar file) _FILE_ was returning odd results in the loader script.  Is it possible that I need to play with loading a bit more or was I doing something wrong there?  How stable is the patched JRuby 1.4.0 that JRuby Embed uses?

Thanks,
Ben Christenson
Developer/Analyst

Kinetic Data, Inc.

"Building a Better Service Experience"


651.556.0937
  I  www.kineticdata.com


On Fri, Sep 11, 2009 at 12:48 PM, Charles Oliver Nutter <headius@...> wrote:
Can you describe what you need to accomplish in the other "process" in
a little more detail? I'm not sure if there's a perfect solution, but
maybe we can work together to come up with something that fits your
needs...

2009/9/9 Benjamin Christenson <ben.christenson@...>:
> After playing around with JRuby Embed and RAWR (and my ruby application require statements), I still don't have a good solution for managing a process written in Ruby from a Java Servlet.  For some background, we are developing a "next generation" suite of tools for our products (Java based) in Ruby and working to deploy them as part of our existing applications.  One of these is a simple poller written in Ruby that we would like to be able to manage from our existing web management console.
>
> Currently, we are doing this via a RAWRed executable jar file that is triggered to execute on initialization of a loader Servlet.  This works fine, but prevents us from passing information back and forth (such as the desire to cleanly halt after the current poll process).  I dug into JRuby Embed a bit (the interface examples specifically) and came up with a small manager/worker thread example that seemed to work pretty well.  However when I went to implement the worker thread to load up my rawred library, I found myself in a load path spiderweb that I was unable to untangle.  Specifically, the _FILE_ constant in my loader file was not evaluating properly in precompiled files.
>
> Does JRuby Embed support precompiled Jruby?  IE can I jrubyc my ruby application and then have a single uncompiled ruby manager class that is loaded via JRuby Embed?
>
> Am I missing something easy on how to implement starting and stopping of a ruby polling process from a Java Servlet?
>
> Thanks,
> Ben Christenson
> Developer/Analyst
>
> Kinetic Data, Inc.
> "Building a Better Service Experience"
>
> 651.556.0937  I  www.kineticdata.com
>

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

   http://xircles.codehaus.org/manage_email




Re: Managing (start/stop) a JRuby application from a Servlet

by ben.christenson :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hey guys,

Well with the release of 1.4 and some embedded code hacking I have pretty much resolved the problem.  A few niceties came up during the process that I am interested in feedback on.

First, we have quite a few jar files (and a jar file for gems leveraging the gems-in-a-jar strategy).  Right now Jruby does not support loading scripts from jars within other jars (http://jira.codehaus.org/browse/JRUBY-3299).  Is there a plan to address this?

Also, for embedded Jruby, it looks like __FILE__ does not work when executing scripts from the classpath.  It just returns the base file name (without the location within the jar file it is in).  I think I saw a thread about this already on the list, but I wanted to verify that this is unexpected behavior.  If so, are there any known workarounds?  We got around it by finding the file using the java classloader and then modifying our init scripts to append the jar file manually.


Lastly, there are a few idiosyncrasies that I don't quite understand:

It is possible to check if a jar file contains a specified file, but it doesn't look like it is possible to check if a jar file contains a directory (see below).  Is that expected behavior?
  File.exist?("file:/C:/my.jar!/directory/file.txt") # true
  File.exist?("file:/C:/my.jar!/directory") # false

Also, Dir.glob with wildcards does not seem to work within jar files (see below).  Is that expected behavior?
  Dir["file:/C:/my.jar!/*"] # []

Thanks,
Ben Christenson
Developer/Analyst

Kinetic Data, Inc.

"Building a Better Service Experience"


651.556.0937
  I  www.kineticdata.com


On Fri, Sep 11, 2009 at 12:21 PM, Benjamin Christenson <ben.christenson@...> wrote:
Sure.  We have a simple ruby DSL built up that represents a tree of dependent actions.  Each action is built up of an xml description and a ruby class that gets called when it is its turn to execute.  Managing this process is a simple driver program that loads up the application:

FILE: kinetic_task.rb (this is our loader script)
  # Require ruby standard libraries
  require 'erb'
  require 'rexml/document'
  ...
  # Require gems
  require 'uuidtools'
  require 'xmlsimple'
  ...
  # Require the DSL files (either ruby source or precompiled)
  Dir[File.join(File.dirname(__FILE__), 'dsl', '**', '*.{rb,class}')].each do |lib|
    require File.expand_path(lib.chomp('.class'))
  end

FILE: driver.rb
  # Require our application
  require 'kinetic_task'
  # Process the configuration
  ...
  # Start the polling process
  engine = DSL::Engine.new(:config => {...})
  engine.start

The start method queries the database for records indicating an action is ready and then executes them (once by default, or loops continually sleeping for x seconds if configured to run as a continual process).

Currently, we have our entire application packaged with RAWR and just pass in a configuration item so that the engine loops infinitely.  What we would like to do is be able to call Engine.start or Engine.stop from a Servlet so that we can control the process from our web interface (and allow for safe termination of the polling process).  I think we can do this if we package the plaintext ruby files into our web application, but we want to be able to deploy this package as a jar file.

I was able to successfully write a manager ruby class that supported start/stop control of a worker thread (that just did a puts statement and slept for x seconds) and then manage the starting/stoping from a Servlet.  However, when I attempted to replace the puts with actual code (requiring our application from the RAWRed jar file) _FILE_ was returning odd results in the loader script.  Is it possible that I need to play with loading a bit more or was I doing something wrong there?  How stable is the patched JRuby 1.4.0 that JRuby Embed uses?


Thanks,
Ben Christenson
Developer/Analyst

Kinetic Data, Inc.

"Building a Better Service Experience"


651.556.0937
  I  www.kineticdata.com


On Fri, Sep 11, 2009 at 12:48 PM, Charles Oliver Nutter <headius@...> wrote:
Can you describe what you need to accomplish in the other "process" in
a little more detail? I'm not sure if there's a perfect solution, but
maybe we can work together to come up with something that fits your
needs...

2009/9/9 Benjamin Christenson <ben.christenson@...>:
> After playing around with JRuby Embed and RAWR (and my ruby application require statements), I still don't have a good solution for managing a process written in Ruby from a Java Servlet.  For some background, we are developing a "next generation" suite of tools for our products (Java based) in Ruby and working to deploy them as part of our existing applications.  One of these is a simple poller written in Ruby that we would like to be able to manage from our existing web management console.
>
> Currently, we are doing this via a RAWRed executable jar file that is triggered to execute on initialization of a loader Servlet.  This works fine, but prevents us from passing information back and forth (such as the desire to cleanly halt after the current poll process).  I dug into JRuby Embed a bit (the interface examples specifically) and came up with a small manager/worker thread example that seemed to work pretty well.  However when I went to implement the worker thread to load up my rawred library, I found myself in a load path spiderweb that I was unable to untangle.  Specifically, the _FILE_ constant in my loader file was not evaluating properly in precompiled files.
>
> Does JRuby Embed support precompiled Jruby?  IE can I jrubyc my ruby application and then have a single uncompiled ruby manager class that is loaded via JRuby Embed?
>
> Am I missing something easy on how to implement starting and stopping of a ruby polling process from a Java Servlet?
>
> Thanks,
> Ben Christenson
> Developer/Analyst
>
> Kinetic Data, Inc.
> "Building a Better Service Experience"
>
> 651.556.0937  I  www.kineticdata.com
>

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

   http://xircles.codehaus.org/manage_email





Re: Managing (start/stop) a JRuby application from a Servlet

by Nick Sieger-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

On Thu, Nov 5, 2009 at 5:16 PM, Benjamin Christenson
<ben.christenson@...> wrote:

> Hey guys,
>
> Well with the release of 1.4 and some embedded code hacking I have pretty
> much resolved the problem.  A few niceties came up during the process that I
> am interested in feedback on.
>
> First, we have quite a few jar files (and a jar file for gems leveraging the
> gems-in-a-jar strategy).  Right now Jruby does not support loading scripts
> from jars within other jars (http://jira.codehaus.org/browse/JRUBY-3299).
> Is there a plan to address this?
>
> Also, for embedded Jruby, it looks like __FILE__ does not work when
> executing scripts from the classpath.  It just returns the base file name
> (without the location within the jar file it is in).  I think I saw a thread
> about this already on the list, but I wanted to verify that this is
> unexpected behavior.  If so, are there any known workarounds?  We got around
> it by finding the file using the java classloader and then modifying our
> init scripts to append the jar file manually.
>
>
> Lastly, there are a few idiosyncrasies that I don't quite understand:
>
> It is possible to check if a jar file contains a specified file, but it
> doesn't look like it is possible to check if a jar file contains a directory
> (see below).  Is that expected behavior?
>   File.exist?("file:/C:/my.jar!/directory/file.txt") # true
>   File.exist?("file:/C:/my.jar!/directory") # false
>
> Also, Dir.glob with wildcards does not seem to work within jar files (see
> below).  Is that expected behavior?
>   Dir["file:/C:/my.jar!/*"] # []

Make sure you build your jar files with directory entries; otherwise
neither of the above will work (File.exist? or File.directory? or Dir
glob in jars).

/Nick

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email



Re: Managing (start/stop) a JRuby application from a Servlet

by ben.christenson :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Spectacular Nick.  That is exactly what was occurring.  I got tripped up by inspecting the jar with a GUI tool instead of 'jar -tf'.

Thanks,
Ben Christenson
Developer/Analyst

Kinetic Data, Inc.

"Building a Better Service Experience"


651.556.0937
  I  www.kineticdata.com


On Thu, Nov 5, 2009 at 9:14 PM, Nick Sieger <nicksieger@...> wrote:
On Thu, Nov 5, 2009 at 5:16 PM, Benjamin Christenson
> Hey guys,
>
> Well with the release of 1.4 and some embedded code hacking I have pretty
> much resolved the problem.  A few niceties came up during the process that I
> am interested in feedback on.
>
> First, we have quite a few jar files (and a jar file for gems leveraging the
> gems-in-a-jar strategy).  Right now Jruby does not support loading scripts
> from jars within other jars (http://jira.codehaus.org/browse/JRUBY-3299).
> Is there a plan to address this?
>
> Also, for embedded Jruby, it looks like __FILE__ does not work when
> executing scripts from the classpath.  It just returns the base file name
> (without the location within the jar file it is in).  I think I saw a thread
> about this already on the list, but I wanted to verify that this is
> unexpected behavior.  If so, are there any known workarounds?  We got around
> it by finding the file using the java classloader and then modifying our
> init scripts to append the jar file manually.
>
>
> Lastly, there are a few idiosyncrasies that I don't quite understand:
>
> It is possible to check if a jar file contains a specified file, but it
> doesn't look like it is possible to check if a jar file contains a directory
> (see below).  Is that expected behavior?
>   File.exist?("file:/C:/my.jar!/directory/file.txt") # true
>   File.exist?("file:/C:/my.jar!/directory") # false
>
> Also, Dir.glob with wildcards does not seem to work within jar files (see
> below).  Is that expected behavior?
>   Dir["file:/C:/my.jar!/*"] # []

Make sure you build your jar files with directory entries; otherwise
neither of the above will work (File.exist? or File.directory? or Dir
glob in jars).

/Nick

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

   http://xircles.codehaus.org/manage_email