- java.lang.Object
-
- org.praxislive.base.AbstractRoot.Delegate
-
- Enclosing class:
- AbstractRoot
protected abstract class AbstractRoot.Delegate extends Object
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 calldoUpdate(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 triggerdoPollQueue()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
Constructors Modifier Constructor Description protectedDelegate()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected voiddoPollQueue()Poll the queue, running any available tasks and dispatching any packets with a timecode before the current Root time.protected 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 booleandoUpdate(long time)Update the Root time and process tasks, inbound calls and clock listeners.protected ThreadFactorygetThreadFactory()Get a thread factory for creating any new threads required by the delegate.protected voidonQueueReceipt()Called when a new PacketAbstractRoot.Controller.submitPacket(org.praxislive.core.Packet)or taskAbstractRoot.invokeLater(java.lang.Runnable)is submitted.
-
-
-
Method Detail
-
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
protected final void doTimedPoll(long time, TimeUnit unit) throws InterruptedExceptionWait 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
protected final ThreadFactory 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.
-
-