public class ExecutionContext extends Object
Executable
.
You should always release()
an execution context when done using it.
An execution context is not in itself thread-safe. However, it supports two use cases with different threading behavior.
The first occurs when
Executable.execute(ExecutionContext, Object, ExecutionController)
is
callable by concurrent threads. In this case, each thread should create
its own execution context, and the context in such cases is
essentially thread-unique. Just be aware that if your executable spawns
threads, they would need to coordinate access to the context if they need it.
The second occurs when
Executable.makeEnterable(Object, ExecutionContext, Object, ExecutionController)
is called, and then Executable.enter(Object, String, Object...)
is
callable by concurrent threads. In this case, all invoking threads share
the same execution context. Because the context is immutable (internally
makeImmutable()
is called), it is "thread-safe" to the extent that
you better not try to modify it. Otherwise, an IllegalStateException
is thrown.
Modifier and Type | Field and Description |
---|---|
protected Executable |
enterableExecutable
Non-null if this context is enterable.
|
protected Object |
enteringKey
Non-null if this context is enterable.
|
Constructor and Description |
---|
ExecutionContext()
Constructor.
|
ExecutionContext(Writer writer)
Constructor.
|
ExecutionContext(Writer writer,
Writer errorWriter)
Constructor.
|
Modifier and Type | Method and Description |
---|---|
void |
addAdapter(LanguageAdapter languageAdapter)
Sets a language adapter as a user of this context.
|
static void |
disconnect()
Makes sure there is no execution context associated with this thread.
|
Object |
enter(String entryPointName,
Object... arguments)
Enters the executable at a stored, named location, via the last language
adapter that used this context.
|
LanguageAdapter |
getAdapter()
The last language adapter used by the context.
|
Map<String,Object> |
getAttributes()
General-purpose attributes.
|
static ExecutionContext |
getCurrent()
The execution context set for this thread.
|
Executable |
getEnterableExecutable()
Non-null if this context is enterable.
|
Writer |
getErrorWriter()
The standard error set for executables using this context.
|
Writer |
getErrorWriterOrDefault()
The standard error set for executables using this context.
|
List<URI> |
getLibraryLocations()
Locations where language adapters might search for extra libraries.
|
Map<String,Object> |
getServices()
Services exposed to executables using this context.
|
Writer |
getWriter()
The standard output set for executables using this context.
|
Writer |
getWriterOrDefault()
The standard output set for executables using this context.
|
boolean |
isImmutable()
Immutable contexts will throw an
IllegalStateException whenever
an attempt is made to change them. |
ExecutionContext |
makeCurrent()
Sets this execution context for this thread.
|
void |
makeImmutable()
Makes this context immutable.
|
void |
release()
Calls
LanguageAdapter.releaseContext(ExecutionContext) on all
adapters that have used this context. |
Writer |
setErrorWriter(Writer writer)
The standard error set for executables using this context.
|
Writer |
setWriter(Writer writer)
The standard output set for executables using this context.
|
String |
toString() |
protected Executable enterableExecutable
protected Object enteringKey
public ExecutionContext()
public ExecutionContext(Writer writer)
writer
- The standard output set for executables using this contextpublic static ExecutionContext getCurrent()
makeCurrent()
,
disconnect()
public static void disconnect()
makeCurrent()
,
getCurrent()
public Map<String,Object> getAttributes()
Immutable contexts will return an unmodifiable map.
isImmutable()
public List<URI> getLibraryLocations()
Immutable contexts will return an unmodifiable list.
File.toURI()
public Map<String,Object> getServices()
Immutable contexts will return an unmodifiable map.
isImmutable()
public Writer getWriter()
public Writer getWriterOrDefault()
public Writer setWriter(Writer writer)
writer
- The writerpublic Writer getErrorWriter()
public Writer getErrorWriterOrDefault()
public Writer setErrorWriter(Writer writer)
writer
- The writerpublic LanguageAdapter getAdapter()
public void addAdapter(LanguageAdapter languageAdapter)
release()
is
called.languageAdapter
- The language adapterLanguageAdapter.releaseContext(ExecutionContext)
public Executable getEnterableExecutable()
enter(String, Object...)
,
Executable.makeEnterable(Object, ExecutionContext, Object,
ExecutionController)
public boolean isImmutable()
IllegalStateException
whenever
an attempt is made to change them.public Object enter(String entryPointName, Object... arguments) throws ParsingException, ExecutionException, NoSuchMethodException
The context must have been previously made enterable by a call to
Executable.makeEnterable(Object, ExecutionContext, Object, ExecutionController)
.
entryPointName
- The name of the entry pointarguments
- Optional state to pass to the entry pointParsingException
- In case of a parsing errorExecutionException
- In case of an execution errorNoSuchMethodException
- In case the entry point does not existgetEnterableExecutable()
,
getAdapter()
public void makeImmutable()
IllegalStateException
.
Calling this method more than once will have no effect. Once made immutable, execution contexts cannot become mutable again.
public ExecutionContext makeCurrent()
getCurrent()
,
disconnect()
public void release()
LanguageAdapter.releaseContext(ExecutionContext)
on all
adapters that have used this context.
After this call, any attempt to access the context will result in an
IllegalStateException
.
Copyright © 2009-2015 Three Crickets LLC.