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 void
clearInterval(java.lang.Object timer)
Clear the interval with the specified handle, if it has not already executed.void
clearTimeout(java.lang.Object timer)
Clear the timeout with the specified handle, if it has not already executed.java.lang.String
description()
Return a description.void
error(java.lang.String message)
Report an error.void
eventLoop()
Start an event loop in a new thread that does not end untilwrapup()
is called.NamedObj
getContainer()
Return null.java.lang.String
getDisplayName()
Return the name specified in the constructor.java.lang.String
getFullName()
Return the name specified in the constructor.java.lang.String
getName()
Return the name specified in the constructor.java.lang.String
getName(NamedObj relativeTo)
Return the name specified in the constructor.void
invokeCallback(java.lang.Runnable function)
Invoke the specified function as soon as possible, but after any currently executing or other pending callbacks have completed.void
log(java.lang.String message)
Print a message.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).void
setName(java.lang.String name)
Set the name.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.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.void
wrapup()
Stop the event loop, canceling all pending callbacks.
-
-
-
Method Detail
-
clearInterval
public void clearInterval(java.lang.Object timer) throws IllegalActionException
Clear the interval with the specified handle, if it has not already executed.- Specified by:
clearInterval
in 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 IllegalActionException
Clear the timeout with the specified handle, if it has not already executed.- Specified by:
clearTimeout
in 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 IllegalActionException
Return a description.- Specified by:
description
in 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:
error
in 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:
getContainer
in interfaceNameable
- Returns:
- The container.
-
getDisplayName
public java.lang.String getDisplayName()
Return the name specified in the constructor.- Specified by:
getDisplayName
in interfaceNameable
- Returns:
- A name to present to the user.
-
getFullName
public java.lang.String getFullName()
Return the name specified in the constructor.- Specified by:
getFullName
in interfaceNameable
- Returns:
- The full name of the object.
-
getName
public java.lang.String getName()
Return the name specified in the constructor.- Specified by:
getName
in 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:
getName
in 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:AccessorOrchestrator
Invoke the specified function as soon as possible, but after any currently executing or other pending callbacks have completed.- Specified by:
invokeCallback
in interfaceAccessorOrchestrator
- Parameters:
function
- The function to invoke.
-
log
public void log(java.lang.String message)
Print a message.- Specified by:
log
in 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:
setInterval
in 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:
setTimeout
in 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 IllegalActionException
Stop the event loop, canceling all pending callbacks.- Specified by:
wrapup
in interfaceAccessorOrchestrator
- Throws:
IllegalActionException
- If there is a problem wrapping up.
-
-