public final class RingoWorker extends Object
| Constructor and Description |
|---|
RingoWorker(RhinoEngine engine)
Create a new ringo worker
|
| Modifier and Type | Method and Description |
|---|---|
void |
cancel(Future<?> future)
Cancel a scheduled call.
|
long |
countScheduledTasks()
Count the number of scheduled calls in this worker.
|
Object |
evaluateScript(org.mozilla.javascript.Context cx,
ReloadableScript script,
org.mozilla.javascript.Scriptable scope)
Evaluate a script within a given scope.
|
RhinoEngine |
getEngine()
Get the worker's engine.
|
org.mozilla.javascript.Function |
getErrorListener()
Get the current error listener for uncaught errors in this worker
|
List<ScriptError> |
getErrors()
Get a list of errors encountered in the last invocation of this worker.
|
Object |
invoke(Object module,
Object function,
Object... args)
Invoke the function specified by `function` in module `module` with the
given arguments on the current thread.
|
boolean |
isActive()
Returns true if this worker is currently running.
|
boolean |
isReloading()
Returns true if this worker will reload modified modules between
invocations.
|
org.mozilla.javascript.Scriptable |
loadModule(org.mozilla.javascript.Context cx,
String moduleName,
org.mozilla.javascript.Scriptable loadingScope)
Load a Javascript module into a module scope.
|
Future<Object> |
loadModuleInWorkerThread(String module)
Load a module in the worker's event loop thread, returning a future for
the loaded module.
|
protected void |
registerModule(Resource resource,
org.mozilla.javascript.Scriptable module)
Add a resource/scope pair to our map of known up-to-date modules.
|
void |
release()
Release the worker, returning it to the engine's worker pool.
|
void |
releaseWhenDone()
Schedule a task that will release this worker when the current task
is finished, returning it back into the engine's worker pool.
|
ScheduledFuture<Object> |
schedule(long delay,
Object module,
Object function,
Object... args)
Submit a function to be invoked on the worker's event loop thread
with the given delay and arguments, returning a future for the result.
|
ScheduledFuture<?> |
scheduleInterval(long interval,
Object module,
Object function,
Object... args)
Submit a function to be invoked repeatedly with the given interval
on the worker's event loop thread, returning a future for the result.
|
void |
setErrorListener(org.mozilla.javascript.Function errorListener)
Set the error listener to handle uncaught errors in this worker
|
void |
setReloading(boolean reload)
Enable or disable reloading of modified modules for this worker.
|
void |
shutdown()
Immediately shut down this worker's event loop.
|
Future<Object> |
submit(Object module,
Object function,
Object... args)
Submit a function to be invoked on the worker's event loop thread and
return a future for the result.
|
String |
toString()
Returns a string representation of the worker.
|
public RingoWorker(RhinoEngine engine)
engine - the enginepublic String toString()
public Object invoke(Object module, Object function, Object... args) throws NoSuchMethodException, IOException
Invoke the function specified by `function` in module `module` with the given arguments on the current thread. If this worker is currently busy running another thread this method will block until the other thread is done.
Note that if module specifies a module id, the function is looked up in the top level module scope, not the module's exports object.
module - the module id or objectfunction - the function name or objectargs - optional arguments to pass to the functionNoSuchMethodException - if the function could not be foundIOException - if loading the module caused an IO errorpublic Future<Object> submit(Object module, Object function, Object... args)
Submit a function to be invoked on the worker's event loop thread and return a future for the result.
This method always returns immediately.
module - the module id or objectfunction - the function name or objectargs - optional arguments to pass to the functionpublic ScheduledFuture<Object> schedule(long delay, Object module, Object function, Object... args)
Submit a function to be invoked on the worker's event loop thread with the given delay and arguments, returning a future for the result.
This method always returns immediately.
delay - the delay in millisecondsmodule - the module id or objectfunction - the function name or objectargs - optional arguments to pass to the functionpublic ScheduledFuture<?> scheduleInterval(long interval, Object module, Object function, Object... args)
Submit a function to be invoked repeatedly with the given interval on the worker's event loop thread, returning a future for the result.
This method always returns immediately.
interval - the interval in millisecondsmodule - the module id or objectfunction - the function name or objectargs - optional arguments to pass to the functionpublic Future<Object> loadModuleInWorkerThread(String module)
module - the module idpublic void cancel(Future<?> future)
future - the futurepublic org.mozilla.javascript.Scriptable loadModule(org.mozilla.javascript.Context cx,
String moduleName,
org.mozilla.javascript.Scriptable loadingScope)
throws IOException
cx - the current contextmoduleName - the module nameloadingScope - the scope requesting the moduleIOException - indicates that in input/output related error occurredprotected void registerModule(Resource resource, org.mozilla.javascript.Scriptable module)
resource - a resourcemodule - the module scopepublic Object evaluateScript(org.mozilla.javascript.Context cx, ReloadableScript script, org.mozilla.javascript.Scriptable scope) throws IOException
cx - the current contextscript - the scriptscope - the scopeIOException - an I/O related error occurredpublic boolean isReloading()
public void setReloading(boolean reload)
reload - true to enable module reloadingpublic org.mozilla.javascript.Function getErrorListener()
public void setErrorListener(org.mozilla.javascript.Function errorListener)
errorListener - the error listenerpublic RhinoEngine getEngine()
public List<ScriptError> getErrors()
public long countScheduledTasks()
public boolean isActive()
public void shutdown()
public void release()
public void releaseWhenDone()
Copyright © 2016. All rights reserved.