Class AbstractRoot.Controller

java.lang.Object
org.praxislive.base.AbstractRoot.Controller
All Implemented Interfaces:
Root.Controller
Enclosing class:
AbstractRoot

protected class AbstractRoot.Controller extends Object implements Root.Controller
Implementation of Root.Controller.
  • Constructor Details

    • Controller

      protected Controller()
  • Method Details

    • submitPacket

      public boolean submitPacket(Packet packet)
      Description copied from interface: Root.Controller
      Deliver a Packet to this Root. This method is intended to be called from a thread other than the primary thread of the Root. It will add the packet to a queue and return immediately - this method will never block as it may be called from the thread of another Root.

      This method will return true if the Packet can be handled (see eg. BlockingQueue::offer)

      Specified by:
      submitPacket in interface Root.Controller
      Parameters:
      packet - message (see Packet / Call) to handle
      Returns:
      true if the packet can be handled
    • start

      public void start(Lookup lookup)
      Description copied from interface: Root.Controller
      Start the Root. Controller implementations will ensure that this method can only be invoked once.

      The lookup may contain services that the root may utilise - eg. a shared ScheduledExecutorService. This allows services to be controlled on a per-root basis, rather than relying on the hub lookup.

      Specified by:
      start in interface Root.Controller
      Parameters:
      lookup - optional services for the root to use
    • shutdown

      public void shutdown()
      Description copied from interface: Root.Controller
      Signal the Root to be shutdown. This method is intended to be called asynchronously and will return immediately - it will not wait for the Root to actually complete execution.
      Specified by:
      shutdown in interface Root.Controller
    • isAlive

      public boolean isAlive()
      Description copied from interface: Root.Controller
      Query whether the Root is alive - has been started and has not been signalled to shutdown. This method may return false even if the Root is still in the process of termination. If the caller needs to know when the Root has finished termination, use Root.Controller.awaitTermination(long, java.util.concurrent.TimeUnit).
      Specified by:
      isAlive in interface Root.Controller
      Returns:
      true if started and not signalled to shutdown
    • awaitTermination

      public void awaitTermination(long timeout, TimeUnit unit) throws InterruptedException, TimeoutException, ExecutionException
      Description copied from interface: Root.Controller
      Wait for the Root to fully terminate, freeing up all resources.
      Specified by:
      awaitTermination in interface Root.Controller
      Parameters:
      timeout - maximum time to wait
      unit - unit of timeout
      Throws:
      InterruptedException - if the current thread is interrupted
      TimeoutException - if the timeout is reached before termination
      ExecutionException - if the termination is the result of an exception
    • onQueueReceipt

      protected void onQueueReceipt()
      Called on receipt of a Packet (Call) or a Runnable task. The default implementation will call AbstractRoot.Delegate.onQueueReceipt() if a delegate is attached, or otherwise trigger an asynchronous poll of the queue.