public final class NetworkLock extends Object
Manages different priority network tasks. A network task that wishes to have its priority respected, and respect the priority of other tasks, should register itself with the lock prior to making network requests. It should then call one of the lock's proceed methods frequently during execution, so as to ensure that it continues only if it is the highest (or equally highest) priority task.
Note that lower integer values correspond to higher priorities.
Modifier and Type | Class and Description |
---|---|
static class |
NetworkLock.PriorityTooLowException
Thrown when a task is attempts to proceed when it does not have the highest priority.
|
Modifier and Type | Field and Description |
---|---|
static int |
DOWNLOAD_PRIORITY
Priority for network tasks associated with background downloads.
|
static NetworkLock |
instance |
static int |
STREAMING_PRIORITY
Priority for network tasks associated with media streaming.
|
Modifier and Type | Method and Description |
---|---|
void |
add(int priority)
Register a new task.
|
void |
proceed(int priority)
Blocks until the passed priority is the lowest one (i.e.
|
boolean |
proceedNonBlocking(int priority)
A non-blocking variant of
proceed(int) . |
void |
proceedOrThrow(int priority)
A throwing variant of
proceed(int) . |
void |
remove(int priority)
Unregister a task.
|
public static final NetworkLock instance
public static final int STREAMING_PRIORITY
public static final int DOWNLOAD_PRIORITY
public void proceed(int priority) throws InterruptedException
priority
- The priority of the task that would like to proceed.InterruptedException
public boolean proceedNonBlocking(int priority)
proceed(int)
.priority
- The priority of the task that would like to proceed.public void proceedOrThrow(int priority) throws NetworkLock.PriorityTooLowException
proceed(int)
.priority
- The priority of the task that would like to proceed.NetworkLock.PriorityTooLowException
- If the passed priority is not high enough to proceed.public void add(int priority)
The task must call remove(int)
when done.
priority
- The priority of the task.public void remove(int priority)
priority
- The priority of the task.