- java.lang.Object
-
- org.praxislive.base.DefaultExecutionContext
-
- All Implemented Interfaces:
ExecutionContext
public class DefaultExecutionContext extends Object implements ExecutionContext
Default implementation ofExecutionContext
for use withAbstractRoot
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface org.praxislive.core.ExecutionContext
ExecutionContext.ClockListener, ExecutionContext.State, ExecutionContext.StateListener
-
-
Constructor Summary
Constructors Constructor Description DefaultExecutionContext(long time)
Create a DefaultExecutionContext
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addClockListener(ExecutionContext.ClockListener listener)
Add a listener for clock changes.void
addStateListener(ExecutionContext.StateListener listener)
Add a listener for state changes.long
getStartTime()
Get the clock time in nanoseconds when the Root last became active.ExecutionContext.State
getState()
Get the current state of the Root.long
getTime()
Get the current Root local time in nanoseconds, relative to the RootHub clock.void
removeClockListener(ExecutionContext.ClockListener listener)
Remove an existing clock listener.void
removeStateListener(ExecutionContext.StateListener listener)
Remove an existing state listener.protected void
updateClock(long time)
Update the clock time.protected void
updateState(long time, ExecutionContext.State state)
Update the state.-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface org.praxislive.core.ExecutionContext
getPeriod
-
-
-
-
Method Detail
-
addStateListener
public void addStateListener(ExecutionContext.StateListener listener)
Description copied from interface:ExecutionContext
Add a listener for state changes.- Specified by:
addStateListener
in interfaceExecutionContext
- Parameters:
listener
- state listener, may not be null
-
removeStateListener
public void removeStateListener(ExecutionContext.StateListener listener)
Description copied from interface:ExecutionContext
Remove an existing state listener.- Specified by:
removeStateListener
in interfaceExecutionContext
- Parameters:
listener
- state listener to remove
-
addClockListener
public void addClockListener(ExecutionContext.ClockListener listener)
Description copied from interface:ExecutionContext
Add a listener for clock changes. Listeners will be called every time the Root is active and its local time changes - the frequency of changes, and whether the frequency is fixed or variable, is Root implementation specific.- Specified by:
addClockListener
in interfaceExecutionContext
- Parameters:
listener
- clock listener, may not be null
-
removeClockListener
public void removeClockListener(ExecutionContext.ClockListener listener)
Description copied from interface:ExecutionContext
Remove an existing clock listener.- Specified by:
removeClockListener
in interfaceExecutionContext
- Parameters:
listener
- clock listener to remove
-
updateState
protected void updateState(long time, ExecutionContext.State state)
Update the state. Will call all state listeners.- Parameters:
time
- time of state change (if ACTIVE also the new start time)state
- new state- Throws:
IllegalStateException
- if attempting to reset to NEW from another state, or attempting to set to another state if current state is TERMINATED
-
getState
public ExecutionContext.State getState()
Description copied from interface:ExecutionContext
Get the current state of the Root.- Specified by:
getState
in interfaceExecutionContext
- Returns:
- current state
-
updateClock
protected void updateClock(long time)
Update the clock time. Will call all clock listeners.- Parameters:
time
-
-
getTime
public long getTime()
Description copied from interface:ExecutionContext
Get the current Root local time in nanoseconds, relative to the RootHub clock.- Specified by:
getTime
in interfaceExecutionContext
- Returns:
- time in nanoseconds
-
getStartTime
public long getStartTime()
Description copied from interface:ExecutionContext
Get the clock time in nanoseconds when the Root last became active. If the current state is not active, the return value is not valid.- Specified by:
getStartTime
in interfaceExecutionContext
- Returns:
- clock time became active
-
-