Class PriorityTaskManager
- java.lang.Object
-
- com.google.android.exoplayer2.util.PriorityTaskManager
-
public final class PriorityTaskManager extends Object
Allows tasks with associated priorities to control how they proceed relative to one another.A task should call
add(int)to register with the manager andremove(int)to unregister. A registered task will prevent tasks of lower priority from proceeding, and should callproceed(int),proceedNonBlocking(int)orproceedOrThrow(int)each time it wishes to check whether it is itself allowed to proceed.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classPriorityTaskManager.PriorityTooLowExceptionThrown when task attempts to proceed when another registered task has a higher priority.
-
Constructor Summary
Constructors Constructor Description PriorityTaskManager()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidadd(int priority)Register a new task.voidproceed(int priority)Blocks until the task is allowed to proceed.booleanproceedNonBlocking(int priority)A non-blocking variant ofproceed(int).voidproceedOrThrow(int priority)A throwing variant ofproceed(int).voidremove(int priority)Unregister a task.
-
-
-
Method Detail
-
add
public void add(int priority)
Register a new task. The task must callremove(int)when done.- Parameters:
priority- The priority of the task. Larger values indicate higher priorities.
-
proceed
public void proceed(int priority) throws InterruptedExceptionBlocks until the task is allowed to proceed.- Parameters:
priority- The priority of the task.- Throws:
InterruptedException- If the thread is interrupted.
-
proceedNonBlocking
public boolean proceedNonBlocking(int priority)
A non-blocking variant ofproceed(int).- Parameters:
priority- The priority of the task.- Returns:
- Whether the task is allowed to proceed.
-
proceedOrThrow
public void proceedOrThrow(int priority) throws PriorityTaskManager.PriorityTooLowExceptionA throwing variant ofproceed(int).- Parameters:
priority- The priority of the task.- Throws:
PriorityTaskManager.PriorityTooLowException- If the task is not allowed to proceed.
-
remove
public void remove(int priority)
Unregister a task.- Parameters:
priority- The priority of the task.
-
-