Class 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, call eventLoop(). To request that a callback be invoked, call invokeCallback(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 calls eventLoop().
    • 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 until wrapup() 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.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • ActorSubstitute

        public ActorSubstitute​(java.lang.String name)
        Construct an actor substitute instance.
        Parameters:
        name - The name of the actor substitute instance.
    • Method Detail

      • error

        public void error​(java.lang.String message)
        Report an error.
        Specified by:
        error in interface AccessorOrchestrator
        Parameters:
        message - The error message.
      • eventLoop

        public void eventLoop()
        Start an event loop in a new thread that does not end until wrapup() is called.
      • getDisplayName

        public java.lang.String getDisplayName()
        Return the name specified in the constructor.
        Specified by:
        getDisplayName in interface Nameable
        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 interface Nameable
        Returns:
        The full name of the object.
      • getName

        public java.lang.String getName()
        Return the name specified in the constructor.
        Specified by:
        getName in interface Nameable
        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 interface Nameable
        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 interface AccessorOrchestrator
        Parameters:
        function - The function to invoke.
      • log

        public void log​(java.lang.String message)
        Print a message.
        Specified by:
        log in interface AccessorOrchestrator
        Parameters:
        message - The message to be printed.
      • setName

        public void setName​(java.lang.String name)
        Set the name.
        Specified by:
        setName in interface Nameable
        Parameters:
        name - The name to use in reporting errors.
        See Also:
        getName()
      • 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 interface AccessorOrchestrator
        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 interface AccessorOrchestrator
        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.