Top Description Constructors Methods
org.jruby.embed.osgi

public Class OSGiScriptingContainer

extends ScriptingContainer
Class Inheritance
Imports
java.io.BufferedInputStream, .IOException, .InputStream, java.net.URL, org.jruby.embed.EmbedEvalUnit, .EvalFailedException, .LocalContextScope, .LocalVariableBehavior, .ScriptingContainer, org.jruby.embed.osgi.internal.JRubyOSGiBundleClassLoader, .OSGiLoadService, org.jruby.embed.osgi.utils.OSGiFileLocator, org.osgi.framework.Bundle

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.

Author
hmalphettes

Constructor Summary

AccessConstructor and Description
public
OSGiScriptingContainer(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.

public
OSGiScriptingContainer(Bundle creator, LocalContextScope
if null, LocalContextScope.SINGLETHREAD
scope
,
LocalVariableBehavior
if null, LocalVariableBehavior.TRANSIENT
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.

Method Summary

Modifier and TypeMethod and Description
public void
addToClassPath(Bundle
Add a bundle to the jruby classloader. Equivalent to require "bundle:/#{bundle.symbolic.name}"
bundle
)

private String

Returns:

a nice debugging string for the stack traces that is passed as the 'filename' of this script to jruby.
getFilename
(Bundle bundle, String path)

public JRubyOSGiBundleClassLoader

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.
getOSGiBundleClassLoader
()

public EmbedEvalUnit

Returns:

an object which can be run
parse
(Bundle
is where the script is located
bundle
,
String
is the entry in the bundle.
path
,
int...
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.
lines
)

Parses a script given by a input stream and return an object which can be run().

public Object
runScriptlet(String
The bundle where the script is located. Lazily added to the loader of the OSGiScriptingContainer. (require bundle:/... is implicitly done here)
bundleSymbolicName
,
String
The entry in the bundle
path
)

public Object
runScriptlet(Bundle
The bundle where the script is located. Lazily added to the loader of the OSGiScriptingContainer. (require bundle:/... is implicitly done here)
bundle
,
String
The entry in the bundle
path
)

Inherited from org.jruby.embed.ScriptingContainer:
addClassLoaderaddGemPathaddGemPathaddLoadPathaddLoadPathcallMethodcallMethodcallMethodcallMethodcallMethodcallMethodcallMethodcallMethodcallMethodcallSupercallSuperclearfinalizegetgetgetArgvgetAttributegetAttributeMapgetClassLoadergetClassloaderDelegategetCompileModegetCurrentDirectorygetEnvironmentgetErrgetErrorgetErrorWritergetHomeDirectorygetIngetInputgetInstancegetJitLogEverygetJitMaxgetJitMaxSizegetJitThresholdgetKCodegetLoadPathsgetLoadServiceCreatorgetOutgetOutputgetProfilegetProfileOutputgetProfilingModegetPropertygetProvidergetReadergetRecordSeparatorgetRuntimegetScriptFilenamegetSupportedRubyVersiongetVarMapgetWriterisNativeEnabledisObjectSpaceEnabledisRunRubyInProcessnewObjectAdapternewRuntimeAdapterparseparseparseparseputputremoveremoveremoveAttributeresetErrorWriterresetWriterrunRubyMethodrunRubyMethodrunScriptletrunScriptletrunScriptletrunScriptletsetArgvsetAttributesetClassLoadersetClassloaderDelegatesetCompileModesetCurrentDirectorysetEnvironmentsetErrorsetErrorsetErrorWritersetHomeDirectorysetInputsetInputsetJitLogEverysetJitMaxsetJitMaxSizesetJitThresholdsetKCodesetLoadPathssetLoadServiceCreatorsetNativeEnabledsetObjectSpaceEnabledsetOutputsetOutputsetProfilesetProfilesetProfileOutputsetProfilingModesetReadersetRecordSeparatorsetRunRubyInProcesssetScriptFilenamesetWriterterminate

Constructor Detail

OSGiScriptingContainerback to summary
public OSGiScriptingContainer(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

OSGiScriptingContainerback to summary
public OSGiScriptingContainer(Bundle creator, LocalContextScope scope, 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.

Parameters
scope:LocalContextScope

if null, LocalContextScope.SINGLETHREAD

behavior:LocalVariableBehavior

if null, LocalVariableBehavior.TRANSIENT

Method Detail

addToClassPathback to summary
public void addToClassPath(Bundle bundle)
Parameters
bundle:Bundle

Add a bundle to the jruby classloader. Equivalent to require "bundle:/#{bundle.symbolic.name}"

getFilenameback to summary
private String getFilename(Bundle bundle, String path)
Returns:String

a nice debugging string for the stack traces that is passed as the 'filename' of this script to jruby.

getOSGiBundleClassLoaderback to summary
public JRubyOSGiBundleClassLoader getOSGiBundleClassLoader()
Returns:JRubyOSGiBundleClassLoader

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.

parseback to summary
public EmbedEvalUnit parse(Bundle bundle, String path, int... lines) throws IOException

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.

Parameters
bundle:Bundle

is where the script is located

path:String

is the entry in the bundle.

lines:int[]

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:EmbedEvalUnit

an object which can be run

runScriptletback to summary
public Object runScriptlet(String bundleSymbolicName, String path)
Parameters
bundleSymbolicName:String

The bundle where the script is located. Lazily added to the loader of the OSGiScriptingContainer. (require bundle:/... is implicitly done here)

path:String

The entry in the bundle

runScriptletback to summary
public Object runScriptlet(Bundle bundle, String path)
Parameters
bundle:Bundle

The bundle where the script is located. Lazily added to the loader of the OSGiScriptingContainer. (require bundle:/... is implicitly done here)

path:String

The entry in the bundle