FileDocCategorySizeDatePackage
TaskSingleDrainer.javaAPI DocAndroid 5.1 API3973Thu Mar 12 22:22:10 GMT 2015android.hardware.camera2.utils

TaskSingleDrainer

public class TaskSingleDrainer extends Object
Keep track of a single concurrent task starting and finishing; allow draining the existing task and figuring out when the task has finished (and won't restart).

The initial state is to allow all tasks to be started and finished. A task may only be started once, after which it must be finished before starting again. Likewise, finishing a task that hasn't been started is also not allowed.

When draining begins, the task cannot be started again. This guarantees that at some point the task will be finished forever, at which point the {@link DrainListener#onDrained} callback will be invoked.

Fields Summary
private final TaskDrainer
mTaskDrainer
private final Object
mSingleTask
Constructors Summary
public TaskSingleDrainer(android.os.Handler handler, android.hardware.camera2.utils.TaskDrainer.DrainListener listener)
Create a new task drainer; {@code onDrained} callbacks will be posted to the listener via the {@code handler}.

param
handler a non-{@code null} handler to use to post runnables to
param
listener a non-{@code null} listener where {@code onDrained} will be called


                                                   
         
        mTaskDrainer = new TaskDrainer<>(handler, listener);
    
public TaskSingleDrainer(android.os.Handler handler, android.hardware.camera2.utils.TaskDrainer.DrainListener listener, String name)
Create a new task drainer; {@code onDrained} callbacks will be posted to the listener via the {@code handler}.

param
handler a non-{@code null} handler to use to post runnables to
param
listener a non-{@code null} listener where {@code onDrained} will be called
param
name an optional name used for debug logging

        mTaskDrainer = new TaskDrainer<>(handler, listener, name);
    
Methods Summary
public voidbeginDrain()
Do not allow any more task re-starts; once the existing task is finished, fire the {@link DrainListener#onDrained} callback asynchronously.

This operation is idempotent; calling it more than once has no effect.

        mTaskDrainer.beginDrain();
    
public voidtaskFinished()
Mark this asynchronous task as having finished.

The task cannot be finished if it hasn't started. Once finished, a task cannot be finished again (unless it's started again).

see
#taskStarted
see
#beginDrain
throws
IllegalStateException If attempting to start a task which is already finished (and not re-started),

        mTaskDrainer.taskFinished(mSingleTask);
    
public voidtaskStarted()
Mark this asynchronous task as having started.

The task cannot be started more than once without first having finished. Once draining begins with {@link #beginDrain}, no new tasks can be started.

see
#taskFinished
see
#beginDrain
throws
IllegalStateException If attempting to start a task which is already started (and not finished), or if attempting to start a task after draining has begun.

        mTaskDrainer.taskStarted(mSingleTask);