java.lang.Object
org.praxislive.base.AbstractRoot
- All Implemented Interfaces:
org.praxislive.core.Lookup.Provider,org.praxislive.core.Root
- Direct Known Subclasses:
AbstractRootContainer
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.-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprotected classImplementation of Root.Controller.protected classAn abstract delegate class that may be attached to this Root to drive it from another source (eg. audio callback or UI event queue).protected static final classA configuration object used for customizingAbstractRoot.Delegatebehaviour in a subclass.protected static enumThe possible states this implementation may transition through. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected voidHook called during activation of this Root, asynchronously after a call to.invalid reference
Controller#start(java.util.concurrent.ThreadFactory)protected final voidattachDelegate(AbstractRoot.Delegate delegate) Attach aAbstractRoot.Delegateto this Root.protected DefaultExecutionContextcreateContext(long initialTime) Method used to create theDefaultExecutionContextduring initialization.protected AbstractRoot.ControllerMethod used to create theAbstractRoot.Controllerduring initialization.protected org.praxislive.core.PacketRouterMethod used to create thePacketRouterduring initialization.protected static AbstractRoot.DelegateConfigurationCreate aAbstractRoot.DelegateConfigurationobject for passing up to the constructor when creating aAbstractRoot.Delegatesubclass.protected final voiddetachDelegate(AbstractRoot.Delegate delegate) Detach the provide delegate (if it is attached).protected org.praxislive.core.ComponentAddressfindService(Class<? extends org.praxislive.core.services.Service> service) Find a Service address in the lookup.protected final org.praxislive.core.ComponentAddressGet the address of this Root.protected final org.praxislive.core.ExecutionContextGet theExecutionContextfor this Root.org.praxislive.core.Lookupprotected final org.praxislive.core.RootHubGet theRootHubthis Root is installed in.protected final org.praxislive.core.PacketRouterGet thePacketRouterfor this Root.protected AbstractRoot.StategetState()Get the State of this Root.initialize(String id, org.praxislive.core.RootHub hub) protected final voidInterrupt the current update cycle, leaving pending calls or tasks to a subsequent update cycle.protected final booleaninvokeLater(Runnable task) Submit a task to be run asynchronously on the main Root thread.protected abstract voidprocessCall(org.praxislive.core.Call call, org.praxislive.core.PacketRouter router) Method called to handle every receivedCall.protected final booleansetIdle()Set the Root state toAbstractRoot.State.ACTIVE_IDLE.protected final booleanSet the Root state toAbstractRoot.State.ACTIVE_RUNNING.protected voidstarting()Hook called during a call tosetRunning()if the previous state wasAbstractRoot.State.ACTIVE_IDLE.protected voidstopping()Hook called during a call tosetIdle()if the previous state wasAbstractRoot.State.ACTIVE_RUNNING.protected voidHook called during termination of this Root, asynchronously after a call toAbstractRoot.Controller.shutdown()or other cause of termination.protected voidupdate()Hook called regularly every time the internal time changes, after allExecutionContext.ClockListenerhave been called.
-
Constructor Details
-
AbstractRoot
protected AbstractRoot()Default constructor.
-
-
Method Details
-
initialize
- Specified by:
initializein interfaceorg.praxislive.core.Root
-
getLookup
public org.praxislive.core.Lookup getLookup()- Specified by:
getLookupin interfaceorg.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 theRootHubthis Root is installed in. Only valid after initialization.- Returns:
- RootHub
-
getRouter
protected final org.praxislive.core.PacketRouter getRouter()Get thePacketRouterfor this Root. Only valid after initialization.- Returns:
- router
-
getExecutionContext
protected final org.praxislive.core.ExecutionContext getExecutionContext()Get theExecutionContextfor this Root. Only valid after initialization.- Returns:
- execution context
-
getState
Get the State of this Root.- Returns:
- State
-
createController
Method used to create theAbstractRoot.Controllerduring initialization. Subclasses may override to customize the Controller.- Returns:
- Controller
-
createContext
Method used to create theDefaultExecutionContextduring 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 thePacketRouterduring initialization. The default implementation directly callsRootHub.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. The default implementation does nothing.invalid reference
Controller#start(java.util.concurrent.ThreadFactory) -
terminating
protected void terminating()Hook called during termination of this Root, asynchronously after a call toAbstractRoot.Controller.shutdown()or other cause of termination. The default implementation does nothing. -
starting
protected void starting()Hook called during a call tosetRunning()if the previous state wasAbstractRoot.State.ACTIVE_IDLE. The default implementation does nothing. -
stopping
protected void stopping()Hook called during a call tosetIdle()if the previous state wasAbstractRoot.State.ACTIVE_RUNNING. The default implementation does nothing. -
update
protected void update()Hook called regularly every time the internal time changes, after allExecutionContext.ClockListenerhave 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 receivedCall. The provided router should be used for all ongoing or return calls.- Parameters:
call-router-
-
setRunning
protected final boolean setRunning()Set the Root state toAbstractRoot.State.ACTIVE_RUNNING. The state will only be changed, andstarting()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 toAbstractRoot.State.ACTIVE_IDLE. The state will only be changed, andstopping()called, if the existing state is running.- Returns:
- true if the state has been set to idle
-
attachDelegate
Attach aAbstractRoot.Delegateto this Root. Also callsinterrupt().- Parameters:
delegate-- Throws:
IllegalStateException- if a delegate is already attached
-
detachDelegate
Detach the provide delegate (if it is attached). Also callsinterrupt().- Parameters:
delegate-
-
interrupt
protected final void interrupt()Interrupt the current update cycle, leaving pending calls or tasks to a subsequent update cycle. -
invokeLater
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
Create aAbstractRoot.DelegateConfigurationobject for passing up to the constructor when creating aAbstractRoot.Delegatesubclass.- Returns:
- delegate configuration
-