java.lang.Object
org.praxislive.base.AbstractRoot.Delegate
- Enclosing class:
AbstractRoot
An abstract delegate class that may be attached to this Root to drive it
from another source (eg. audio callback or UI event queue). Subclasses
should call
doUpdate(long) regularly to update the clock time
and process pending tasks.
The delegate should prefer calling
doTimedPoll(long, java.util.concurrent.TimeUnit) to thread
sleeping or other timing mechanisms where possible so that incoming
packets and tasks are processed while waiting.
If the other source provides a mechanism for invoking tasks
asynchronously (eg. EventQueue.invokeLater(Runnable task)) it should
override onQueueReceipt() to asynchronously trigger
doPollQueue() to process tasks and packets between updates.
If the other source driving this delegate requires a new Thread to run
on, it should obtain it from getThreadFactory()
-
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedDelegate()Create a Delegate with the default configuration.protectedCreate a Delegate subclass with the provided configuration. -
Method Summary
Modifier and TypeMethodDescriptionprotected final voidPoll the queue, running any available tasks and dispatching any packets with a timecode before the current Root time.protected final voiddoTimedPoll(long time, TimeUnit unit) Wait up to the given time for a queue notification, running any available tasks and dispatching any packets with a timecode before the current Root time.protected final booleandoUpdate(long time) Update the Root time and process tasks, inbound calls and clock listeners.protected final ThreadFactoryGet a thread factory for creating any new threads required by the delegate.protected booleanCheck whether the currently executing thread is the current thread executing the delegate.protected voidCalled when a new PacketAbstractRoot.Controller.submitPacket(org.praxislive.core.Packet)or taskAbstractRoot.invokeLater(java.lang.Runnable)is submitted.
-
Constructor Details
-
Delegate
protected Delegate()Create a Delegate with the default configuration. -
Delegate
Create a Delegate subclass with the provided configuration.- Parameters:
config- delegate configuration
-
-
Method Details
-
doUpdate
protected final boolean doUpdate(long time) Update the Root time and process tasks, inbound calls and clock listeners.- Parameters:
time- new clock time (directly from or related toRootHub.getClock()- Returns:
- false if the Root has been terminated or the delegate detached
-
doPollQueue
protected final void doPollQueue()Poll the queue, running any available tasks and dispatching any packets with a timecode before the current Root time. -
doTimedPoll
Wait up to the given time for a queue notification, running any available tasks and dispatching any packets with a timecode before the current Root time.- Parameters:
time-unit-- Throws:
InterruptedException
-
getThreadFactory
Get a thread factory for creating any new threads required by the delegate.- Returns:
- thread factory for all required threads
-
onQueueReceipt
protected void onQueueReceipt()Called when a new PacketAbstractRoot.Controller.submitPacket(org.praxislive.core.Packet)or taskAbstractRoot.invokeLater(java.lang.Runnable)is submitted. By default signals the thread waiting ondoTimedPoll(long, java.util.concurrent.TimeUnit). Can be overridden to perform other notification, but if this implementation is not called then timed polling will not work. -
isRootThread
protected boolean isRootThread()Check whether the currently executing thread is the current thread executing the delegate. The AbstractRoot ThreadContext implementation will delegate to this method if the current thread is not inside an update. The default implementation checks whether the current thread is the last thread that calleddoUpdate(long)ordoPollQueue(). Implementations may want to override this, eg. to check if the current thread is a UI update thread. As a guide, this method should return true if blocking the current thread would block the root from executing.- Returns:
- current thread is root thread
- See Also:
-