ice.storm
Class ImageCache

java.lang.Object
  extended byice.storm.ImageCache
All Implemented Interfaces:
ResourceOwner

public class ImageCache
extends Object
implements ResourceOwner

Object of this class represents an image cache. In many JVMs instances of Images are cached endlessly until somebody calls flush() on the images that have been cached.

The simplest solution in a browser is to store references to all the images on a page and after user leaves the page, call flush() on all those images. Unfortunately this eliminates image caching completely and may not be desirable when data is loaded over a slow link.

To solve the problem ImageCache class has been introduced. It gives the ability to configure or change image caching behaviour. ICE Browser performs all image loading and unloading using this ImageCache.getInstance().

By default the image cache contains reference counter per image. When the counter reaches zero (nobody has a reference to the image), a timeout is set. During the call to flushImages() the timeout values are checked for images that have reference counter equal zero. All such images are flushed. The timeout value can be set via setExpire() method and is by default 30 seconds.

This image caching mechanism could be extended by for example introducing an 'image collector' thread that would kick from time to time and flush unused images.

To disable the image caching, call setExpire(0); This will make sure that the images are freed as soon as possible after they are not in use any more.


Field Summary
protected  HashArray imageToEntry
           
protected  int timeout
           
protected  HashArray uriToEntry
           
 
Constructor Summary
protected ImageCache(Session session)
           
 
Method Summary
 void checkForAnimatedImagesBug()
          Called from the ObjectPool whenever a new animated image is discovered (first time imageUpdate() is called with FRAMEBITS).
 void dispose()
          Deprecated. Use #disposeResource instead
 void disposeResources()
           
protected  Image factoryGetImage(URL url)
           
 void flushImages(boolean all)
          Flush images in the cache.
static ImageCache get(Session session)
           
 Toolkit getAwtToolkit()
           
 int getExpire()
          Get timeout value
 Image getImage(String url)
          Get an image which is loaded from a given URI.
 Image getImage(URL u)
          Deprecated. Use getImage(String).
 void release(Image img)
          After the image is no longer needed, this method should be called notifying the image cache.
static ImageCache set(Session session, ImageCache cache)
           
 void setExpire(int t)
          Set value of the timeout (in seconds) after which an unused image will be flushed.
 void setReload(boolean flag)
           
 void stopLoading(Image img)
          Call this method if you want to stop loading an image
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

uriToEntry

protected HashArray uriToEntry

imageToEntry

protected HashArray imageToEntry

timeout

protected int timeout
Constructor Detail

ImageCache

protected ImageCache(Session session)
Method Detail

get

public static ImageCache get(Session session)

set

public static ImageCache set(Session session,
                             ImageCache cache)

setReload

public void setReload(boolean flag)

getAwtToolkit

public Toolkit getAwtToolkit()

setExpire

public void setExpire(int t)
Set value of the timeout (in seconds) after which an unused image will be flushed.


getExpire

public int getExpire()
Get timeout value


dispose

public void dispose()
Deprecated. Use #disposeResource instead


disposeResources

public void disposeResources()
Specified by:
disposeResources in interface ResourceOwner

getImage

public Image getImage(URL u)
Deprecated. Use getImage(String).


getImage

public Image getImage(String url)
Get an image which is loaded from a given URI. Reference counter for the image is incremented.


stopLoading

public void stopLoading(Image img)
Call this method if you want to stop loading an image


release

public void release(Image img)
After the image is no longer needed, this method should be called notifying the image cache. The reference counter for this image is decrmented.


flushImages

public void flushImages(boolean all)
Flush images in the cache.

Parameters:
all - if false - only epxired unused images are flushed. If true - all the images in the cache are flushed.

checkForAnimatedImagesBug

public void checkForAnimatedImagesBug()
Called from the ObjectPool whenever a new animated image is discovered (first time imageUpdate() is called with FRAMEBITS).
Is responsible for detecting and trying to resolve the hang caused by the common bug in Sun-derived JVMs as described in http://developer.java.sun.com/developer/bugParade/bugs/4339995.html


factoryGetImage

protected Image factoryGetImage(URL url)