org.jdesktop.wonderland.client.assetmgr
Class AssetManager

java.lang.Object
  extended by org.jdesktop.wonderland.client.assetmgr.AssetManager

public class AssetManager
extends java.lang.Object

AssetManager provides services for downloading and maintaining the latest version of asset data for the system. Primary use is for Images (Textures) and geometry files of various types.

Author:
paulby

Nested Class Summary
static interface AssetManager.AssetProgressListener
          Used to indicate the status of an asset that is being downloaded
static class AssetManager.AssetStat
          Asset statistic
static interface AssetManager.AssetStatisticsSPI
          Provider that will be notified of asset statistics
 
Method Summary
 void addProgressListener(AssetManager.AssetProgressListener listener)
          Add a progress listener for asset loading.
 void closeAssetCache()
          Close the asset cache associated with this asset manager.
 void deleteAsset(Asset asset)
          Delete the asset from the local cache
static void downloadFile()
           
static java.lang.String encodeSpaces(java.lang.String uri)
          Replaces all of the spaces (' ') in a URI string with '%20'
protected  void fireDownloadCompleted(Asset asset)
          Notify listeners that a download has completed
protected  void fireDownloadFailed(Asset asset)
          Notify listeners that a download has completed
protected  void fireDownloadProgress(Asset asset, int readBytes, int percent)
          Notify listeners of download progress
 Asset getAsset(AssetURI assetURI)
          Fetches the asset from the Asset Manager.
 Asset getAsset(AssetURI assetURI, AssetRepositoryFactory factory)
          Fetches the asset from the Asset Manager.
 AssetCache getAssetCache()
          Get the asset cache associated with this asset manager.
static AssetManager getAssetManager()
          Return the singleton AssetManager.
 AssetManager.AssetStatisticsSPI getStatsProvider()
          Get the current statistics provider
static void main(java.lang.String[] args)
           
 void removeProgressListener(AssetManager.AssetProgressListener listener)
          Remove a progress listener for asset loading.
 void setStatsProvider(AssetManager.AssetStatisticsSPI provider)
          Set the asset statistics provider
 void unloadAsset(Asset asset)
          Unload the asset from memory
 boolean waitForAsset(Asset asset)
          Wait for the specified asset to load.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

getAssetManager

public static AssetManager getAssetManager()
Return the singleton AssetManager.

Returns:
An instance of the AssetManager class

getAssetCache

public AssetCache getAssetCache()
Get the asset cache associated with this asset manager.

Returns:
the cache associated with this manager

closeAssetCache

public void closeAssetCache()
Close the asset cache associated with this asset manager. The cache will be reopened on the next call to getAssetCache()


addProgressListener

public void addProgressListener(AssetManager.AssetProgressListener listener)
Add a progress listener for asset loading.

Parameters:
listener - The asset progress listener

removeProgressListener

public void removeProgressListener(AssetManager.AssetProgressListener listener)
Remove a progress listener for asset loading.

Parameters:
listener - the asset progress listener to remove

getAsset

public Asset getAsset(AssetURI assetURI)
Fetches the asset from the Asset Manager. If the asset is not in the local cache, then it will be downloaded and cached. This method returns immediately with an Asset object that represents the asset being downloaded or fetched from the cache. Upon error, this method returns null.

To receive an event when the asset is ready, attach a listener to the asset.

Parameters:
assetURI - The URI of the asset to fetch
Returns:
An Asset object

getAsset

public Asset getAsset(AssetURI assetURI,
                      AssetRepositoryFactory factory)
Fetches the asset from the Asset Manager. If the asset is not in the local cache, then it will be downloaded and cached. This method returns immediately with an Asset object that represents the asset being downloaded or fetched from the cache. Upon error, this method returns null.

To receive an event when the asset is ready, attach a listener to the asset.

This method also takes the factory that is responsible for fetching the asset from some server.

Parameters:
assetURI - The URI of the asset to fetch
Returns:
An Asset object

waitForAsset

public boolean waitForAsset(Asset asset)
Wait for the specified asset to load. This method will return once the asset is either loaded, or the load fails. If the load is successful true is returned, otherwise false is returned

Parameters:
asset -
Returns:
true if asset is ready, false if there was a failure

unloadAsset

public void unloadAsset(Asset asset)
Unload the asset from memory

Parameters:
asset -

deleteAsset

public void deleteAsset(Asset asset)
Delete the asset from the local cache

Parameters:
asset -

setStatsProvider

public void setStatsProvider(AssetManager.AssetStatisticsSPI provider)
Set the asset statistics provider

Parameters:
provider - the provider

getStatsProvider

public AssetManager.AssetStatisticsSPI getStatsProvider()
Get the current statistics provider


fireDownloadProgress

protected void fireDownloadProgress(Asset asset,
                                    int readBytes,
                                    int percent)
Notify listeners of download progress

Parameters:
asset - the asset that has progress
readBytes - the bytes read
percent - the percent of the total

fireDownloadCompleted

protected void fireDownloadCompleted(Asset asset)
Notify listeners that a download has completed

Parameters:
asset - the asset that completed

fireDownloadFailed

protected void fireDownloadFailed(Asset asset)
Notify listeners that a download has completed

Parameters:
asset - the asset that completed

encodeSpaces

public static java.lang.String encodeSpaces(java.lang.String uri)
Replaces all of the spaces (' ') in a URI string with '%20'


downloadFile

public static void downloadFile()
                         throws java.net.URISyntaxException
Throws:
java.net.URISyntaxException

main

public static void main(java.lang.String[] args)
                 throws java.net.URISyntaxException
Throws:
java.net.URISyntaxException


Open Wonderland - http://openwonderland.org