LocalContextState defines four scopes to maintain LocalContext.
A single ScriptingContainer can be configured to act as a facade for multiple Ruby runtimes
(or really multiple Ruby VMs, since each Ruby instance is a Ruby "VM"), and this enum controls
that behaviour. (this behaviour is bit like that of ThreadLocal — it changes its behaviour
silently depending on the calling thread, an act of multiplexing.)
When you think of this multiplexing behaviour, there are two sets of states that need separate attention.
One is Ruby instance, which represents the whole VM, classes, global variables, etc. Then
there's attributes and so-called
variables, which are really a special scope induced by the
scripting container for better JSR-223 interop.
In this documentation, we refer to the former as "the runtime" and the latter as "the variables",
but the variables shouldn't be confused with the global variables in Ruby's semantics, which belongs
to the runtime.
| constant | type | note |
|---|---|---|
| SINGLETON | LocalContextScope | Uses a "global" singleton runtime and variables.
All the ScriptingContainers that are created with this scope will share a single
runtime and a single set of variables. Therefore one container can
set a value and another container will see the same value.
The global runtime comes from org.jruby.Ruby#getGlobalRuntime(), which initializes or retrieves a Ruby
instance in a static field on org.jruby.Ruby. All singleton context scopes will reuse this instance.
When any singleton-based scripting container is torn down (ScriptingContainer#terminate()), the global runtime will also
be torn down and cleared. Subsequent singleton containers will see a new runtime.
Note that unlike the other modes, containers created with singleton context scoping will not tear down
the associated JRuby runtime upon finalization. |
| SINGLETHREAD | LocalContextScope | ScriptingContainer will not do any multiplexing at all.
If you have multiple threads calling single
If you aren't using the variables of |
| THREADSAFE | LocalContextScope | Maintain separate runtimes and variable maps for each calling thread.
Known as the "apartment thread model", this mode makes |
| CONCURRENT | LocalContextScope | Use a single runtime but variable maps are thread local.
In this mode, there'll be a single runtime dedicated for each |
compareTo(E arg0)getDeclaringClass() · also: get_declaring_classdescribeConstable()equals(Object arg0)hashCode()name()ordinal()toString()