|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectjava.lang.Thread
org.hermit.android.net.WebFetcher
public abstract class WebFetcher
This class fetches data from the web without blocking the main app.
Nested Class Summary | |
---|---|
static class |
WebFetcher.FetchException
Web fetching exception. |
static interface |
WebFetcher.Listener
Listener for incoming web data. |
Nested classes/interfaces inherited from class java.lang.Thread |
---|
java.lang.Thread.State, java.lang.Thread.UncaughtExceptionHandler |
Field Summary | |
---|---|
protected WebFetcher.Listener |
dataClient
|
protected java.net.URL[] |
dataUrls
|
protected boolean |
killed
|
protected long |
newerThanDate
|
protected long |
timeout
|
Fields inherited from class java.lang.Thread |
---|
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY |
Constructor Summary | |
---|---|
WebFetcher(java.net.URL[] urls,
WebFetcher.Listener client,
long timeout,
long newer)
Create a fetcher to get data from a given list of URLs. |
|
WebFetcher(java.net.URL url,
WebFetcher.Listener client,
long timeout)
Create a fetcher to get data from a given URL. |
|
WebFetcher(java.net.URL url,
WebFetcher.Listener client,
long timeout,
long newer)
Create a fetcher to get data from a given URL. |
Method Summary | |
---|---|
protected void |
fetch(java.net.URL url,
long newer)
Fetch an object from the given URL. |
protected void |
handle(java.net.URL url,
java.net.URLConnection conn,
java.io.BufferedReader stream)
Handle data from the given BufferedReader. |
protected void |
handle(java.net.URL url,
java.net.URLConnection conn,
java.io.InputStream stream)
Handle data from the given stream. |
void |
kill()
Kill this fetcher. |
static void |
killAll()
Stop all fetch operations. |
static void |
queue(WebFetcher fetcher)
Queue a web fetch. |
void |
run()
Thread's main method. |
Methods inherited from class java.lang.Thread |
---|
activeCount, checkAccess, countStackFrames, currentThread, destroy, dumpStack, enumerate, getAllStackTraces, getContextClassLoader, getDefaultUncaughtExceptionHandler, getId, getName, getPriority, getStackTrace, getState, getThreadGroup, getUncaughtExceptionHandler, holdsLock, interrupt, interrupted, isAlive, isDaemon, isInterrupted, join, join, join, resume, setContextClassLoader, setDaemon, setDefaultUncaughtExceptionHandler, setName, setPriority, setUncaughtExceptionHandler, sleep, sleep, start, stop, stop, suspend, toString, yield |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Field Detail |
---|
protected final long timeout
protected boolean killed
protected final java.net.URL[] dataUrls
protected final long newerThanDate
protected final WebFetcher.Listener dataClient
Constructor Detail |
---|
public WebFetcher(java.net.URL url, WebFetcher.Listener client, long timeout)
url
- The URL to fetch data from.client
- Client to pass the data to.timeout
- Maximum time in ms for which the job will be
allowed to run.public WebFetcher(java.net.URL url, WebFetcher.Listener client, long timeout, long newer)
url
- The URL to fetch data from.client
- Client to pass the data to.timeout
- Maximum time in ms for which the job will be
allowed to run.newer
- If-modified-since time in ms UTC. The
fetch will only be carried out if the remote
resource has been modified since this time.
If zero, fetch without this condition.public WebFetcher(java.net.URL[] urls, WebFetcher.Listener client, long timeout, long newer)
urls
- The URLs to fetch data from.client
- Client to pass the data to.timeout
- Maximum time in ms for which the job will be
allowed to run.newer
- If-modified-since time in ms UTC. The
fetch will only be carried out if the remote
resource has been modified since this time.
If zero, fetch without this condition.Method Detail |
---|
public static void queue(WebFetcher fetcher)
fetcher
- The web fetcher to queue.public static void killAll()
public void kill()
public void run()
run
in interface java.lang.Runnable
run
in class java.lang.Thread
protected void fetch(java.net.URL url, long newer) throws WebFetcher.FetchException, java.io.IOException
url
- The URL to fetch.newer
- If-modified-since time in ms UTC. The
fetch will only be carried out if the remote
resource has been modified since this time.
If zero, fetch without this condition.
WebFetcher.FetchException
- Some problem was detected, such as a timeout.
java.io.IOException
- An I/O error occurred.protected void handle(java.net.URL url, java.net.URLConnection conn, java.io.InputStream stream) throws WebFetcher.FetchException, java.io.IOException
url
- The URL we're reading.conn
- The current connection to the URL.stream
- The InputStream to read from.
WebFetcher.FetchException
- Some problem was detected, such as a timeout.
java.io.IOException
- An I/O error occurred.protected void handle(java.net.URL url, java.net.URLConnection conn, java.io.BufferedReader stream) throws WebFetcher.FetchException, java.io.IOException
url
- The URL we're reading.conn
- The current connection to the URL.stream
- The BufferedReader to read from.
WebFetcher.FetchException
- Some problem was detected, such as a timeout.
java.io.IOException
- An I/O error occurred.
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |