info.aduna.gee.publication.net
Class Cache

java.lang.Object
  extended by info.aduna.gee.publication.net.Cache

public class Cache
extends Object

Caching of ZPad specific files.


Field Summary
protected static Hashtable _globalCache
          The world wide collection of ZPad files.
protected static Hashtable _globalSyncObjects
          The table contains WURL <--> _localSyncObjects pairs.
protected  Vector _listeners
          A list of listeners
protected  Hashtable _localCache
          The cache object for this location.
protected  Hashtable _localSyncObjects
          The sync objects for this location.
 WURL _location
          The location of the files handled by this cache
protected static Vector _peers
          A pool of active cache objects
 
Constructor Summary
Cache(WURL location, int maxSize)
          Creates a new cache object.
 
Method Summary
protected  void _notify(WURL location, int info, String filename, Object arg)
          Notify this cache object of an update in the cache done by another cache object.
protected static void _refresh(Hashtable localCache)
          ...
protected static void _remove(Hashtable localCache, String filename)
           
 void addListener(IOListener listener)
          Add a listener to the audience.
 void close()
          Nicely deregister the cache, thus cleaning up any unnecessary peer registration to enable garbage collect.
 boolean contains(String filename)
          Checks whether a specific file is cached.
 Object get(String filename)
          Gets an object from the cache.
 Object get(String filename, WURL url)
          Gets an object from the cache: only used by the OutputHandler for processing jobs in the Q.
 Vector getAll()
          Gets all objects from the cache.
 Object getSynchronizationObject(Object name)
           
 void notifyAll(int info, String filename, Object arg)
          Notify all Cache peers of a change of an object at this Cache's location identified by a name.
 void put(String filename, Object object)
          Puts an object in the cache.
 void refresh()
          Forget EVERYTHING about the current location.
static void refresh(String host)
          Be very careful ....
static void refreshAtMidnight()
          Removing *everything* at midnight is expensive and unnecessary.
 void remove(String filename)
          Remove a file from the cache.
 void removeListener(IOListener listener)
          Remove a listener from the audience.
 void stayForever()
          This ZPad cache will live on forever, even though nobody listens to it.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

_peers

protected static Vector _peers
A pool of active cache objects


_globalCache

protected static Hashtable _globalCache
The world wide collection of ZPad files. The table contains WURL <--> fileHashtable pairs. A fileHashtable contains filename <--> object pairs.


_localCache

protected Hashtable _localCache
The cache object for this location.


_listeners

protected Vector _listeners
A list of listeners


_location

public WURL _location
The location of the files handled by this cache


_globalSyncObjects

protected static Hashtable _globalSyncObjects
The table contains WURL <--> _localSyncObjects pairs.


_localSyncObjects

protected Hashtable _localSyncObjects
The sync objects for this location.

Constructor Detail

Cache

public Cache(WURL location,
             int maxSize)
Creates a new cache object.

Parameters:
location - the ZPad location to transfer from/to.
maxSize - an upper bound for the number of files that are cached without removing inactive files (not implemented yet).
Method Detail

remove

public void remove(String filename)
Remove a file from the cache.

Parameters:
filename - the name of the file to remove.

_remove

protected static void _remove(Hashtable localCache,
                              String filename)

contains

public boolean contains(String filename)
Checks whether a specific file is cached.

Parameters:
filename - the name of the file to look for.
Returns:
true if the file was found in the cache.

get

public Object get(String filename)
Gets an object from the cache.

Parameters:
filename - the name of the file to look for.
Returns:
the object stored under the specified filename or null if not present.

getAll

public Vector getAll()
Gets all objects from the cache.


get

public Object get(String filename,
                  WURL url)
Gets an object from the cache: only used by the OutputHandler for processing jobs in the Q.

Parameters:
filename - the name of the file to look for.
url - the location of the file.
Returns:
the object stored under the specified filename or null if not present.

put

public void put(String filename,
                Object object)
Puts an object in the cache. All registered listeners will be notified.

Parameters:
filename - the filename under which the object will be stored.
object - the object to put in the cache.

notifyAll

public void notifyAll(int info,
                      String filename,
                      Object arg)
Notify all Cache peers of a change of an object at this Cache's location identified by a name. This method is public and that is more-or-less a hack. It is used by Transfer to force ZPad's to the correct section.

Parameters:
info - the information to send.
filename - the name of the object updated.
arg - an optional argument.

_notify

protected void _notify(WURL location,
                       int info,
                       String filename,
                       Object arg)
Notify this cache object of an update in the cache done by another cache object.

Parameters:
location - the location of the cache update.
info - the information to send.
filename - the name of the object updated.
arg - an optional argument.

addListener

public void addListener(IOListener listener)
Add a listener to the audience.

Parameters:
listener - a new I/O listener.

removeListener

public void removeListener(IOListener listener)
Remove a listener from the audience.

Parameters:
listener - the listener to remove.

close

public void close()
Nicely deregister the cache, thus cleaning up any unnecessary peer registration to enable garbage collect.


stayForever

public void stayForever()
This ZPad cache will live on forever, even though nobody listens to it. Note that that is true, because a static Vector (_peers) will contain a reference to this object forever (unless refresh is used in SERVERZPAD, see below). This mechanism is to avoid problems due to the fact that Browser and Proxy caches have never been designed for 2-way HTTP. When a file is written, sometimes at rereading you get the *old* version back. This is because writing (HTTP POST) does not go through the Browser and Proxy caches ....


_refresh

protected static void _refresh(Hashtable localCache)
...


refresh

public static void refresh(String host)
Be very careful .... ONLY refresh the host specified!


refresh

public void refresh()
Forget EVERYTHING about the current location. Required for new users and for leaving users.


refreshAtMidnight

public static void refreshAtMidnight()
Removing *everything* at midnight is expensive and unnecessary. Users will feel a slow start-up early in the morning which is bad. At midnight we want to reload/Cache update *all-and-only* zpad.dat's. For two reasons: -- they might have always-on-today entries (this we check) -- and entries may inspire or expire (therefore we do at least a cache update) (Note: inspiration or expiration is not run-time *registered* in the Entry)


getSynchronizationObject

public Object getSynchronizationObject(Object name)
Parameters:
name - an identification of the file and operation
Returns:
an object for synchronizing the operation on the file from the current location.


Copyright © 1997-2008 Aduna. All Rights Reserved.