|
IcedTea-Web NetX |
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectnet.sourceforge.jnlp.cache.ResourceTracker
public class ResourceTracker
This class tracks the downloading of various resources of a JNLP file to local files in the cache. It can be used to download icons, jnlp and extension files, jars, and jardiff files using the version based protocol or any file using the basic download protocol (jardiff and version not implemented yet).
The resource tracker can be configured to prefetch resources, which are downloaded in the order added to the media tracker.
Multiple threads are used to download and cache resources that are actively being waited for (blocking a caller) or those that have been started downloading by calling the startDownload method. Resources that are prefetched are downloaded one at a time and only if no other trackers have requested downloads. This allows the tracker to start downloading many items without using many system resources, but still quickly download items as needed.
Constructor Summary | |
---|---|
ResourceTracker()
Creates a resource tracker that does not prefetch resources. |
|
ResourceTracker(boolean prefetch)
Creates a resource tracker. |
Method Summary | |
---|---|
void |
addDownloadListener(DownloadListener listener)
Adds the listener to the list of objects interested in receivind DownloadEvents. |
void |
addResource(java.net.URL location,
Version version,
DownloadOptions options,
UpdatePolicy updatePolicy)
Add a resource identified by the specified location and version. |
boolean |
checkResource(java.net.URL location)
Returns whether a resource is available for use (ie, can be accessed with the getCacheFile method). |
protected void |
fireDownloadEvent(Resource resource)
Fires the download event corresponding to the resource's state. |
long |
getAmountRead(java.net.URL location)
Returns the number of bytes downloaded for a resource. |
java.io.File |
getCacheFile(java.net.URL location)
Returns a file containing the downloaded resource. |
java.net.URL |
getCacheURL(java.net.URL location)
Returns a URL pointing to the cached location of the resource, or the resource itself if it is a non-cacheable resource. |
java.io.InputStream |
getInputStream(java.net.URL location)
Returns an input stream that reads the contents of the resource. |
long |
getTotalSize(java.net.URL location)
Returns the number of total size in bytes of a resource, or -1 it the size is not known. |
void |
removeDownloadListener(DownloadListener listener)
Removes a download listener. |
void |
removeResource(java.net.URL location)
Removes a resource from the tracker. |
boolean |
startResource(java.net.URL location)
Starts loading the resource if it is not already being downloaded or already cached. |
protected void |
startThread()
Start a new download thread if there are not too many threads already running. |
boolean |
waitForResource(java.net.URL location,
long timeout)
Wait for a particular resource to be downloaded and made available. |
boolean |
waitForResources(java.net.URL[] urls,
long timeout)
Wait for a group of resources to be downloaded and made available locally. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public ResourceTracker()
public ResourceTracker(boolean prefetch)
prefetch
- whether to download resources before requested.Method Detail |
---|
public void addResource(java.net.URL location, Version version, DownloadOptions options, UpdatePolicy updatePolicy)
location
- the location of the resourceversion
- the resource versionupdatePolicy
- whether to check for updates if already in cachepublic void removeResource(java.net.URL location)
java.lang.IllegalArgumentException
- if the resource is not being trackedpublic void addDownloadListener(DownloadListener listener)
listener
- the listener to add.public void removeDownloadListener(DownloadListener listener)
listener
- the listener to remove.protected void fireDownloadEvent(Resource resource)
public java.net.URL getCacheURL(java.net.URL location)
If the resource has not downloaded yet, the method will block until it has been transferred to the cache.
location
- the resource location
java.lang.IllegalArgumentException
- if the resource is not being trackedCacheUtil.isCacheable(java.net.URL, net.sourceforge.jnlp.Version)
public java.io.File getCacheFile(java.net.URL location)
If the resource has not downloaded yet, the method will block until it has been transferred to the cache.
location
- the resource location
java.lang.IllegalArgumentException
- if the resource is not being trackedCacheUtil.isCacheable(java.net.URL, net.sourceforge.jnlp.Version)
public java.io.InputStream getInputStream(java.net.URL location) throws java.io.IOException
This method will block while the resource is downloaded to the cache.
java.io.IOException
- if there was an error opening the stream
java.lang.IllegalArgumentException
- if the resource is not being trackedpublic boolean waitForResources(java.net.URL[] urls, long timeout) throws java.lang.InterruptedException
urls
- the resources to wait fortimeout
- the time in ms to wait before returning, 0 for no timeout
java.lang.IllegalArgumentException
- if the resource is not being tracked
java.lang.InterruptedException
public boolean waitForResource(java.net.URL location, long timeout) throws java.lang.InterruptedException
location
- the resource to wait fortimeout
- the timeout, or 0 to wait until completed
java.lang.InterruptedException
- if another thread interrupted the wait
java.lang.IllegalArgumentException
- if the resource is not being trackedpublic long getAmountRead(java.net.URL location)
location
- the resource location
java.lang.IllegalArgumentException
- if the resource is not being trackedpublic boolean checkResource(java.net.URL location)
java.lang.IllegalArgumentException
- if the resource is not being trackedpublic boolean startResource(java.net.URL location)
java.lang.IllegalArgumentException
- if the resource is not being trackedpublic long getTotalSize(java.net.URL location)
location
- the resource location
java.lang.IllegalArgumentException
- if the resource is not being trackedprotected void startThread()
Calls to this method should be synchronized on lock.
|
IcedTea-Web NetX |
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |