Back to Fresco

AbstractDataSource

docs/javadoc/reference/com/facebook/datasource/AbstractDataSource.html

3.6.023.2 KB
Original Source

Fresco

|

|

Packages | Classes

Interfaces

Classes

Packages | Classes

Summary: Nested Classes | Protected Ctors | Methods | Protected Methods | Inherited Methods | [Expand All]

public abstract class

AbstractDataSource

extends Object
implements DataSource<T>

| java.lang.Object | | ↳ | com.facebook.datasource.AbstractDataSource<T> |

| Known Direct Subclasses

AbstractProducerToDataSourceAdapter<T>, ListDataSource<T>, SettableDataSource<T>, SimpleDataSource<T>

| AbstractProducerToDataSourceAdapter<T> | DataSource backed by a Producer | | ListDataSource<T> | Data source that wraps number of other data sources and waits until all of them are finished. | | SettableDataSource<T> | A DataSource whose result may be set by a #set(CloseableReference) or setException(Throwable) call. | | SimpleDataSource<T> | Settable DataSource. |

|

| Known Indirect Subclasses

CloseableProducerToDataSourceAdapter<T>, ProducerToDataSourceAdapter<T>

| CloseableProducerToDataSourceAdapter<T> | DataSource> backed by a Producer> | | ProducerToDataSourceAdapter<T> | DataSource backed by a Producer |

|

Class Overview

An abstract implementation of DataSource interface.

It is highly recommended that other data sources extend this class as it takes care of the state, as well as of notifying listeners when the state changes.

Subclasses should override closeResult(T) if results need clean up

Summary

Nested Classes
interface
Protected Constructors
Public Methods
boolean
Cancels the ongoing request and releases all associated resources.
static AbstractDataSource.DataSourceInstrumenter
Map<String, Object>
synchronized Throwable
synchronized float
synchronized T
The most recent result of the asynchronous computation.
synchronized boolean
boolean
synchronized boolean
synchronized boolean
synchronized boolean
static void
boolean
void
Subscribe for notifications whenever the state of the DataSource changes.
Protected Methods
void
Subclasses should override this method to close the result that is not needed anymore.
void
void
void
boolean
Subclasses should invoke this method to set the failure.
boolean
boolean
Subclasses should invoke this method to set the progress.
boolean
Subclasses should invoke this method to set the result to value.

| [Expand] Inherited Methods | | --- | | From class java.lang.Object

| Object | clone() | | boolean | equals(Object arg0) | | void | finalize() | | final Class<?> | getClass() | | int | hashCode() | | final void | notify() | | final void | notifyAll() | | String | toString() | | final void | wait(long arg0, int arg1) | | final void | wait(long arg0) | | final void | wait() |

| | From interface com.facebook.datasource.DataSource

| abstract boolean | close() Cancels the ongoing request and releases all associated resources. | | abstract Map<String, Object> | getExtras() | | abstract Throwable | getFailureCause() | | abstract float | getProgress() | | abstract T | getResult() The most recent result of the asynchronous computation. | | abstract boolean | hasFailed() | | abstract boolean | hasMultipleResults() | | abstract boolean | hasResult() | | abstract boolean | isClosed() | | abstract boolean | isFinished() | | abstract void | subscribe(DataSubscriber<T> dataSubscriber, Executor executor) Subscribe for notifications whenever the state of the DataSource changes. |

|

Protected Constructors

protected AbstractDataSource()

Public Methods

public boolean close()

Cancels the ongoing request and releases all associated resources.

Subsequent calls to getResult() will return null.

Returns
  • true if the data source is closed for the first time

public static AbstractDataSource.DataSourceInstrumenter getDataSourceInstrumenter()

public Map<String, Object> getExtras()

public synchronized Throwable getFailureCause()

public synchronized float getProgress()

public synchronized T getResult()

The most recent result of the asynchronous computation.

The caller gains ownership of the object and is responsible for releasing it. Note that subsequent calls to getResult might give different results. Later results should be considered to be of higher quality.

This method will return null in the following cases:

  • when the DataSource does not have a result (hasResult returns false).
  • when the last result produced was null.
Returns
  • current best result

public synchronized boolean hasFailed()

public boolean hasMultipleResults()

public synchronized boolean hasResult()

public synchronized boolean isClosed()

public synchronized boolean isFinished()

public static void provideInstrumenter(AbstractDataSource.DataSourceInstrumenter dataSourceInstrumenter)

public boolean setResult(T value, boolean isLast)

public void subscribe(DataSubscriber<T> dataSubscriber, Executor executor)

Subscribe for notifications whenever the state of the DataSource changes.

All changes will be observed on the provided executor.

Protected Methods

protected void closeResult(T result)

Subclasses should override this method to close the result that is not needed anymore.

This method is called in two cases: 1. to clear the result when data source gets closed 2. to clear the previous result when a new result is set

protected void notifyDataSubscriber(DataSubscriber<T> dataSubscriber, Executor executor, boolean isFailure, boolean isCancellation)

protected void notifyProgressUpdate()

protected void setExtras(Map<String, Object> extras)

protected boolean setFailure(Throwable throwable)

Subclasses should invoke this method to set the failure.

This method will return true if the failure was successfully set, or false if the data source has already been set, failed or closed.

If the failure was successfully set, state of the data source will be set to AbstractDataSource.DataSourceStatus#FAILURE.

This will also notify the subscribers if the failure was successfully set.

Do NOT call this method from a synchronized block as it invokes external code of the subscribers.

Parameters

| throwable | the failure cause to be set. |

Returns
  • true if the failure was successfully set.

protected boolean setFailure(Throwable throwable, Map<String, Object> extras)

protected boolean setProgress(float progress)

Subclasses should invoke this method to set the progress.

This method will return true if the progress was successfully set, or false if the data source has already been set, failed or closed.

This will also notify the subscribers if the progress was successfully set.

Do NOT call this method from a synchronized block as it invokes external code of the subscribers.

Parameters

| progress | the progress in range [0, 1] to be set. |

Returns
  • true if the progress was successfully set.

protected boolean setResult(T value, boolean isLast, Map<String, Object> extras)

Subclasses should invoke this method to set the result to value.

This method will return true if the value was successfully set, or false if the data source has already been set, failed or closed.

If the value was successfully set and isLast is true, state of the data source will be set to AbstractDataSource.DataSourceStatus#SUCCESS.

closeResult(T) will be called for the previous result if the new value was successfully set, OR for the new result otherwise.

This will also notify the subscribers if the value was successfully set.

Do NOT call this method from a synchronized block as it invokes external code of the subscribers.

Parameters

| value | the value that was the result of the task. | | isLast | whether or not the value is last. | | extras | an object with extra data for this datasource |

Returns
  • true if the value was successfully set.

+Generated by Doclava. +