public final class Loader extends java.lang.Object implements LoaderErrorThrower
Loader.Loadable
s.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.UnexpectedLoaderException
Thrown when an unexpected exception is encountered during loading.
|
Modifier and Type | Field and Description |
---|---|
static int |
DONT_RETRY |
static int |
DONT_RETRY_FATAL |
static int |
RETRY |
static int |
RETRY_RESET_ERROR_COUNT |
Constructor and Description |
---|
Loader(java.lang.String threadName) |
Modifier and Type | Method and Description |
---|---|
void |
cancelLoading()
Cancels the current load.
|
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 Loader s 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(java.lang.Runnable postLoadAction)
Releases the
Loader , running postLoadAction on its thread. |
<T extends Loader.Loadable> |
startLoading(T loadable,
Loader.Callback<T> callback,
int defaultMinRetryCount)
Starts loading a
Loader.Loadable . |
public static final int RETRY
public static final int RETRY_RESET_ERROR_COUNT
public static final int DONT_RETRY
public static final int DONT_RETRY_FATAL
public Loader(java.lang.String threadName)
threadName
- A name for the loader's thread.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 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(java.lang.Runnable postLoadAction)
Loader
, running postLoadAction
on its thread. This method should
be called when the Loader
is no longer required.postLoadAction
- A Runnable
to run on the loader's thread when
Loader.Loadable.load()
is no longer running.public void maybeThrowError() throws java.io.IOException
LoaderErrorThrower
Loader.Loadable
has incurred a number of errors greater than the Loader
s default
minimum number of retries. Else does nothing.maybeThrowError
in interface LoaderErrorThrower
java.io.IOException
- The error.public void maybeThrowError(int minRetryCount) throws java.io.IOException
LoaderErrorThrower
Loader.Loadable
has incurred a number of errors greater than the specified minimum number
of retries. Else does nothing.maybeThrowError
in interface LoaderErrorThrower
minRetryCount
- 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.