(jruby 1.5) Issue/Question with embed (RedBridge), and "refreshing" code

Hello -

I have been working on converting an existing RoR app into a glassfish
environment, using jruby, etc.

One of the things that I am trying to get working, is a way to have a
couple of extra processes running (basically the equivalent of the
activemessaging pollers) - that were originally called via ‘ruby
/path/to/poller/script’. This is basically loading an external JMS
listener that needs to interact with the core rails app - but needs to
be run separately (there are multiple ones that need to be run).

I have this setup now as an MDB that takes a message on whether to start
the process or not, using the embedded API (jruby 1.5) to get this
running. There are cases where we need multiple listeners of the same
object running.

What this does now is:

  • Takes the path to the external script
  • Creates a new ScriptingContainer
  • Runs the scriptlet to the main script, getting the class
  • Takes the container and creates an instance of the object
    (callMethod(“new”))
  • Takes the object instance and calls the “run” method on it to start
    the listener we need
  • Store this saved instance of an object so I can have access to it -
    as well as be able to start new instances and run them

This is enabling me to start multiple listeners if needed, and to stop
them if needed (callMethod(“stop”) on the object, which kills the
session and connection to the listener). I need to be able to tell my
environment as well to completely get rid of the instance in memory.

But - there are some major issues I am having that I cannot seem to get
past:

  • If I update the external script, I need to be able to “refresh” it -
    so I attempt to stop all the existing objects that were created, and
    call terminate() on the container, then attempt to reload the original
    location. This is causing major memory and state issues, and doesn’t
    seem to do what is needed.

I need to be able to change a value or something in the calling script,
and be able to reload this into my environment - basically killing off
all the existing versions of it if possible. I thought terminate might
help here - but I get to a point doing this where my system become
unusable - CPU usage and memory go haywire.

One thing here - the external scripts that are being loaded also load in
the rails environment - I wish they wouldn’t “reload” this whole
environment, and can just utilize the one that the scripts are coming
from - but it sure seems to do so.

Does anyone have any ideas on how I can accomplish this in a better
manner?

Thanks for your time.


Robert B. Weeks
[email protected]

To unsubscribe from this list, please visit:

http://xircles.codehaus.org/manage_email

Hi Robert,

On Mon, May 3, 2010 at 11:07 AM, Robert W. [email protected]
wrote:

But - there are some major issues I am having that I cannot seem to get past:

  • If I update the external script, I need to be able to “refresh” it - so I attempt to stop all the existing objects that were created, and call terminate() on the container, then attempt to reload the original location. This is causing major memory and state issues, and doesn’t seem to do what is needed.

Would you try System.gc() after ScriptingContainer’s terminate()
method? This kind of stuffs are held in ThreadContext, and terminate()
method tries to clear them up from ThreadContext. However, those are
in SoftReference, actually, in WeafReference of SoftReference as for
Sun’s JDK. So those might not be cleared unless GC works. Slight
difference among JDKs are there since that part is written in C and
depends on how the JDK implements Soft/WeakReference.

One thing here - the external scripts that are being loaded also load in the rails environment - I wish they wouldn’t “reload” this whole environment, and can just utilize the one that the scripts are coming from - but it sure seems to do so.

Are you using singleton type for ScriptingContainer’s context? Then, a
single Ruby runtime exists on a single JVM, and you don’t need to
re-evaluate the same script. Ruby runtime remembers it.

-Yoko

http://xircles.codehaus.org/manage_email


To unsubscribe from this list, please visit:

http://xircles.codehaus.org/manage_email