Class AbstractRoot

java.lang.Object
org.praxislive.base.AbstractRoot
All Implemented Interfaces:
org.praxislive.core.Lookup.Provider, org.praxislive.core.Root
Direct Known Subclasses:
AbstractRootContainer

public abstract class AbstractRoot extends Object implements org.praxislive.core.Root
A general purpose base implementation of Root. By default uses a ScheduledExecutorService but allows for attaching custom AbstractRoot.Delegate implementations to drive from a thread of choice.
  • Constructor Details

    • AbstractRoot

      protected AbstractRoot()
      Default constructor.
  • Method Details

    • initialize

      public AbstractRoot.Controller initialize(String id, org.praxislive.core.RootHub hub)
      Specified by:
      initialize in interface org.praxislive.core.Root
    • getLookup

      public org.praxislive.core.Lookup getLookup()
      Specified by:
      getLookup in interface org.praxislive.core.Lookup.Provider
    • findService

      protected org.praxislive.core.ComponentAddress findService(Class<? extends org.praxislive.core.services.Service> service) throws org.praxislive.core.services.ServiceUnavailableException
      Find a Service address in the lookup.
      Parameters:
      service -
      Returns:
      service address
      Throws:
      org.praxislive.core.services.ServiceUnavailableException
    • getAddress

      protected final org.praxislive.core.ComponentAddress getAddress()
      Get the address of this Root. Only valid after initialization.
      Returns:
      address
    • getRootHub

      protected final org.praxislive.core.RootHub getRootHub()
      Get the RootHub this Root is installed in. Only valid after initialization.
      Returns:
      RootHub
    • getRouter

      protected final org.praxislive.core.PacketRouter getRouter()
      Get the PacketRouter for this Root. Only valid after initialization.
      Returns:
      router
    • getExecutionContext

      protected final org.praxislive.core.ExecutionContext getExecutionContext()
      Get the ExecutionContext for this Root. Only valid after initialization.
      Returns:
      execution context
    • getState

      protected AbstractRoot.State getState()
      Get the State of this Root.
      Returns:
      State
    • createController

      protected AbstractRoot.Controller createController()
      Method used to create the AbstractRoot.Controller during initialization. Subclasses may override to customize the Controller.
      Returns:
      Controller
    • createContext

      protected DefaultExecutionContext createContext(long initialTime)
      Method used to create the DefaultExecutionContext during initialization. Subclasses may override to customize the execution context.
      Parameters:
      initialTime - the current clock time of the hub
      Returns:
      execution context
    • createRouter

      protected org.praxislive.core.PacketRouter createRouter()
      Method used to create the PacketRouter during initialization. The default implementation directly calls RootHub.dispatch(org.praxislive.core.Packet). Subclasses may override to provide an alternative that eg. logs all messages.
      Returns:
      packet router
    • activating

      protected void activating()
      Hook called during activation of this Root, asynchronously after a call to
      invalid reference
      Controller#start(java.util.concurrent.ThreadFactory)
      . The default implementation does nothing.
    • terminating

      protected void terminating()
      Hook called during termination of this Root, asynchronously after a call to AbstractRoot.Controller.shutdown() or other cause of termination. The default implementation does nothing.
    • starting

      protected void starting()
      Hook called during a call to setRunning() if the previous state was AbstractRoot.State.ACTIVE_IDLE. The default implementation does nothing.
    • stopping

      protected void stopping()
      Hook called during a call to setIdle() if the previous state was AbstractRoot.State.ACTIVE_RUNNING. The default implementation does nothing.
    • update

      protected void update()
      Hook called regularly every time the internal time changes, after all ExecutionContext.ClockListener have been called. The default implementation does nothing.
    • processCall

      protected abstract void processCall(org.praxislive.core.Call call, org.praxislive.core.PacketRouter router)
      Method called to handle every received Call. The provided router should be used for all ongoing or return calls.
      Parameters:
      call -
      router -
    • setRunning

      protected final boolean setRunning()
      Set the Root state to AbstractRoot.State.ACTIVE_RUNNING. The state will only be changed, and starting() called, if the existing state is idle.
      Returns:
      true if the state has been set to running
    • setIdle

      protected final boolean setIdle()
      Set the Root state to AbstractRoot.State.ACTIVE_IDLE. The state will only be changed, and stopping() called, if the existing state is running.
      Returns:
      true if the state has been set to idle
    • attachDelegate

      protected final void attachDelegate(AbstractRoot.Delegate delegate)
      Attach a AbstractRoot.Delegate to this Root. Also calls interrupt().
      Parameters:
      delegate -
      Throws:
      IllegalStateException - if a delegate is already attached
    • detachDelegate

      protected final void detachDelegate(AbstractRoot.Delegate delegate)
      Detach the provide delegate (if it is attached). Also calls interrupt().
      Parameters:
      delegate -
    • interrupt

      protected final void interrupt()
      Interrupt the current update cycle, leaving pending calls or tasks to a subsequent update cycle.
    • invokeLater

      protected final boolean invokeLater(Runnable task)
      Submit a task to be run asynchronously on the main Root thread. The task is added to the same queue as incoming packets.
      Parameters:
      task -
      Returns:
      true if the task has been successfully submitted
    • delegateConfig

      protected static AbstractRoot.DelegateConfiguration delegateConfig()
      Create a AbstractRoot.DelegateConfiguration object for passing up to the constructor when creating a AbstractRoot.Delegate subclass.
      Returns:
      delegate configuration