Modifier and Type | Method and Description |
---|---|
Context.Builder |
allowAllAccess(boolean enabled)
If
true , grants the context the same access privileges as the host virtual
machine. |
Context.Builder |
allowCreateThread(boolean enabled)
If
true , allows guest languages to create new threads. |
Context.Builder |
allowHostAccess(boolean enabled)
Allows guest languages to access the host language by loading new classes.
|
Context.Builder |
allowHostClassLoading(boolean enabled)
If host class loading is enabled, then the guest language is allowed to load new host
classes via jar or class files.
|
Context.Builder |
allowIO(boolean enabled)
If
true , allows guest language to perform unrestricted IO operations on host
system. |
Context.Builder |
allowNativeAccess(boolean enabled)
Allows guest languages to access the native interface.
|
Context.Builder |
arguments(String language,
String[] args)
Sets the guest language application arguments for a language
context . |
Context |
build()
Creates a new context instance from the configuration provided in the builder.
|
Context.Builder |
engine(Engine engine)
Explicitly sets the underlying engine to use.
|
Context.Builder |
err(OutputStream err)
Sets the error output stream to be used for the context.
|
Context.Builder |
fileSystem(FileSystem fileSystem)
Installs a new
FileSystem . |
Context.Builder |
hostClassFilter(Predicate<String> classFilter)
Sets a class filter that allows to limit the classes that are allowed to be loaded by
guest languages.
|
Context.Builder |
in(InputStream in)
Sets the input stream to be used for the context.
|
Context.Builder |
logHandler(Handler logHandler)
Installs a new logging
Handler . |
Context.Builder |
logHandler(OutputStream logOut)
Installs a new logging
Handler using given OutputStream . |
Context.Builder |
option(String key,
String value)
Sets an option for this
context . |
Context.Builder |
options(Map<String,String> options)
Shortcut for setting multiple
options using a map. |
Context.Builder |
out(OutputStream out)
Sets the standard output stream to be used for the context.
|
Context.Builder |
serverTransport(MessageTransport serverTransport)
Take over the transport of messages communication with a server peer.
|
public Context.Builder engine(Engine engine)
Engine
for more details about system resource sharing.public Context.Builder out(OutputStream out)
engine
or standard error stream
is used.public Context.Builder err(OutputStream err)
engine
or standard error stream
is used.public Context.Builder in(InputStream in)
engine
or standard in stream is used.public Context.Builder allowHostAccess(boolean enabled)
false
. If all access
is set to
true
, then host access is enabled if not allowed explicitly.public Context.Builder allowNativeAccess(boolean enabled)
public Context.Builder allowCreateThread(boolean enabled)
true
, allows guest languages to create new threads. Default is
false
. If all access
is set to
true
, then the creation of threads is enabled if not allowed explicitly.
Threads created by guest languages are closed, when the context is closed
.public Context.Builder allowAllAccess(boolean enabled)
true
, grants the context the same access privileges as the host virtual
machine. If not explicitly specified, then all access is false
. If the host
VM runs without a security manager
enabled, then enabling all
access gives the guest languages full control over the host process. Otherwise, Java
security manager
is in control of restricting the privileges of
the polyglot context. If new privilege restrictions are added to the polyglot API, then
they will default to full access. If all access is enabled then certain privileges may
still be disabled by configuring it explicitly using the builder.
Grants full access to the following privileges by default:
creation
and use of new threads.
host classes
.
host classes
by adding
entries to the class path.
bindings
.
IO operations
on host system.
enabled
- true
for all access by default.public Context.Builder allowHostClassLoading(boolean enabled)
all access
is set to
true
, then the host class loading is enabled if it is not disallowed
explicitly. For host class loading to be useful, IO
operations
and host access
need to be allowed as well.public Context.Builder hostClassFilter(Predicate<String> classFilter)
true
, then the class is accessible,
otherwise it is not accessible and throws a guest language error when accessed. In order
to have an effect, Context.Builder.allowHostAccess(boolean)
or Context.Builder.allowAllAccess(boolean)
needs to be set to true
.classFilter
- a predicate that returns true
or false
for a
java qualified class name.public Context.Builder option(String key, String value)
context
. By default, any options for the
engine
, language
or
instrument
can be set for a context. If an
explicit engine
is set for the context, then only language
options can be set. Instrument and engine options can be set exclusively on the explicit
engine instance. If a language option is set for the context and the engine, then the
option of the context is going to take precedence.
If one of the set option keys or values is invalid, then an
IllegalArgumentException
is thrown when the context is built
.
The given key and value must not be null
.
To specify an option for the engine.
public Context.Builder options(Map<String,String> options)
options
using a map. All
values of the provided map must be non-null.options
- a map options.To set a single option.
public Context.Builder arguments(String language, String[] args)
context
.
Application arguments are typically made available to guest language implementations. It
depends on the language if and how they are accessible within the
evaluated
guest language scripts. Passing no arguments to a
language is equivalent to providing an empty arguments array.language
- the language id of the primary language.args
- an array of arguments passed to the guest language program.IllegalArgumentException
- if an invalid language id was specified.public Context.Builder allowIO(boolean enabled)
true
, allows guest language to perform unrestricted IO operations on host
system. Default is false
. If all access
is
set to true
, then IO is enabled if not allowed explicitly.enabled
- true
to enable Input/OutputContext.Builder
public Context.Builder fileSystem(FileSystem fileSystem)
FileSystem
.fileSystem
- the file system to be installedContext.Builder
public Context.Builder serverTransport(MessageTransport serverTransport)
MessageTransport
to virtualize a transport of messages to a
server endpoint.
MessageTransport.open(java.net.URI, org.graalvm.polyglot.io.MessageEndpoint)
corresponds to accept of a server socket.serverTransport
- an implementation of message transport interceptorMessageTransport
public Context.Builder logHandler(Handler logHandler)
Handler
. The logger's Level
configuration is done
using the Context's options
. The level option key has the
following format: log.languageId.loggerName.level
or
log.instrumentId.loggerName.level
. The value is either the name of a pre-defined
Level
constant or a numeric Level
value. If not explicitly set in
options, the level is inherited from the parent logger.
Examples of setting log level options:
builder.option("log.level","FINE");
sets the FINE level
to all
TruffleLogger
s.
builder.option("log.js.level","FINE");
sets the FINE level
to
JavaScript TruffleLogger
s.
builder.option("log.js.com.oracle.truffle.js.parser.JavaScriptLanguage.level","FINE");
sets the FINE level
to TruffleLogger
for the
JavaScriptLanguage
class.
If the logHandler
is not set on Engine
nor on Context
, the log
messages are printed to Context's error output stream
.
logHandler
- the Handler
to use for logging in built Context
. The
passed logHandler
is closed when the context is closed
.Context.Builder
public Context.Builder logHandler(OutputStream logOut)
Handler
using given OutputStream
. The logger's
Level
configuration is done using the Context's
options
. The level option key has the following format:
log.languageId.loggerName.level
or log.instrumentId.loggerName.level
. The
value is either the name of pre-defined Level
constant or a numeric Level
value. If not explicitly set in options the level is inherited from the parent logger.
Examples of setting log level options:
builder.option("log.level","FINE");
sets the FINE level
to all
TruffleLogger
s.
builder.option("log.js.level","FINE");
sets the FINE level
to
JavaScript TruffleLogger
s.
builder.option("log.js.com.oracle.truffle.js.parser.JavaScriptLanguage.level","FINE");
sets the FINE level
to TruffleLogger
for the
JavaScriptLanguage
class.
If the logHandler
is not set on Engine
nor on Context
the log
messages are printed to Context's standard output
stream
.
logOut
- the OutputStream
to use for logging in built Context
. The
passed logOut
stream is closed when the context is
closed
.Context.Builder
public Context build()