jruby/docs BETA
Navigation
org.jruby.embed.osgi 2
C OSGiIsolatedScriptingContainer
C OSGiScriptingContainer
OSGiScriptingContainer — members 7+
C new(creator)
C new(creator, scope, behavior)
C add_to_class_path(bundle)
M os_gi_bundle_class_loader() JRubyOSGiBundleClassLoader
M parse(bundle, path, lines) EmbedEvalUnit
M run_scriptlet(bundle_symbolic_name, path) Object
M run_scriptlet(bundle, path) Object
from ScriptingContainer
C add_class_loader(class_loader)
M argv() String[]
C argv=(argv)
M attribute_map() Map
M call_method(receiver, method_name, args) Object
M call_method(receiver, method_name, block, args) Object
M call_method(receiver, method_name, return_type) T
M call_method(receiver, method_name, single_arg, return_type) T
M call_method(receiver, method_name, args, return_type) T
M call_method(receiver, method_name, args, block, return_type) T
M call_method(receiver, method_name, return_type, unit) T
M call_method(receiver, method_name, args, return_type, unit) T
M call_method(receiver, method_name, args, block, return_type, unit) T
M call_super(receiver, args, return_type) T
M call_super(receiver, args, block, return_type) T
M class_loader() ClassLoader
C class_loader=(loader)
M classloader_delegate() boolean
C classloader_delegate=(classloader_delegate)
C clear()
M compile_mode() CompileMode
C compile_mode=(mode)
M current_directory() String
C current_directory=(directory)
M environment() Map
C environment=(environment)
M error() PrintStream
C error=(pstream)
C error=(writer)
M error_writer() Writer
C error_writer=(error_writer)
C finalize()
M get(key) Object
M get(receiver, key) Object
M get_attribute(key) Object
M get_instance(receiver, clazz) T
M get_property(key) String[]
M home_directory() String
C home_directory=(home)
M input() InputStream
C input=(istream)
C input=(reader)
M jit_log_every() int
C jit_log_every=(log_every)
M jit_max() int
C jit_max=(max)
M jit_max_size() int
C jit_max_size=(max_size)
M jit_threshold() int
C jit_threshold=(threshold)
M k_code() KCode
C k_code=(kcode)
M load_paths() List<String>
C load_paths=(paths)
M load_service_creator() LoadServiceCreator
C load_service_creator=(creator)
C native_enabled=(b)
M native_enabled?() boolean
M new_object_adapter() EmbedRubyObjectAdapter
M new_runtime_adapter() EmbedRubyRuntimeAdapter
C object_space_enabled=(enable)
M object_space_enabled?() boolean
M output() PrintStream
C output=(pstream)
C output=(writer)
M parse(script, lines) EmbedEvalUnit
M parse(reader, filename, lines) EmbedEvalUnit
M parse(type, filename, lines) EmbedEvalUnit
M parse(istream, filename, lines) EmbedEvalUnit
M profile() Profile
C profile=(profile)
M profile_output() ProfileOutput
C profile_output=(out)
M profiling_mode() ProfilingMode
C profiling_mode=(mode)
M provider() LocalContextProvider
M put(key, value) Object
M put(receiver, key, value) Object
M reader() Reader
C reader=(reader)
M record_separator() String
C record_separator=(separator)
M remove(key) Object
M remove(receiver, key) Object
M remove_attribute(key) Object
C reset_error_writer()
C reset_writer()
C run_ruby_in_process=(inprocess)
M run_ruby_in_process?() boolean
M run_ruby_method(return_type, receiver, method_name, args) T
M run_ruby_method(return_type, receiver, method_name, block, args) T
M run_scriptlet(script) Object
M run_scriptlet(reader, filename) Object
M run_scriptlet(istream, filename) Object
M run_scriptlet(type, filename) Object
M script_filename() String
C script_filename=(filename)
M set_attribute(key, value) Object
M supported_ruby_version() String
C terminate()
M var_map() BiVariableMap
M writer() Writer
C writer=(writer)

org.jruby.embed.osgi.OSGiScriptingContainer

class extends ScriptingContainer 7 members

Helpers to create a ScriptingContainer and set it up so it lives as well as possible in the OSGi world.

Currently:

  1. Access to the java classes and resources provided by the osgi bundle.
  2. Setup of jruby home pointing at the jruby bundle by default. Supporting unzipped jruby bundle for now.

TODO: look into using the LoadService of jruby. Look if it would be possible to reuse the base runtime and minimize the cost of new jruby runtimes.

Constructors

new

new ( Bundle creator )
Java: <init>(org.osgi.framework.Bundle creator)

A scripting container where the classloader can find classes in the osgi creator bundle and where the jruby home is set to point to the one in the jruby's bundle home folder.

scope: LocalContextScope.SINGLETHREAD; behavior: LocalVariableBehavior.TRANSIENT

new

new ( Bundle creator, LocalContextScope scope, LocalVariableBehavior behavior )
Java: <init>(org.osgi.framework.Bundle creator, org.jruby.embed.LocalContextScope scope, org.jruby.embed.LocalVariableBehavior behavior)

A scripting container where the classloader can find classes in the osgi creator bundle and where the jruby home is set to point to the one in the jruby's bundle home folder.

nametypedescription
scopeorg.jruby.embed.LocalContextScopeif null, LocalContextScope.SINGLETHREAD
behaviororg.jruby.embed.LocalVariableBehaviorif null, LocalVariableBehavior.TRANSIENT

Instance Methods

add_to_class_path

add_to_class_path ( Bundle bundle )
Java: addToClassPath(org.osgi.framework.Bundle bundle)
nametypedescription
bundleorg.osgi.framework.BundleAdd a bundle to the jruby classloader. Equivalent to require "bundle:/#{bundle.symbolic.name}"

os_gi_bundle_class_loader

JRubyOSGiBundleClassLoader os_gi_bundle_class_loader ( )
Java: getOSGiBundleClassLoader() · also: get_os_gi_bundle_class_loader

Returns: The ScriptingContainer's classloader casted to a JRubyOSGiBundleClassLoader. It is the parent classloader of the actual's runtime's JRubyClassLoader. It enables finding classes and resources in the OSGi environment.

parse

EmbedEvalUnit parse ( Bundle bundle, String path, int[] lines )
Java: parse(org.osgi.framework.Bundle bundle, String path, int[] lines)

Parses a script given by a input stream and return an object which can be run(). This allows the script to be parsed once and evaluated many times.

nametypedescription
bundleorg.osgi.framework.Bundleis where the script is located
pathStringis the entry in the bundle.
linesint[]are linenumbers to display for parse errors and backtraces. This field is optional. Only the first argument is used for parsing. When no line number is specified, 0 is applied to.

Returns: an object which can be run

run_scriptlet

Object run_scriptlet ( String bundle_symbolic_name, String path )
Java: runScriptlet(String bundleSymbolicName, String path)
nametypedescription
bundle_symbolic_nameStringThe bundle where the script is located. Lazily added to the loader of the OSGiScriptingContainer. (require bundle:/... is implicitly done here)
pathStringThe entry in the bundle

run_scriptlet

Object run_scriptlet ( Bundle bundle, String path )
Java: runScriptlet(org.osgi.framework.Bundle bundle, String path)
nametypedescription
bundleorg.osgi.framework.BundleThe bundle where the script is located. Lazily added to the loader of the OSGiScriptingContainer. (require bundle:/... is implicitly done here)
pathStringThe entry in the bundle

Inherited

from ScriptingContainer

add_class_loader

add_class_loader ( ClassLoader class_loader )
Java: addClassLoader(ClassLoader classLoader)

add the given classLoader to the LOAD_PATH and GEM_PATH

argv

String[] argv ( )
Java: getArgv() · also: get_argv

Returns a list of argument.

Returns: an arguments' list.

argv=

argv= ( String[] argv )
Java: setArgv(String[] argv) · also: set_argv

Changes values of the arguments' list.

nametypedescription
argvString[]a new arguments' list.

attribute_map

Map attribute_map ( )
Java: getAttributeMap() · also: get_attribute_map

Returns a attribute map in one of LocalContextScope. Attributes in this map accept any key value pair, types of which are java.lang.Object. Ruby scripts do not look up this map.

Returns: an attribute map specific to the current thread

call_method

Object call_method ( Object receiver, String method_name, Object[] args )
Java: callMethod(Object receiver, String methodName, Object[] args)

Executes a method defined in Ruby script. This method is used when a Ruby method does not have any argument.

nametypedescription
receiverObjectis an instance that will receive this method call. Ruby's self object will be used if no appropriate receiver is given.
method_nameStringis a method name to be called
argsObject[]is an array of method arguments

Returns: an instance of requested Java type

call_method

Object call_method ( Object receiver, String method_name, Block block, Object[] args )
Java: callMethod(Object receiver, String methodName, org.jruby.runtime.Block block, Object[] args)

Executes a method defined in Ruby script. This method is used when a Ruby method does not have any argument.

nametypedescription
receiverObjectis an instance that will receive this method call Ruby's self object will be used if no appropriate receiver is given.
method_nameStringis a method name to be called
blockorg.jruby.runtime.Blockis a block to be executed in this method
argsObject[]is an array of method arguments

Returns: an instance of requested Java type

call_method

T call_method ( Object receiver, String method_name, Class<T> return_type )
Java: callMethod(Object receiver, String methodName, Class<T> returnType)

Executes a method defined in Ruby script. This method is used when a Ruby method does not have any argument.

nametypedescription
receiverObjectis an instance that will receive this method call. Ruby's self object will be used if no appropriate receiver is given.
method_nameStringis a method name to be called
return_typeClass<T>is the type we want it to convert to

Returns: an instance of requested Java type

call_method

T call_method ( Object receiver, String method_name, Object single_arg, Class<T> return_type )
Java: callMethod(Object receiver, String methodName, Object singleArg, Class<T> returnType)

Executes a method defined in Ruby script. This method is used when a Ruby method have only one argument.

nametypedescription
receiverObjectis an instance that will receive this method call. Ruby's self object will be used if no appropriate receiver is given.
method_nameStringis a method name to be called
single_argObjectis an method argument
return_typeClass<T>returnType is the type we want it to convert to

Returns: an instance of requested Java type

call_method

T call_method ( Object receiver, String method_name, Object[] args, Class<T> return_type )
Java: callMethod(Object receiver, String methodName, Object[] args, Class<T> returnType)

Executes a method defined in Ruby script. This method is used when a Ruby method have multiple arguments.

nametypedescription
receiverObjectis an instance that will receive this method call. Ruby's self object will be used if no appropriate receiver is given.
method_nameStringis a method name to be called
argsObject[]is an array of method arguments
return_typeClass<T>is the type we want it to convert to

Returns: an instance of requested Java type

call_method

T call_method ( Object receiver, String method_name, Object[] args, Block block, Class<T> return_type )
Java: callMethod(Object receiver, String methodName, Object[] args, org.jruby.runtime.Block block, Class<T> returnType)

Executes a method defined in Ruby script. This method is used when a Ruby method have multiple arguments, one of which is a block.

nametypedescription
receiverObjectis an instance that will receive this method call. Ruby's self object will be used if no appropriate receiver is given.
method_nameStringis a method name to be called
argsObject[]is an array of method arguments except a block
blockorg.jruby.runtime.Blockis a block to be executed in this method
return_typeClass<T>is the type we want it to convert to

Returns: an instance of requested Java type

call_method

T call_method ( Object receiver, String method_name, Class<T> return_type, EmbedEvalUnit unit )
Java: callMethod(Object receiver, String methodName, Class<T> returnType, org.jruby.embed.EmbedEvalUnit unit)

Executes a method defined in Ruby script. This method is used when a Ruby method does not have any argument, and users want to inject Ruby's local variables' values from Java.

nametypedescription
receiverObjectis an instance that will receive this method call. Ruby's self object will be used if no appropriate receiver is given.
method_nameStringis a method name to be called
return_typeClass<T>is the type we want it to convert to
unitorg.jruby.embed.EmbedEvalUnitis parsed unit

Returns: an instance of requested Java type

call_method

T call_method ( Object receiver, String method_name, Object[] args, Class<T> return_type, EmbedEvalUnit unit )
Java: callMethod(Object receiver, String methodName, Object[] args, Class<T> returnType, org.jruby.embed.EmbedEvalUnit unit)

Executes a method defined in Ruby script. This method is used when a Ruby method have multiple arguments, and users want to inject Ruby's local variables' values from Java.

nametypedescription
receiverObjectis an instance that will receive this method call. Ruby's self object will be used if no appropriate receiver is given.
method_nameStringis a method name to be called
argsObject[]is an array of method arguments
return_typeClass<T>is the type we want it to convert to
unitorg.jruby.embed.EmbedEvalUnitis parsed unit

Returns: an instance of requested Java type

call_method

T call_method ( Object receiver, String method_name, Object[] args, Block block, Class<T> return_type, EmbedEvalUnit unit )
Java: callMethod(Object receiver, String methodName, Object[] args, org.jruby.runtime.Block block, Class<T> returnType, org.jruby.embed.EmbedEvalUnit unit)

Executes a method defined in Ruby script. This method is used when a Ruby method have multiple arguments, one of which is a block, and users want to inject Ruby's local variables' values from Java.

nametypedescription
receiverObjectis an instance that will receive this method call. Ruby's self object will be used if no appropriate receiver is given.
method_nameStringis a method name to be called
argsObject[]is an array of method arguments except a block
blockorg.jruby.runtime.Blockis a block to be executed in this method
return_typeClass<T>is the type we want it to convert to
unitorg.jruby.embed.EmbedEvalUnitis parsed unit

Returns: is the type we want it to convert to

call_super

T call_super ( Object receiver, Object[] args, Class<T> return_type )
Java: callSuper(Object receiver, Object[] args, Class<T> returnType)
nametypedescription
receiverObjectis an instance that will receive this method call. Ruby's self object will be used if no appropriate receiver is given.
argsObject[]is an array of method arguments
return_typeClass<T>is the type we want it to convert to

Returns: is the type we want it to convert to

call_super

T call_super ( Object receiver, Object[] args, Block block, Class<T> return_type )
Java: callSuper(Object receiver, Object[] args, org.jruby.runtime.Block block, Class<T> returnType)
nametypedescription
receiverObjectis an instance that will receive this method call. Ruby's self object will be used if no appropriate receiver is given.
argsObject[]is an array of method arguments except a block
blockorg.jruby.runtime.Blockis a block to be executed in this method
return_typeClass<T>is the type we want it to convert to

Returns: is the type we want it to convert to

class_loader

ClassLoader class_loader ( )
Java: getClassLoader() · also: get_class_loader

Returns a class loader object that is currently used. This loader loads Ruby files and libraries.

Returns: a class loader object that is currently used.

class_loader=

class_loader= ( ClassLoader loader )
Java: setClassLoader(ClassLoader loader) · also: set_class_loader

Changes a class loader to a given loader. Call this method before you use put/get, runScriptlet, and parse methods so that the given class loader will be used.

nametypedescription
loaderClassLoadera new class loader to be set.

classloader_delegate

boolean classloader_delegate ( )
Java: getClassloaderDelegate() · also: get_classloader_delegate

Retrieve the self-first classloader setting.

classloader_delegate=

classloader_delegate= ( boolean classloader_delegate )
Java: setClassloaderDelegate(boolean classloaderDelegate) · also: set_classloader_delegate

Force dynamically-loaded Java classes to load first from the classloader provided by JRuby before searching parent classloaders. This can be used to isolated dependency in different runtimes from each other and from parent classloaders. The default behavior is to defer to parent classloaders if they can provide the requested classes. Note that if different versions of a library are loaded by both a parent classloader and the JRuby classloader, those classess would be incompatible with each other and with other library objects from the opposing classloader.

nametypedescription
classloader_delegatebooleanset whether prefer the JRuby classloader to delegate first to the parent classloader when dynamically loading classes

clear

clear ( )
Java: clear()

Removes all of the mappings from this map. The map will be empty after this call returns. Ruby variables are also removed from Ruby instance. However, Ruby instance keep having global variable names with null value. This is a short cut method of ScriptingContainer#getVarMap().clear().

compile_mode

RubyInstanceConfig.CompileMode compile_mode ( )
Java: getCompileMode() · also: get_compile_mode

Returns a compile mode currently chosen, which is one of CompileMode.JIT, CompileMode.FORCE, CompileMode.OFF. The default mode is CompileMode.JIT. Also, CompileMode.OFF is chosen when a security restriction is set.

Returns: a compile mode.

compile_mode=

compile_mode= ( RubyInstanceConfig.CompileMode mode )
Java: setCompileMode(org.jruby.RubyInstanceConfig.CompileMode mode) · also: set_compile_mode

Changes a compile mode to a given mode, which should be one of CompileMode.JIT, CompileMode.FORCE, CompileMode.OFF. Call this method before you use put/get, runScriptlet, and parse methods so that the given mode will be used.

nametypedescription
modeorg.jruby.RubyInstanceConfig.CompileModecompile mode

current_directory

String current_directory ( )
Java: getCurrentDirectory() · also: get_current_directory

Returns a current directory. The default current directory is identical to a value of "user.dir" system property if no security restriction is set. If the "user.dir" directory is protected by the security restriction, the default value is "/".

Returns: a current directory.

current_directory=

current_directory= ( String directory )
Java: setCurrentDirectory(String directory) · also: set_current_directory

Changes a current directory to a given directory. The current directory can be changed anytime.

nametypedescription
directoryStringa new directory to be set.

environment

Map environment ( )
Java: getEnvironment() · also: get_environment

Returns a map of environment variables.

Returns: a map that has environment variables' key-value pairs.

environment=

environment= ( Map environment )
Java: setEnvironment(Map environment) · also: set_environment

Changes an environment variables' map. Call this method before you use put/get, runScriptlet, and parse methods so that initial configurations will work.

nametypedescription
environmentMapa new map of environment variables.

error

PrintStream error ( )
Java: getError() · also: get_error

Returns an error stream assigned to STDERR and $stderr.

Returns: output stream for error stream

error=

error= ( PrintStream pstream )
Java: setError(java.io.PrintStream pstream) · also: set_error

Changes STDERR and $stderr to a given print stream. The default standard error is java.lang.System.err. Call this method before you use put/get, runScriptlet, and parse methods so that the given print stream will be used.

nametypedescription
pstreamjava.io.PrintStreama print stream to be set

error=

error= ( Writer writer )
Java: setError(java.io.Writer writer) · also: set_error

Changes STDERR and $stderr to a given writer. No writer is set by default. Call this method before you use put/get, runScriptlet, and parse methods so that the given writer will be used.

nametypedescription
writerjava.io.Writera writer to be set

error_writer

Writer error_writer ( )
Java: getErrorWriter() · also: get_error_writer

Returns an error writer set in an attribute map.

Returns: an error writer in a attribute map

error_writer=

error_writer= ( Writer error_writer )
Java: setErrorWriter(java.io.Writer errorWriter) · also: set_error_writer

Replaces a standard error by a specified writer.

nametypedescription
error_writerjava.io.Writeris a writer to be set

finalize

finalize ( )
Java: finalize()

Ensure this ScriptingContainer instance is terminated when nobody holds any references to it (and GC wants to reclaim it). Note that org.jruby.embed.LocalContextScope#SINGLETON containers will not terminate on GC.

Throws

Throwable

get

Object get ( String key )
Java: get(String key)

Returns a value of the specified key in a top level of runtime or null if this map doesn't have a mapping for the key. The key must be a valid Ruby variable or constant name.

nametypedescription
keyStringis a key whose associated value is to be returned

Returns: a value to which the specified key is mapped, or null if this map contains no mapping for the key

get

Object get ( Object receiver, String key )
Java: get(Object receiver, String key)

Returns a value of a specified key in a specified receiver or null if a variable map doesn't have a mapping for the key in a given receiver. The key must be a valid Ruby variable or constant name. A global variable doesn't depend on the receiver.

nametypedescription
receiverObjecta receiver to get the value from
keyStringis a key whose associated value is to be returned

Returns: a value to which the specified key is mapped, or null if this map contains no mapping for the key

get_attribute

Object get_attribute ( Object key )
Java: getAttribute(Object key)

Returns an attribute value associated with the specified key in a attribute map. This is a short cut method of ScriptingContainer#getAttributeMap().get(key).

nametypedescription
keyObjectis the attribute key

Returns: value is a value associated to the specified key

get_instance

T get_instance ( Object receiver, Class<T> clazz )
Java: getInstance(Object receiver, Class<T> clazz)

Returns an instance of a requested interface type. An implementation of the requested interface is done by a Ruby script, which has been evaluated before getting the instance. In most cases, users don't need to use this method. ScriptingContainer's runScriptlet method returns an instance of the interface type that is implemented by Ruby.

Example
Interface
    //QuadraticFormula.java
    package org.jruby.embed;
    import java.util.List;
    public interface QuadraticFormula {
        List solve(int a, int b, int c) throws Exception;
    }

Implementation
    #quadratic_formula.rb
    def solve(a, b, c)
      v = b ** 2 - 4 * a * c
      if v < 0: raise RangeError end
      s0 = ((-1)*b - Math.sqrt(v))/(2*a)
      s1 = ((-1)*b + Math.sqrt(v))/(2*a)
      return s0, s1
    end

Usage
    ScriptingContainer container = new ScriptingContainer();
    String filename = "ruby/quadratic_formula_class.rb";
    Object receiver = container.runScriptlet(PathType.CLASSPATH, filename);
    QuadraticFormula qf = container.getInstance(receiver, QuadraticFormula.class);
    try {
         List<Double> solutions = qf.solve(1, -2, -13);
         printSolutions(solutions);
         solutions = qf.solve(1, -2, 13);
         for (double s : solutions) {
             System.out.print(s + ", ");
         }
    } catch (Exception e) {
         e.printStackTrace();
    }

Output
    -2.7416573867739413, 4.741657386773941,

nametypedescription
receiverObjectis an instance that implements the interface
clazzClass<T>is a requested interface

Returns: an instance of a requested interface type

get_property

String[] get_property ( String key )
Java: getProperty(String key)

Returns an array of values associated to a key.

nametypedescription
keyStringis a key in a property file

Returns: values associated to the key

home_directory

String home_directory ( )
Java: getHomeDirectory() · also: get_home_directory

Returns a JRuby home directory. The default JRuby home is the value of JRUBY_HOME environment variable, or "jruby.home" system property when no security restriction is set to those directories. If none of JRUBY_HOME or jruby.home is set and jruby-complete.jar is used, the default JRuby home is "/META-INF/jruby.home" in the jar archive. Otherwise, "java.io.tmpdir" system property is the default value.

Returns: a JRuby home directory.

home_directory=

home_directory= ( String home )
Java: setHomeDirectory(String home) · also: set_home_directory

Changes a JRuby home directory to a directory of a given name. Call this method before you use put/get, runScriptlet, and parse methods so that the given directory will be used.

nametypedescription
homeStringa name of new JRuby home directory.

input

InputStream input ( )
Java: getInput() · also: get_input

Returns an input stream assigned to STDIN and $stdin.

Returns: input stream of STDIN and $stdin

input=

input= ( InputStream istream )
Java: setInput(java.io.InputStream istream) · also: set_input

Changes STDIN and $stdin to a given input stream. The default standard input is java.lang.System.in. Call this method before you use put/get, runScriptlet, and parse methods so that the given input stream will be used.

nametypedescription
istreamjava.io.InputStreaman input stream to be set

input=

input= ( Reader reader )
Java: setInput(java.io.Reader reader) · also: set_input

Changes STDIN and $stdin to a given reader. No reader is set by default. Call this method before you use put/get, runScriptlet, and parse methods so that the given reader will be used.

nametypedescription
readerjava.io.Readera reader to be set

jit_log_every

int jit_log_every ( )
Java: getJitLogEvery() · also: get_jit_log_every

Returns the value of n, which means that jitted methods are logged in every n methods. The default value is 0.

Returns: a value that determines how often jitted methods are logged.

jit_log_every=

jit_log_every= ( int log_every )
Java: setJitLogEvery(int logEvery) · also: set_jit_log_every

Changes a value of n, so that jitted methods are logged in every n methods. The default value is 0. This value can be set by the jruby.jit.logEvery System property. Call this method before you use put/get, runScriptlet, and parse methods so that the configurations will work.

nametypedescription
log_everyinta new number of methods.

jit_max

int jit_max ( )
Java: getJitMax() · also: get_jit_max

Returns a value of a max class cache size. The default value is 0 when security restriction is applied, or 4096 when no security restriction exists.

Returns: a value of a max class cache size.

jit_max=

jit_max= ( int max )
Java: setJitMax(int max) · also: set_jit_max

Changes a value of a max class cache size. The default value is 0 when security restriction is applied, or 4096 when no security restriction exists. This value can be set by jruby.jit.max System property. Call this method before you use put/get, runScriptlet, and parse methods so that the configurations will work.

nametypedescription
maxinta new value of a max class cache size.

jit_max_size

int jit_max_size ( )
Java: getJitMaxSize() · also: get_jit_max_size

Returns a value of a max size of the bytecode generated by compiler. The default value is -1 when security restriction is applied, or 10000 when no security restriction exists.

Returns: a value of a max size of the bytecode.

jit_max_size=

jit_max_size= ( int max_size )
Java: setJitMaxSize(int maxSize) · also: set_jit_max_size

Changes a value of a max size of the bytecode generated by compiler. The default value is -1 when security restriction is applied, or 10000 when no security restriction exists. This value can be set by jruby.jit.maxsize System property. Call this method before you use put/get, runScriptlet, and parse methods so that the configurations will work.

nametypedescription
max_sizeinta new value of a max size of the bytecode.

jit_threshold

int jit_threshold ( )
Java: getJitThreshold() · also: get_jit_threshold

Returns a value of the threshold that determines whether jitted methods' call reached to the limit or not. The default value is -1 when security restriction is applied, or 50 when no security restriction exists.

Returns: a value of the threshold.

jit_threshold=

jit_threshold= ( int threshold )
Java: setJitThreshold(int threshold) · also: set_jit_threshold

Changes a value of the threshold that determines whether jitted methods' call reached to the limit or not. The default value is -1 when security restriction is applied, or 50 when no security restriction exists. This value can be set by jruby.jit.threshold System property. Call this method before you use put/get, runScriptlet, and parse methods so that the configurations will work.

nametypedescription
thresholdinta new value of the threshold.

k_code

KCode k_code ( )
Java: getKCode() · also: get_k_code

Returns a value of KCode currently used. The default value is KCode.NONE.

Returns: a KCode value.

k_code=

k_code= ( KCode kcode )
Java: setKCode(org.jruby.util.KCode kcode) · also: set_k_code

Changes a value of KCode to a given value. The value should be one of KCode.NONE, KCode.UTF8, KCode.SJIS, or KCode.EUC. The default value is KCode.NONE. Call this method before you use put/get, runScriptlet, and parse methods so that the given value will be used.

nametypedescription
kcodeorg.jruby.util.KCodea new KCode value.

load_paths

List<String> load_paths ( )
Java: getLoadPaths() · also: get_load_paths

Returns a list of load paths for Ruby scripts/libraries. If no paths is given, the list is created from java.class.path System property.

Returns: a list of load paths.

load_paths=

load_paths= ( List<String> paths )
Java: setLoadPaths(List<String> paths) · also: set_load_paths

Changes a list of load paths Ruby scripts/libraries. The default value is an empty array. If no paths is given, the list is created from java.class.path System property. This value can be set by org.jruby.embed.class.path System property, also. Call this method before you use put/get, runScriptlet, and parse methods so that the given paths will be used.

nametypedescription
pathsList<String>a new list of load paths.

load_service_creator

RubyInstanceConfig.LoadServiceCreator load_service_creator ( )
Java: getLoadServiceCreator() · also: get_load_service_creator

Returns a LoadServiceCreator currently used.

Returns: a current LoadServiceCreator.

load_service_creator=

load_service_creator= ( RubyInstanceConfig.LoadServiceCreator creator )
Java: setLoadServiceCreator(org.jruby.RubyInstanceConfig.LoadServiceCreator creator) · also: set_load_service_creator

Changes a LoadServiceCreator to a given one. Call this method before you use put/get, runScriptlet, and parse methods so that initial configurations will work.

nametypedescription
creatororg.jruby.RubyInstanceConfig.LoadServiceCreatora new LoadServiceCreator

native_enabled=

native_enabled= ( boolean b )
Java: setNativeEnabled(boolean b) · also: set_native_enabled

Set whether native code is enabled for this config. Disabling it also disables C extensions (@see RubyInstanceConfig#setCextEnabled).

nametypedescription
bbooleannew value indicating whether native code is enabled

native_enabled?

boolean native_enabled? ( )
Java: isNativeEnabled() · also: is_native_enabled

Get whether native code is enabled for this config.

Returns: true if native code is enabled; false otherwise.

new_object_adapter

EmbedRubyObjectAdapter new_object_adapter ( )
Java: newObjectAdapter()

Returns an instance of EmbedRubyObjectAdapter for embedders to invoke methods defined by Ruby. The script must be evaluated prior to a method call. In most cases, users don't need to use this method. ScriptingContainer's callMethods are the shortcut and work in the same way.

Example
        # calendar.rb
        require 'date'
        class Calendar
          def initialize;@today = DateTime.now;end
          def next_year;@today.year + 1;end
        end
        Calendar.new


        ScriptingContainer container = new ScriptingContainer();
        String filename =  "ruby/calendar.rb";
        Object receiver = instance.runScriptlet(PathType.CLASSPATH, filename);
        EmbedRubyObjectAdapter adapter = instance.newObjectAdapter();
        Integer result =
            (Integer) adapter.callMethod(receiver, "next_year", Integer.class);
        System.out.println("next year: " + result);
        System.out.println(instance.get("@today"));

Outputs:
    next year: 2010
    2009-05-19T17:46:44-04:00

Returns: an instance of EmbedRubyObjectAdapter

new_runtime_adapter

EmbedRubyRuntimeAdapter new_runtime_adapter ( )
Java: newRuntimeAdapter()

Returns an instance of EmbedRubyRuntimeAdapter for embedders to parse scripts.

Returns: an instance of EmbedRubyRuntimeAdapter.

object_space_enabled=

object_space_enabled= ( boolean enable )
Java: setObjectSpaceEnabled(boolean enable) · also: set_object_space_enabled

Changes the value to determine whether the Object Space is enabled or not. The default value is false. Call this method before you use put/get, runScriptlet, and parse methods so that the given condition will be used.

nametypedescription
enablebooleantrue to enable the Object Space, or false to disable.

object_space_enabled?

boolean object_space_enabled? ( )
Java: isObjectSpaceEnabled() · also: is_object_space_enabled

Tests whether the Object Space is enabled or not.

Returns: true if the Object Space is able to use, otherwise, false.

output

PrintStream output ( )
Java: getOutput() · also: get_output

Returns an output stream assigned to STDOUT and $stdout.

Returns: an output stream of STDOUT and $stdout

output=

output= ( PrintStream pstream )
Java: setOutput(java.io.PrintStream pstream) · also: set_output

Changes STDOUT and $stdout to a given output stream. The default standard output is java.lang.System.out. Call this method before you use put/get, runScriptlet, and parse methods so that the given output stream will be used.

nametypedescription
pstreamjava.io.PrintStreaman output stream to be set

output=

output= ( Writer writer )
Java: setOutput(java.io.Writer writer) · also: set_output

Changes STDOUT and $stdout to a given writer. No writer is set by default. Call this method before you use put/get, runScriptlet, and parse methods so that the given writer will be used.

nametypedescription
writerjava.io.Writera writer to be set

parse

EmbedEvalUnit parse ( String script, int[] lines )
Java: parse(String script, int[] lines)

Parses a script and return an object which can be run(). This allows the script to be parsed once and evaluated many times.

nametypedescription
scriptStringis a Ruby script to be parsed
linesint[]are linenumbers to display for parse errors and backtraces. This field is optional. Only the first argument is used for parsing. When no line number is specified, 0 is applied to.

Returns: an object which can be run

parse

EmbedEvalUnit parse ( Reader reader, String filename, int[] lines )
Java: parse(java.io.Reader reader, String filename, int[] lines)

Parses a script given by a reader and return an object which can be run(). This allows the script to be parsed once and evaluated many times.

nametypedescription
readerjava.io.Readeris used to read a script from
filenameStringis used as in information, for example, appears in a stack trace of an exception
linesint[]are linenumbers to display for parse errors and backtraces. This field is optional. Only the first argument is used for parsing. When no line number is specified, 0 is applied to.

Returns: an object which can be run

parse

EmbedEvalUnit parse ( PathType type, String filename, int[] lines )
Java: parse(org.jruby.embed.PathType type, String filename, int[] lines)

Parses a script read from a specified path and return an object which can be run(). This allows the script to be parsed once and evaluated many times.

nametypedescription
typeorg.jruby.embed.PathTypeis one of the types PathType defines
filenameStringis used as in information, for example, appears in a stack trace of an exception
linesint[]are linenumbers to display for parse errors and backtraces. This field is optional. Only the first argument is used for parsing. When no line number is specified, 0 is applied to.

Returns: an object which can be run

parse

EmbedEvalUnit parse ( InputStream istream, String filename, int[] lines )
Java: parse(java.io.InputStream istream, String filename, int[] lines)

Parses a script given by a input stream and return an object which can be run(). This allows the script to be parsed once and evaluated many times.

nametypedescription
istreamjava.io.InputStreamis an input stream to get a script from
filenameStringfilename is used as in information, for example, appears in a stack trace of an exception
linesint[]are linenumbers to display for parse errors and backtraces. This field is optional. Only the first argument is used for parsing. When no line number is specified, 0 is applied to.

Returns: an object which can be run

profile

Profile profile ( )
Java: getProfile() · also: get_profile

Returns a Profile currently used. The default value is Profile.DEFAULT, which has the same behavior to Profile.ALL. Profile allows you to define a restricted subset of code to be loaded during the runtime initialization. When you use JRuby in restricted environment such as Google App Engine, Profile is a helpful option.

Returns: a current profiler.

profile=

profile= ( Profile profile )
Java: setProfile(org.jruby.Profile profile) · also: set_profile

Changes a Profile to a given one. The default value is Profile.DEFAULT, which has the same behavior to Profile.ALL. Call this method before you use put/get, runScriptlet, and parse methods so that initial configurations will work. Profile allows you to define a restricted subset of code to be loaded during the runtime initialization. When you use JRuby in restricted environment such as Google App Engine, Profile is a helpful option. For example, Profile.NO_FILE_CLASS doesn't load File class.

nametypedescription
profileorg.jruby.Profilea new profiler to be set.

profile_output

ProfileOutput profile_output ( )
Java: getProfileOutput() · also: get_profile_output

Returns currently configured ProfileOutput object, which determines where the output of profiling operations will be sent. (e.g., a file specified by --profile.out).

Returns: current profiling output location.

profile_output=

profile_output= ( ProfileOutput out )
Java: setProfileOutput(org.jruby.runtime.profile.builtin.ProfileOutput out) · also: set_profile_output

Changes ProfileOutput to given one. The default value is a ProfileOutput instance that writes to stderr. Similar to passing `--profile.out` from the command line

nametypedescription
outorg.jruby.runtime.profile.builtin.ProfileOutputa new ProfileOutput object, to which profiling data should be written

profiling_mode

RubyInstanceConfig.ProfilingMode profiling_mode ( )
Java: getProfilingMode() · also: get_profiling_mode

Returns a ProfilingMode currently used. The default value is ProfilingMode.OFF.

Returns: a current profiling mode.

profiling_mode=

profiling_mode= ( RubyInstanceConfig.ProfilingMode mode )
Java: setProfilingMode(org.jruby.RubyInstanceConfig.ProfilingMode mode) · also: set_profiling_mode

Changes a ProfilingMode to a given one. The default value is Profiling.OFF. Call this method before you use put/get, runScriptlet, and parse methods so that initial configurations will work. ProfilingMode allows you to change profiling style. Profiling.OFF - default. profiling off. Profiling.API - activates Ruby profiler API. equivalent to --profile.api command line option Profiling.FLAT - synonym for --profile command line option equivalent to --profile.flat command line option Profiling.GRAPH - runs with instrumented (timed) profiling, graph format. equivalent to --profile.graph command line option.

nametypedescription
modeorg.jruby.RubyInstanceConfig.ProfilingModea new profiling mode to be set.

provider

LocalContextProvider provider ( )
Java: getProvider() · also: get_provider

Returns a provider instance of LocalContextProvider. When users want to configure Ruby runtime, they can do by setting class loading paths, org.jruby.RubyInstanceConfig to the provider before they get Ruby runtime.

Returns: a provider of LocalContextProvider

put

Object put ( String key, Object value )
Java: put(String key, Object value)

Associates the specified value with the specified key in a variable map. This key-value pair is injected to a top level of runtime during evaluation. If the map previously contained a mapping for the key, the old value is replaced. The key must be a valid Ruby variable or constant name. It will be a top level variable or constant.

nametypedescription
keyStringis a key that the specified value is to be associated with
valueObjectis a value to be associated with the specified key

Returns: a previous value associated with a key, or null if there was no mapping for this key.

put

Object put ( Object receiver, String key, Object value )
Java: put(Object receiver, String key, Object value)

Associates the specified value with the specified key in a variable map. This key-value pair is injected to a given receiver during evaluation. If the map previously contained a mapping for the key, the old value is replaced. The key must be a valid Ruby variable or constant name. A given receiver limits the scope of a variable or constant. However, a global variable is accessible globally always.

nametypedescription
receiverObjecta receiver to put the value in
keyStringis a key that the specified value is to be associated with
valueObjectis a value to be associated with the specified key

Returns: a previous value associated with a key, or null if there was no mapping for this key.

reader

Reader reader ( )
Java: getReader() · also: get_reader

Returns a reader set in an attribute map.

Returns: a reader in an attribute map

reader=

reader= ( Reader reader )
Java: setReader(java.io.Reader reader) · also: set_reader

Replaces a standard input by a specified reader

nametypedescription
readerjava.io.Readeris a reader to be set

record_separator

String record_separator ( )
Java: getRecordSeparator() · also: get_record_separator

Returns a record separator. The default value is "\n".

Returns: a record separator.

record_separator=

record_separator= ( String separator )
Java: setRecordSeparator(String separator) · also: set_record_separator

Changes a record separator to a given value. If "0" is given, the record separator goes to "\n\n", "777" goes to "￿", otherwise, an octal value of the given number. Call this before you use put/get, runScriptlet, and parse methods so that initial configurations will work.

nametypedescription
separatorStringa new record separator value, "0" or "777"

remove

Object remove ( String key )
Java: remove(String key)

Removes the specified Ruby variable with the specified variable name from a variable map and runtime top level. If the map previously contained a mapping for the key, the old value is returned. The key must be a valid Ruby variable name.

nametypedescription
keyStringis a key that the specified value is to be associated with

Returns: a previous value associated with a key, or null if there was no mapping for this key.

remove

Object remove ( Object receiver, String key )
Java: remove(Object receiver, String key)

Removes the specified Ruby variable with the specified variable name in a variable map and given receiver. If the map previously contained a mapping for the key, the old value is returned. The key must be a valid Ruby variable name. This is a short cut method of ScriptingContainer#getVarMap().remove(key).

nametypedescription
receiverObjecta receiver to remove the value from
keyStringis a key that the specified value is to be associated with

Returns: a previous value associated with a key, or null if there was no mapping for this key.

remove_attribute

Object remove_attribute ( Object key )
Java: removeAttribute(Object key)

Removes the specified value with the specified key in a attribute map. If the map previously contained a mapping for the key, the old value is returned. This is a short cut method of ScriptingContainer#getAttributeMap().remove(key).

nametypedescription
keyObjectis a key that the specified value is to be removed from

Returns: the previous value associated with key, or null if there was no mapping for key.

reset_error_writer

reset_error_writer ( )
Java: resetErrorWriter()

reset_writer

reset_writer ( )
Java: resetWriter()

run_ruby_in_process=

run_ruby_in_process= ( boolean inprocess )
Java: setRunRubyInProcess(boolean inprocess) · also: set_run_ruby_in_process

Changes the value to determine whether Ruby runs in a process or not. The default value is true. Call this method before you use put/get, runScriptlet, and parse methods so that the given condition will be set.

nametypedescription
inprocessbooleantrue when Ruby is set to run in the process, or false not to run in the process.

run_ruby_in_process?

boolean run_ruby_in_process? ( )
Java: isRunRubyInProcess() · also: is_run_ruby_in_process

Tests whether Ruby runs in a process or not.

Returns: true if Ruby is configured to run in a process, otherwise, false.

run_ruby_method

T run_ruby_method ( Class<T> return_type, Object receiver, String method_name, Object[] args )
Java: runRubyMethod(Class<T> returnType, Object receiver, String methodName, Object[] args)

Executes a method defined in Ruby script. This method is used when a Ruby method does not have any argument.

nametypedescription
return_typeClass<T>is the type we want it to convert to
receiverObjectis an instance that will receive this method call. The receiver can be null or other Java objects as well as RubyObject. The null will be converted to RubyNil. Java objects will be wrapped in RubyObject.
method_nameStringis a method name to be called
argsObject[]is an array of method arguments

Returns: an instance of requested Java type

run_ruby_method

T run_ruby_method ( Class<T> return_type, Object receiver, String method_name, Block block, Object[] args )
Java: runRubyMethod(Class<T> returnType, Object receiver, String methodName, org.jruby.runtime.Block block, Object[] args)

Executes a method defined in Ruby script. This method is used when a Ruby method does not have any argument.

nametypedescription
return_typeClass<T>is the type we want it to convert to
receiverObjectis an instance that will receive this method call. The receiver can be null or other Java objects as well as RubyObject. The null will be converted to RubyNil. Java objects will be wrapped in RubyObject.
method_nameStringis a method name to be called
blockorg.jruby.runtime.Blockis an optional Block object. Send null for no block.
argsObject[]is an array of method arguments

Returns: an instance of requested Java type

run_scriptlet

Object run_scriptlet ( String script )
Java: runScriptlet(String script)

Evaluates a script under the current scope (perhaps the top-level scope) and returns a result only if a script returns a value. Right after the parsing, the script is evaluated once.

nametypedescription
scriptStringis a Ruby script to get run

Returns: an evaluated result converted to a Java object

run_scriptlet

Object run_scriptlet ( Reader reader, String filename )
Java: runScriptlet(java.io.Reader reader, String filename)

Evaluates a script read from a reader under the current scope (perhaps the top-level scope) and returns a result only if a script returns a value. Right after the parsing, the script is evaluated once.

nametypedescription
readerjava.io.Readeris used to read a script from
filenameStringis used as in information, for example, appears in a stack trace of an exception

Returns: an evaluated result converted to a Java object

run_scriptlet

Object run_scriptlet ( InputStream istream, String filename )
Java: runScriptlet(java.io.InputStream istream, String filename)

Evaluates a script read from a input stream under the current scope (perhaps the top-level scope) and returns a result only if a script returns a value. Right after the parsing, the script is evaluated once.

nametypedescription
istreamjava.io.InputStreamis used to input a script from
filenameStringis used as in information, for example, appears in a stack trace of an exception

Returns: an evaluated result converted to a Java object

run_scriptlet

Object run_scriptlet ( PathType type, String filename )
Java: runScriptlet(org.jruby.embed.PathType type, String filename)

Reads a script file from specified path and evaluates it under the current scope (perhaps the top-level scope) and returns a result only if a script returns a value. Right after the parsing, the script is evaluated once.

nametypedescription
typeorg.jruby.embed.PathTypeis one of the types PathType defines
filenameStringis used to read the script from and an information

Returns: an evaluated result converted to a Java object

script_filename

String script_filename ( )
Java: getScriptFilename() · also: get_script_filename

Returns a script filename to run. The default value is "<script>".

Returns: a script filename.

script_filename=

script_filename= ( String filename )
Java: setScriptFilename(String filename) · also: set_script_filename

Changes a script filename to run. The default value is "<script>". Call this before you use put/get, runScriptlet, and parse methods so that initial configurations will work.

nametypedescription
filenameStringa new script filename.

set_attribute

Object set_attribute ( Object key, Object value )
Java: setAttribute(Object key, Object value)

Associates the specified value with the specified key in a attribute map. If the map previously contained a mapping for the key, the old value is replaced. This is a short cut method of ScriptingContainer#getAttributeMap().put(key, value).

nametypedescription
keyObjectis a key that the specified value is to be associated with
valueObjectis a value to be associated with the specified key

Returns: the previous value associated with key, or null if there was no mapping for key.

supported_ruby_version

String supported_ruby_version ( )
Java: getSupportedRubyVersion() · also: get_supported_ruby_version

Returns version information about JRuby and Ruby supported by this platform.

Returns: version information.

terminate

terminate ( )
Java: terminate()

Cleanly shut down this ScriptingContainer and any JRuby resources it holds. All ScriptingContainer instances should be terminated when you are done with them, rather then leaving them for GC to finalize.

var_map

BiVariableMap var_map ( )
Java: getVarMap() · also: get_var_map

Returns a variable map in one of LocalContextScope. Variables in this map is used to share between Java and Ruby. Map keys are Ruby's variable names, thus they must be valid Ruby names.

Returns: a variable map specific to the current thread

writer

Writer writer ( )
Java: getWriter() · also: get_writer

Returns a writer set in an attribute map.

Returns: a writer in a attribute map

writer=

writer= ( Writer writer )
Java: setWriter(java.io.Writer writer) · also: set_writer

Replaces a standard output by a specified writer.

nametypedescription
writerjava.io.Writeris a writer to be set
Copyright (C) 2002-2011 JRuby Community