public final class Loader extends java.lang.Object implements LoaderErrorThrower
Loader.Loadables.| Modifier and Type | Class and Description |
|---|---|
static interface |
Loader.Callback<T extends Loader.Loadable>
A callback to be notified of
Loader events. |
static interface |
Loader.Loadable
An object that can be loaded using a
Loader. |
static class |
Loader.LoadErrorAction
Action that can be taken in response to
Callback#onLoadError(Loadable, long, long,
IOException, int). |
static interface |
Loader.ReleaseCallback
A callback to be notified when a
Loader has finished being released. |
static class |
Loader.UnexpectedLoaderException
Thrown when an unexpected exception or error is encountered during loading.
|
LoaderErrorThrower.Dummy| Modifier and Type | Field and Description |
|---|---|
static Loader.LoadErrorAction |
DONT_RETRY
Discards the failed loading task and ignores any errors that have occurred.
|
static Loader.LoadErrorAction |
DONT_RETRY_FATAL
Discards the failed load.
|
static Loader.LoadErrorAction |
RETRY
Retries the load using the default delay.
|
static Loader.LoadErrorAction |
RETRY_RESET_ERROR_COUNT
Retries the load using the default delay and resets the error count.
|
| Constructor and Description |
|---|
Loader(java.lang.String threadName) |
| Modifier and Type | Method and Description |
|---|---|
void |
cancelLoading()
Cancels the current load.
|
static Loader.LoadErrorAction |
createRetryAction(boolean resetErrorCount,
long retryDelayMillis)
Creates a
Loader.LoadErrorAction for retrying with the given parameters. |
boolean |
isLoading()
Returns whether the
Loader is currently loading a Loader.Loadable. |
void |
maybeThrowError()
Throws a fatal error, or a non-fatal error if loading is currently backed off and the current
Loader.Loadable has incurred a number of errors greater than the Loaders default
minimum number of retries. |
void |
maybeThrowError(int minRetryCount)
Throws a fatal error, or a non-fatal error if loading is currently backed off and the current
Loader.Loadable has incurred a number of errors greater than the specified minimum number
of retries. |
void |
release()
Releases the
Loader. |
void |
release(Loader.ReleaseCallback callback)
Releases the
Loader. |
<T extends Loader.Loadable> |
startLoading(T loadable,
Loader.Callback<T> callback,
int defaultMinRetryCount)
Starts loading a
Loader.Loadable. |
public static final Loader.LoadErrorAction RETRY
public static final Loader.LoadErrorAction RETRY_RESET_ERROR_COUNT
public static final Loader.LoadErrorAction DONT_RETRY
public static final Loader.LoadErrorAction DONT_RETRY_FATAL
maybeThrowError() will throw the last load
error.public Loader(java.lang.String threadName)
threadName - A name for the loader's thread.public static Loader.LoadErrorAction createRetryAction(boolean resetErrorCount, long retryDelayMillis)
Loader.LoadErrorAction for retrying with the given parameters.resetErrorCount - Whether the previous error count should be set to zero.retryDelayMillis - The number of milliseconds to wait before retrying.Loader.LoadErrorAction for retrying with the given parameters.public <T extends Loader.Loadable> long startLoading(T loadable, Loader.Callback<T> callback, int defaultMinRetryCount)
Loader.Loadable.
The calling thread must be a Looper thread, which is the thread on which the Loader.Callback will be called.
T - The type of the loadable.loadable - The Loader.Loadable to load.callback - A callback to be called when the load ends.defaultMinRetryCount - The minimum number of times the load must be retried before maybeThrowError() will propagate an error.SystemClock.elapsedRealtime() when the load started.java.lang.IllegalStateException - If the calling thread does not have an associated Looper.public boolean isLoading()
Loader is currently loading a Loader.Loadable.public void cancelLoading()
public void release()
public void release(@Nullable
Loader.ReleaseCallback callback)
callback - An optional callback to be called on the loading thread once the loader has
been released.public void maybeThrowError()
throws java.io.IOException
LoaderErrorThrowerLoader.Loadable has incurred a number of errors greater than the Loaders default
minimum number of retries. Else does nothing.maybeThrowError in interface LoaderErrorThrowerjava.io.IOException - The error.public void maybeThrowError(int minRetryCount)
throws java.io.IOException
LoaderErrorThrowerLoader.Loadable has incurred a number of errors greater than the specified minimum number
of retries. Else does nothing.maybeThrowError in interface LoaderErrorThrowerminRetryCount - A minimum retry count that must be exceeded for a non-fatal error to be
thrown. Should be non-negative.java.io.IOException - The error.