FileDocCategorySizeDatePackage
AsyncRunner.javaAPI DocAndroid 5.1 API7691Thu Mar 12 22:22:30 GMT 2015android.filterfw.core

AsyncRunner

public class AsyncRunner extends GraphRunner
hide

Fields Summary
private Class
mSchedulerClass
private SyncRunner
mRunner
private AsyncRunnerTask
mRunTask
private OnRunnerDoneListener
mDoneListener
private boolean
isProcessing
private Exception
mException
private boolean
mLogVerbose
private static final String
TAG
Constructors Summary
public AsyncRunner(FilterContext context, Class schedulerClass)
Create a new asynchronous graph runner with the given filter context, and the given scheduler class. Must be created on the UI thread.


                                
         
        super(context);

        mSchedulerClass = schedulerClass;
        mLogVerbose = Log.isLoggable(TAG, Log.VERBOSE);
    
public AsyncRunner(FilterContext context)
Create a new asynchronous graph runner with the given filter context. Uses a default scheduler. Must be created on the UI thread.

        super(context);

        mSchedulerClass = SimpleScheduler.class;
        mLogVerbose = Log.isLoggable(TAG, Log.VERBOSE);
    
Methods Summary
public synchronized voidclose()

        if (isRunning()) {
            throw new RuntimeException("Cannot close graph while it is running!");
        }
        if (mLogVerbose) Log.v(TAG, "Closing filters.");
        mRunner.close();
    
public synchronized java.lang.ExceptiongetError()

        return mException;
    
public FilterGraphgetGraph()

        return mRunner != null ? mRunner.getGraph() : null;
    
public synchronized booleanisRunning()
Check if background processing is happening

        return isProcessing;
    
public synchronized voidrun()
Execute the graph in a background thread.

        if (mLogVerbose) Log.v(TAG, "Running graph.");
        setException(null);

        if (isRunning()) {
            throw new RuntimeException("Graph is already running!");
        }
        if (mRunner == null) {
            throw new RuntimeException("Cannot run before a graph is set!");
        }
        mRunTask = this.new AsyncRunnerTask();

        setRunning(true);
        mRunTask.execute(mRunner);
    
public voidsetDoneCallback(OnRunnerDoneListener listener)
Set a callback to be called in the UI thread once the AsyncRunner completes running a graph, whether the completion is due to a stop() call or the filters running out of data to process.

        mDoneListener = listener;
    
private synchronized voidsetException(java.lang.Exception exception)

        mException = exception;
    
public synchronized voidsetGraph(FilterGraph graph)
Sets the graph to be run. Will call prepare() on graph. Cannot be called when a graph is already running.

        if (isRunning()) {
            throw new RuntimeException("Graph is already running!");
        }
        mRunner = new SyncRunner(mFilterContext, graph, mSchedulerClass);
    
private synchronized voidsetRunning(boolean running)

        isProcessing = running;
    
public synchronized voidstop()
Stop graph execution. This is an asynchronous call; register a callback with setDoneCallback to be notified of when the background processing has been completed. Calling stop will close the filter graph.

        if (mRunTask != null && !mRunTask.isCancelled() ) {
            if (mLogVerbose) Log.v(TAG, "Stopping graph.");
            mRunTask.cancel(false);
        }