com.jthomas.mailfaces
Class FaceCache

java.lang.Object
  |
  +--com.jthomas.mailfaces.FaceCache
All Implemented Interfaces:
java.util.EventListener, FaceEventListener

public class FaceCache
extends java.lang.Object
implements FaceEventListener

Class to Manage the Cache of Face Images used by MailFaces.

The cache saved on disk consists of a single index file and some number of icon files (gif images). The index file consists of a list of FaceCachEntry entries in String format. At startup, the index file is read and a number of hashtables are built with the data portion being the FaceCacheEntry _ByUser - key is Userid@host _ByHost - key is host _ByURL - key is URL There is also a Vecter _Entries that contains all of the FaceCachEntry objects. When MailFaces is stopped normally, the current entries are written back to the index file.

Author:
John Thomas
Field Summary
 boolean _Active
          true if Cache is being used.
 
Constructor Summary
FaceCache(java.lang.String directory)
          Constructor Uses the specified directory to setup the Cache.
 
Method Summary
 void actionPerformed(FaceEvent e)
          actionPerformed is the required implementation of FaceEventListener.
 void addIndex(com.jthomas.mailfaces.FaceCacheEntry entry)
          addIndex(FaceCacheEntry entry) This adds an entry to the Cache It updates the in-memory indexes and adds it to the list of entries
 void clearIndex()
          clearIndex() Clears the Cache Index file
 void deleteIndex(com.jthomas.mailfaces.FaceCacheEntry entry)
          deleteIndex(FaceCacheEntry entry) This deletes an entry to the Cache by deleting it from the in-memory indexes and and setting a flag so it will not be rewritten when the index is rewritten
 int getCount()
          getCount Get the current count of index entries
 java.lang.String getHost(java.lang.String host)
          getHost(String host) returns -> String CacheURL Return the URL of the cached image if present.
 java.lang.String getURL(java.lang.String url)
          getURL(String url) returns -> String CacheURL Return the URL of the cached image if present.
 java.lang.String getUser(java.lang.String user, java.lang.String host)
          getUser(String user,String host) returns -> String CacheURL Return the URL of the cached image if present.
 void listIndex()
          listIndex() Lists the Cache Index file
static void main(java.lang.String[] args)
          Adding this makes this class self-testing
 void verify(int verifyAge)
          verify Runs thru the index and verifies that the entries are correct This is currently unused (no menuitem to call it)
 void writeIndex()
          writeIndex() Writes the Cache Index file
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

_Active

public boolean _Active
true if Cache is being used.

Constructor Detail

FaceCache

public FaceCache(java.lang.String directory)
          throws java.io.IOException
Constructor Uses the specified directory to setup the Cache.

Parameters:
directory - where the cache info is stored.
Throws:
java.io.IOException - if problems writing cache entries
Method Detail

actionPerformed

public void actionPerformed(FaceEvent e)
actionPerformed is the required implementation of FaceEventListener. It is given control when some other components has sent an event that the Cache object needs to know about

Specified by:
actionPerformed in interface FaceEventListener

addIndex

public void addIndex(com.jthomas.mailfaces.FaceCacheEntry entry)
addIndex(FaceCacheEntry entry) This adds an entry to the Cache It updates the in-memory indexes and adds it to the list of entries


deleteIndex

public void deleteIndex(com.jthomas.mailfaces.FaceCacheEntry entry)
deleteIndex(FaceCacheEntry entry) This deletes an entry to the Cache by deleting it from the in-memory indexes and and setting a flag so it will not be rewritten when the index is rewritten


writeIndex

public void writeIndex()
writeIndex() Writes the Cache Index file


listIndex

public void listIndex()
listIndex() Lists the Cache Index file


clearIndex

public void clearIndex()
clearIndex() Clears the Cache Index file


getHost

public java.lang.String getHost(java.lang.String host)
getHost(String host) returns -> String CacheURL Return the URL of the cached image if present. Will return null if not found.


getUser

public java.lang.String getUser(java.lang.String user,
                                java.lang.String host)
getUser(String user,String host) returns -> String CacheURL Return the URL of the cached image if present. Will return null if not found.

There is a special case here. We can have a cache entry for user@host that has a null url that represents that we searched the PIconDB and did not find an entry. So if the url in the entry is null than we return "" instead of null. to indicate that there is no reason to search the PiconDB again.


getURL

public java.lang.String getURL(java.lang.String url)
getURL(String url) returns -> String CacheURL Return the URL of the cached image if present. Will return null if not found.


getCount

public int getCount()
getCount Get the current count of index entries


verify

public void verify(int verifyAge)
verify Runs thru the index and verifies that the entries are correct This is currently unused (no menuitem to call it)


main

public static void main(java.lang.String[] args)
Adding this makes this class self-testing