Package ptolemy.actor.lib.jjs
Class NashornAccessorHostApplication.ActorSubstitute
- java.lang.Object
-
- ptolemy.actor.lib.jjs.NashornAccessorHostApplication.ActorSubstitute
-
- All Implemented Interfaces:
AccessorOrchestrator,Nameable
- Enclosing class:
- NashornAccessorHostApplication
public static class NashornAccessorHostApplication.ActorSubstitute extends java.lang.Object implements AccessorOrchestrator
Class that substitute for the JavaScript actor so that setTimeout, setInterval, and CapeCode modules work in a pure Nashorn host. This class provides an event loop that invokes callback functions. To start the event loop, calleventLoop(). To request that a callback be invoked, callinvokeCallback(Runnable)from any thread. The argument will be appended to a list of callbacks to be invoked, and the event loop thread will be notified. Callbacks will be executed in the same thread as the thread that callseventLoop().
-
-
Constructor Summary
Constructors Constructor Description ActorSubstitute(java.lang.String name)Construct an actor substitute instance.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidclearInterval(java.lang.Object timer)Clear the interval with the specified handle, if it has not already executed.voidclearTimeout(java.lang.Object timer)Clear the timeout with the specified handle, if it has not already executed.java.lang.Stringdescription()Return a description.voiderror(java.lang.String message)Report an error.voideventLoop()Start an event loop in a new thread that does not end untilwrapup()is called.NamedObjgetContainer()Return null.java.lang.StringgetDisplayName()Return the name specified in the constructor.java.lang.StringgetFullName()Return the name specified in the constructor.java.lang.StringgetName()Return the name specified in the constructor.java.lang.StringgetName(NamedObj relativeTo)Return the name specified in the constructor.voidinvokeCallback(java.lang.Runnable function)Invoke the specified function as soon as possible, but after any currently executing or other pending callbacks have completed.voidlog(java.lang.String message)Print a message.java.util.TimersetInterval(java.lang.Runnable function, long periodMS)Specify a function to invoke as a callback periodically with the specified period (in milliseconds).voidsetName(java.lang.String name)Set the name.java.util.TimersetTimeout(java.lang.Runnable function, long timeMS)Specify a function to invoke as a callback after the specified time (in milliseconds) has elapsed.voidsetTopLevelAccessor(jdk.nashorn.api.scripting.ScriptObjectMirror accessor)Specify a top-level accessor to associate with this orchestrator and start an event loop to invoke callbacks.voidwrapup()Stop the event loop, canceling all pending callbacks.
-
-
-
Method Detail
-
clearInterval
public void clearInterval(java.lang.Object timer) throws IllegalActionExceptionClear the interval with the specified handle, if it has not already executed.- Specified by:
clearIntervalin interfaceAccessorOrchestrator- Parameters:
timer- The timeout handle.- Throws:
IllegalActionException- If the handle is invalid.- See Also:
setTimeout(Runnable, long),setInterval(Runnable, long)
-
clearTimeout
public void clearTimeout(java.lang.Object timer) throws IllegalActionExceptionClear the timeout with the specified handle, if it has not already executed.- Specified by:
clearTimeoutin interfaceAccessorOrchestrator- Parameters:
timer- The timeout handle.- Throws:
IllegalActionException- If the handle is invalid.- See Also:
setTimeout(Runnable, long),setInterval(Runnable, long)
-
description
public java.lang.String description() throws IllegalActionExceptionReturn a description.- Specified by:
descriptionin interfaceNameable- Returns:
- A description of this object.
- Throws:
IllegalActionException- If there is a problem accessing subcomponents of the object.
-
error
public void error(java.lang.String message)
Report an error.- Specified by:
errorin interfaceAccessorOrchestrator- Parameters:
message- The error message.
-
eventLoop
public void eventLoop()
Start an event loop in a new thread that does not end untilwrapup()is called.
-
getContainer
public NamedObj getContainer()
Return null.- Specified by:
getContainerin interfaceNameable- Returns:
- The container.
-
getDisplayName
public java.lang.String getDisplayName()
Return the name specified in the constructor.- Specified by:
getDisplayNamein interfaceNameable- Returns:
- A name to present to the user.
-
getFullName
public java.lang.String getFullName()
Return the name specified in the constructor.- Specified by:
getFullNamein interfaceNameable- Returns:
- The full name of the object.
-
getName
public java.lang.String getName()
Return the name specified in the constructor.- Specified by:
getNamein interfaceNameable- Returns:
- The name of the object.
- See Also:
setName(String)
-
getName
public java.lang.String getName(NamedObj relativeTo) throws InvalidStateException
Return the name specified in the constructor.- Specified by:
getNamein interfaceNameable- Parameters:
relativeTo- The object relative to which you want the name.- Returns:
- A string of the form "name2...nameN".
- Throws:
InvalidStateException- If a recursive structure is encountered, where this object directly or indirectly contains itself. Note that this is a runtime exception so it need not be declared explicitly.- See Also:
setName(String)
-
invokeCallback
public void invokeCallback(java.lang.Runnable function)
Description copied from interface:AccessorOrchestratorInvoke the specified function as soon as possible, but after any currently executing or other pending callbacks have completed.- Specified by:
invokeCallbackin interfaceAccessorOrchestrator- Parameters:
function- The function to invoke.
-
log
public void log(java.lang.String message)
Print a message.- Specified by:
login interfaceAccessorOrchestrator- Parameters:
message- The message to be printed.
-
setName
public void setName(java.lang.String name)
Set the name.
-
setInterval
public java.util.Timer setInterval(java.lang.Runnable function, long periodMS)Specify a function to invoke as a callback periodically with the specified period (in milliseconds).- Specified by:
setIntervalin interfaceAccessorOrchestrator- Parameters:
function- The function to invoke.periodMS- The period in milliseconds.- Returns:
- handle A handle that can be used to cancel the timeout.
- See Also:
AccessorOrchestrator.clearTimeout(Object)
-
setTimeout
public java.util.Timer setTimeout(java.lang.Runnable function, long timeMS)Specify a function to invoke as a callback after the specified time (in milliseconds) has elapsed.- Specified by:
setTimeoutin interfaceAccessorOrchestrator- Parameters:
function- The function to invoke.timeMS- The time in milliseconds.- Returns:
- handle A handle that can be used to cancel the timeout.
- See Also:
AccessorOrchestrator.clearTimeout(Object)
-
setTopLevelAccessor
public void setTopLevelAccessor(jdk.nashorn.api.scripting.ScriptObjectMirror accessor)
Specify a top-level accessor to associate with this orchestrator and start an event loop to invoke callbacks. This implementation ignores the accessor argument.- Parameters:
accessor- A top-level accessor.
-
wrapup
public void wrapup() throws IllegalActionExceptionStop the event loop, canceling all pending callbacks.- Specified by:
wrapupin interfaceAccessorOrchestrator- Throws:
IllegalActionException- If there is a problem wrapping up.
-
-