public class ScriptRunner extends Object implements NodeRuntime, Callable<ScriptStatus>
| Modifier and Type | Class and Description |
|---|---|
class |
ScriptRunner.Activity |
| Modifier and Type | Field and Description |
|---|---|
protected AbstractProcess |
process |
static String |
RUNNER |
static String |
TIMEOUT_TIMESTAMP_KEY |
| Constructor and Description |
|---|
ScriptRunner(NodeScript so,
NodeEnvironment env,
Sandbox sandbox,
File scriptFile,
String[] args) |
ScriptRunner(NodeScript so,
NodeEnvironment env,
Sandbox sandbox,
String[] args,
boolean forceRepl) |
ScriptRunner(NodeScript so,
NodeEnvironment env,
Sandbox sandbox,
String scriptName,
String script,
String[] args) |
| Modifier and Type | Method and Description |
|---|---|
void |
awaitInitialization()
We use this when spawning child scripts to avoid sending them messages before they are ready.
|
void |
cacheInternalModule(String name,
Object module) |
void |
cacheModule(String name,
NativeModule.ModuleImpl module) |
ScriptStatus |
call()
Execute the script.
|
void |
clearErrno() |
void |
close() |
Future<Boolean> |
createTimedTask(Runnable r,
long delay,
TimeUnit unit,
boolean repeating,
Object domain)
This is a more generic way of creating a timer that can be used in the kernel, and which
works even if we are not in the main thread.
|
ScriptRunner.Activity |
createTimer(long delay,
boolean repeating,
long repeatInterval,
ScriptTask task,
org.mozilla.javascript.Scriptable scope)
This method puts the task directly on the timer queue, which is unsynchronized.
|
void |
enqueueCallback(org.mozilla.javascript.Function f,
org.mozilla.javascript.Scriptable scope,
org.mozilla.javascript.Scriptable thisObj,
Object[] args)
This method uses a concurrent queue so it may be called from any thread.
|
void |
enqueueCallback(org.mozilla.javascript.Function f,
org.mozilla.javascript.Scriptable scope,
org.mozilla.javascript.Scriptable thisObj,
Object domain,
Object[] args)
This method uses a concurrent queue so it may be called from any thread.
|
void |
enqueueIpc(org.mozilla.javascript.Context cx,
Object message,
TriremeProcess child)
This method is used by the "child_process" module when sending an IPC message between child processes
in the same JVM.
|
void |
enqueueTask(ScriptTask task)
This method uses a concurrent queue so it may be called from any thread.
|
void |
enqueueTask(ScriptTask task,
Object domain)
This method uses a concurrent queue so it may be called from any thread.
|
void |
executeCallback(org.mozilla.javascript.Context cx,
Object[] args,
org.mozilla.javascript.Function function,
org.mozilla.javascript.Scriptable thisObj)
Immediately execute the specified callback.
|
void |
executeScriptTask(Runnable r,
Object domain) |
void |
executeTicks(org.mozilla.javascript.Context cx)
Execute ticks as defined by process.nextTick() and anything put on the queue from Java code.
|
ExecutorService |
getAsyncPool()
This thread pool is a thread pool that has a fixed maximum size and a queue.
|
Object |
getCachedInternalModule(String name)
Return a module that is used internally and exposed by "process.binding".
|
NativeModule.ModuleImpl |
getCachedModule(String name)
Return a module that was created implicitly or by the "native module"
|
Object |
getDomain() |
NodeEnvironment |
getEnvironment()
Return the Environment used to create this script.
|
Object |
getErrno() |
BasicFilesystem |
getFilesystem() |
ScriptFuture |
getFuture() |
long |
getLoopTimestamp() |
NativeModule.NativeImpl |
getNativeModule() |
NetworkPolicy |
getNetworkPolicy() |
TriremeProcess |
getParentProcess() |
PathTranslator |
getPathTranslator() |
AbstractProcess |
getProcess() |
AbstractModuleRegistry |
getRegistry() |
Sandbox |
getSandbox()
Return the sandbox used to limit script execution, or null if none was set
|
NodeScript |
getScriptObject()
Return the "NodeScript" used to create this script.
|
org.mozilla.javascript.Scriptable |
getScriptScope() |
Selector |
getSelector() |
OutputStream |
getStderr() |
InputStream |
getStdin() |
OutputStream |
getStdout() |
ExecutorService |
getUnboundedPool()
This thread pool is a "cached thread pool" with no maximum size, which means that any task submitted will
run in its own thread until it completes.
|
String |
getWorkingDirectory() |
Object |
initializeModule(String modName,
AbstractModuleRegistry.ModuleType type,
org.mozilla.javascript.Context cx,
org.mozilla.javascript.Scriptable scope)
Initialize a native module implemented in Java code.
|
boolean |
isNativeModule(String name)
This is where we load native modules.
|
void |
pin() |
void |
registerCloseable(Closeable c) |
Object |
require(String modName,
org.mozilla.javascript.Context cx)
This is used internally when one native module depends on another.
|
Object |
requireInternal(String modName,
org.mozilla.javascript.Context cx) |
String |
reverseTranslatePath(String path)
Given a file path, return what the path would be within the Node environment.
|
protected ScriptStatus |
runScript(org.mozilla.javascript.Context cx) |
void |
setErrno(String err) |
void |
setFuture(ScriptFuture future) |
void |
setParentProcess(TriremeProcess parentProcess) |
void |
setRegistry(AbstractModuleRegistry registry) |
void |
setWorkingDirectory(String wd) |
File |
translatePath(String path)
Translate a path based on the root.
|
void |
unPin() |
void |
unregisterCloseable(Closeable c) |
public static final String RUNNER
public static final String TIMEOUT_TIMESTAMP_KEY
protected AbstractProcess process
public ScriptRunner(NodeScript so, NodeEnvironment env, Sandbox sandbox, File scriptFile, String[] args)
public ScriptRunner(NodeScript so, NodeEnvironment env, Sandbox sandbox, String scriptName, String script, String[] args)
public ScriptRunner(NodeScript so, NodeEnvironment env, Sandbox sandbox, String[] args, boolean forceRepl)
public void close()
public void setFuture(ScriptFuture future)
public ScriptFuture getFuture()
public NodeEnvironment getEnvironment()
NodeRuntimegetEnvironment in interface NodeRuntimepublic long getLoopTimestamp()
public AbstractModuleRegistry getRegistry()
public void setRegistry(AbstractModuleRegistry registry)
public Sandbox getSandbox()
NodeRuntimegetSandbox in interface NodeRuntimepublic NetworkPolicy getNetworkPolicy()
getNetworkPolicy in interface GenericNodeRuntimepublic NodeScript getScriptObject()
NodeRuntimegetScriptObject in interface NodeRuntimepublic String getWorkingDirectory()
public void setWorkingDirectory(String wd) throws IOException
IOExceptionpublic org.mozilla.javascript.Scriptable getScriptScope()
public NativeModule.NativeImpl getNativeModule()
public Selector getSelector()
getSelector in interface GenericNodeRuntimepublic ExecutorService getAsyncPool()
getAsyncPool in interface GenericNodeRuntimepublic ExecutorService getUnboundedPool()
getUnboundedPool in interface GenericNodeRuntimepublic BasicFilesystem getFilesystem()
public InputStream getStdin()
public OutputStream getStdout()
public OutputStream getStderr()
public TriremeProcess getParentProcess()
public AbstractProcess getProcess()
public void setParentProcess(TriremeProcess parentProcess)
public void awaitInitialization()
public File translatePath(String path)
translatePath in interface NodeRuntimepublic String reverseTranslatePath(String path) throws IOException
NodeRuntimereverseTranslatePath in interface NodeRuntimeIOExceptionpublic PathTranslator getPathTranslator()
public void enqueueCallback(org.mozilla.javascript.Function f,
org.mozilla.javascript.Scriptable scope,
org.mozilla.javascript.Scriptable thisObj,
Object[] args)
enqueueCallback in interface NodeRuntimef - Function to callscope - the scope where the function should runthisObj - the value of "this" where the function should run, or nullargs - arguments for the function, or nullpublic void enqueueCallback(org.mozilla.javascript.Function f,
org.mozilla.javascript.Scriptable scope,
org.mozilla.javascript.Scriptable thisObj,
Object domain,
Object[] args)
enqueueCallback in interface NodeRuntimef - Function to callscope - the scope where the function should runthisObj - the value of "this" where the function should run, or nulldomain - the domain where this callback should run -- should set to the current domainargs - arguments for the function, or nullpublic void enqueueTask(ScriptTask task)
enqueueTask in interface NodeRuntimepublic void enqueueTask(ScriptTask task, Object domain)
enqueueTask in interface NodeRuntimepublic void executeScriptTask(Runnable r, Object domain)
executeScriptTask in interface GenericNodeRuntimepublic void executeCallback(org.mozilla.javascript.Context cx,
Object[] args,
org.mozilla.javascript.Function function,
org.mozilla.javascript.Scriptable thisObj)
public void enqueueIpc(org.mozilla.javascript.Context cx,
Object message,
TriremeProcess child)
message - A JavaScript object, String, or Buffer. We will make a copy to prevent confusion.child - If null, deliver the message to the "process" object. Otherwise, deliver it to the
specified child.public Object getDomain()
getDomain in interface GenericNodeRuntimepublic ScriptRunner.Activity createTimer(long delay, boolean repeating, long repeatInterval, ScriptTask task, org.mozilla.javascript.Scriptable scope)
public Future<Boolean> createTimedTask(Runnable r, long delay, TimeUnit unit, boolean repeating, Object domain)
createTimedTask in interface GenericNodeRuntimepublic void pin()
pin in interface GenericNodeRuntimepublic void unPin()
unPin in interface GenericNodeRuntimepublic void setErrno(String err)
public void clearErrno()
public Object getErrno()
public void registerCloseable(Closeable c)
registerCloseable in interface GenericNodeRuntimepublic void unregisterCloseable(Closeable c)
unregisterCloseable in interface GenericNodeRuntimepublic ScriptStatus call() throws NodeException
call in interface Callable<ScriptStatus>NodeExceptionprotected ScriptStatus runScript(org.mozilla.javascript.Context cx)
public void executeTicks(org.mozilla.javascript.Context cx)
throws org.mozilla.javascript.RhinoException
org.mozilla.javascript.RhinoExceptionpublic Object initializeModule(String modName, AbstractModuleRegistry.ModuleType type, org.mozilla.javascript.Context cx, org.mozilla.javascript.Scriptable scope) throws InvocationTargetException, InstantiationException, IllegalAccessException
public Object require(String modName, org.mozilla.javascript.Context cx)
require in interface NodeRuntimepublic boolean isNativeModule(String name)
public NativeModule.ModuleImpl getCachedModule(String name)
public void cacheModule(String name, NativeModule.ModuleImpl module)
public Object getCachedInternalModule(String name)
Copyright © 2016 Apigee Corporation. All Rights Reserved.