public abstract class

StatefulRunnable

extends Object
implements Runnable
java.lang.Object
   ↳ com.facebook.common.executors.StatefulRunnable<T>
Known Direct Subclasses

Class Overview

Abstraction for computation.

Computation expressed as StatefulRunnable can be cancelled, but only if it has not started yet.

For better decoupling of the code computing the result and the code that handles it, 4 separate methods are provided: getResult, onSuccess, onFailure and onCancellation.

This runnable can be run only once. Subsequent calls to run method won't have any effect.

Summary

Constants
int STATE_CANCELLED
int STATE_CREATED
int STATE_FAILED
int STATE_FINISHED
int STATE_STARTED
Fields
protected final AtomicInteger mState
Public Constructors
StatefulRunnable()
Public Methods
void cancel()
final void run()
Protected Methods
void disposeResult(T result)
Called after onSuccess callback completes in order to dispose the result.
abstract T getResult()
void onCancellation()
Called when the runnable is cancelled.
void onFailure(Exception e)
Called if exception occurred during computation.
void onSuccess(T result)
Called after computing result successfully.
[Expand]
Inherited Methods
From class java.lang.Object
From interface java.lang.Runnable

Constants

protected static final int STATE_CANCELLED

Constant Value: 2 (0x00000002)

protected static final int STATE_CREATED

Constant Value: 0 (0x00000000)

protected static final int STATE_FAILED

Constant Value: 4 (0x00000004)

protected static final int STATE_FINISHED

Constant Value: 3 (0x00000003)

protected static final int STATE_STARTED

Constant Value: 1 (0x00000001)

Fields

protected final AtomicInteger mState

Public Constructors

public StatefulRunnable ()

Public Methods

public void cancel ()

public final void run ()

Protected Methods

protected void disposeResult (T result)

Called after onSuccess callback completes in order to dispose the result.

protected abstract T getResult ()

Throws
Exception

protected void onCancellation ()

Called when the runnable is cancelled.

protected void onFailure (Exception e)

Called if exception occurred during computation.

protected void onSuccess (T result)

Called after computing result successfully.