Created
July 13, 2011 22:12
-
-
Save anonymous/1081455 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/src/org/jruby/management/Runtime.java b/src/org/jruby/management/Runtime.java | |
index e013b43..9014e3f 100644 | |
--- a/src/org/jruby/management/Runtime.java | |
+++ b/src/org/jruby/management/Runtime.java | |
@@ -31,6 +31,7 @@ package org.jruby.management; | |
import java.lang.ref.SoftReference; | |
import org.jruby.Ruby; | |
+import org.jruby.runtime.builtin.IRubyObject; | |
public class Runtime implements RuntimeMBean { | |
private final SoftReference<Ruby> ruby; | |
@@ -50,4 +51,23 @@ public class Runtime implements RuntimeMBean { | |
public int getCallerCount() { | |
return ruby.get().getCallerCount(); | |
} | |
+ | |
+ public String executeRuby(final String code) { | |
+ final IRubyObject[] result = new IRubyObject[1]; | |
+ | |
+ Thread t = new Thread() { | |
+ @Override | |
+ public void run() { | |
+ result[0] = ruby.get().evalScriptlet(code); | |
+ } | |
+ }; | |
+ t.start(); | |
+ try { | |
+ t.join(); | |
+ } catch (InterruptedException ie) { | |
+ throw new RuntimeException(ie); | |
+ } | |
+ | |
+ return result[0].toString(); | |
+ } | |
} | |
diff --git a/src/org/jruby/management/RuntimeMBean.java b/src/org/jruby/management/RuntimeMBean.java | |
index 78d3692..796476f 100644 | |
--- a/src/org/jruby/management/RuntimeMBean.java | |
+++ b/src/org/jruby/management/RuntimeMBean.java | |
@@ -32,4 +32,5 @@ public interface RuntimeMBean { | |
public int getExceptionCount(); | |
public int getBacktraceCount(); | |
public int getCallerCount(); | |
+ public String executeRuby(String code); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment