|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectnet.sf.jmatchparser.util.PrefetchDownloader
public class PrefetchDownloader
Utility class that makes it easy to download files in the background as they
are detected (over slow links) while still doing all of the parsing in a
single thread.
The main idea is, that whenever you encounter a file you have to parse later,
you add it to the prefetcher by calling the download(String, String)
method. All documents added to the prefetcher are loaded in a configurable
number of background threads (and stored into the CachingDownloader
's
cache. When ready to parse the new document, you can request the result by
calling waitFor(String)
, waiting for it if needed.
Constructor Summary | |
---|---|
PrefetchDownloader(CachingDownloader cd,
int threadcount,
boolean cacheResults)
Create a new prefetch downloader. |
Method Summary | |
---|---|
void |
download(String url,
String cacheName)
Add a document to download |
void |
download(String url,
String postData,
String cacheName)
Add a document to download, including POST data. |
void |
shutdown()
Wait until all prefetching is finished and shut down the prefetch threads. |
InputStream |
waitFor(String cacheName)
Wait until a given document has been prefetched. |
void |
waitPrefetch()
Wait until all prefetching is finished. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public PrefetchDownloader(CachingDownloader cd, int threadcount, boolean cacheResults)
cd
- Caching downloader to usethreadcount
- Number of prefetch threads to startcacheResults
- Whether to cache the results in the prefetcher. If not, they
are only written to the cache and can be retrieved from thereMethod Detail |
---|
public void download(String url, String cacheName)
url
- URL of the documentcacheName
- Name of the document in the cacheCachingDownloader.download(String, String)
public void download(String url, String postData, String cacheName)
url
- URL of the documentpostData
- postData to postcacheName
- Name of the document in the cacheCachingDownloader.download(String, String, String)
public void waitPrefetch() throws InterruptedException
InterruptedException
public InputStream waitFor(String cacheName) throws InterruptedException
cacheName
- Name of the document in the cache
InterruptedException
public void shutdown() throws InterruptedException
InterruptedException
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |