|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--netx.jnlp.cache.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,
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 getLocalFile 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.InputStream |
getInputStream(java.net.URL location)
Returns an input stream that reads the contents of the resource. |
java.io.File |
getLocalFile(java.net.URL location)
Returns the file containing the downloaded resource, or null if the resource could not be downloaded to a local file (was not a cacheable 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, 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)
location
- the resource to add a callback forrunnable
- the runnable to call when resource is completedpublic void removeDownloadListener(DownloadListener listener)
protected void fireDownloadEvent(Resource resource)
public java.io.File getLocalFile(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 source location to get the local file forjava.lang.IllegalArgumentException
- if the resource is not being trackedpublic 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 streamjava.lang.IllegalArgumentException
- if the resource is not being trackedpublic boolean waitForResources(java.net.URL[] urls, long timeout) throws java.lang.InterruptedException
java.lang.IllegalArgumentException
- if the resource is not being trackedpublic 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 completedjava.lang.InterruptedException
- if another thread interrupted the waitjava.lang.IllegalArgumentException
- if the resource is not being trackedpublic long getAmountRead(java.net.URL location)
location
- the resource locationjava.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 locationjava.lang.IllegalArgumentException
- if the resource is not being trackedprotected void startThread()
Calls to this method should be synchronized on lock.
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |