wtanaka.praya.gale
Class KeyCache

java.lang.Object
  |
  +--wtanaka.praya.gale.KeyCache

public class KeyCache
extends java.lang.Object

Cache for public and private keys. The cache consists of three parts:

The cache supports two operations: If you would like to explicitly move keys from disk to memory, you will need to retrieve the key and then re-store it. This may have the side-effect of re-storing the key on the disk in a directory earlier in the list than the directory the key was fetched from.

Return to Sourceforge or the Praya Homepage

Version:
$Name: $ $Date: 2002/01/27 20:45:57 $
Author:
$Author: wtanaka $

Field Summary
private  java.io.File m_confDir
          location of ~/.gale/
private  java.lang.String m_defaultDomain
          default domain
private  java.util.Hashtable m_private
          Map of Location (id) into GalePrivateKey
private  java.util.Hashtable m_public
          Map of Location (id) into GalePublicKey
private  java.io.File m_sysDir
          location of GALE_SYS_DIR
private static KeyCache s_singleton
           
 
Constructor Summary
KeyCache()
          Constructor
 
Method Summary
 void addKey(GalePrivateKey key)
          Adds a key to the cache.
 void addKey(GalePublicKey key)
          Adds a key to the cache.
private  java.lang.String generateFilename()
          Tries to generate a unique filename.
static KeyCache getInstance()
          Returns the singleton instance, instantiating it if it doesn't already exist.
 GalePublicKey getKey(java.lang.String id)
          Deprecated. use getPublic(Location) instead.
 GalePrivateKey getPrivate(Location id)
          Retrieve a private key.
 GalePublicKey getPublic(Location id)
          Retrieve a public key.
static java.io.File[] getSearchOrderForPrivateKey(Location key, java.io.File sysDir, java.io.File confDir)
          Generates the list of files to search for a given public key.
static java.io.File[] getSearchOrderForPublicKey(Location key, java.io.File sysDir, java.io.File confDir)
          Generates the list of files to search for a given public key.
static java.io.File[] getWriteOrderForPrivateKey(Location key, java.io.File sysDir, java.io.File confDir)
          Generates the list of files to attempt to write a private key to.
static java.io.File[] getWriteOrderForPublicKey(Location key, java.io.File sysDir, java.io.File confDir)
          Generates the list of files to attempt to write a public key to.
private static java.lang.String hexEncode(byte[] bytes)
           
private static void initSingleton()
          Helper method which ensures that the singleton instance is instantiated.
 GalePrivateKey removePrivateFromMemory(Location id)
          Removes a key from the memory cache.
 GalePublicKey removePublicFromMemory(Location id)
          Removes a key from the memory cache.
 void setConfDir(java.io.File confDir)
          Sets the ~/.gale/ directory
 void setDefaultDomain(java.lang.String defaultDomain)
          sets the default domain for locations
 void setSysDir(java.io.File sysDir)
          Sets the GALE_SYS_DIR directory
 void waitForFirstPublic(long timeout, Location[] id)
          Waits for the first of the given keys to come back for a maximum of timeout milliseconds.
 void waitForPublic(long timeout, Location id)
          Waits for a single public key.
 void waitForPublic(long timeout, java.lang.String id)
          Deprecated. use waitForPublic (long, Location) instead.
 
Methods inherited from class java.lang.Object
, clone, equals, finalize, getClass, hashCode, notify, notifyAll, registerNatives, toString, wait, wait, wait
 

Field Detail

s_singleton

private static KeyCache s_singleton

m_public

private java.util.Hashtable m_public
Map of Location (id) into GalePublicKey

m_private

private java.util.Hashtable m_private
Map of Location (id) into GalePrivateKey

m_sysDir

private java.io.File m_sysDir
location of GALE_SYS_DIR

m_confDir

private java.io.File m_confDir
location of ~/.gale/

m_defaultDomain

private java.lang.String m_defaultDomain
default domain
Constructor Detail

KeyCache

public KeyCache()
Constructor
Method Detail

initSingleton

private static void initSingleton()
Helper method which ensures that the singleton instance is instantiated.

getInstance

public static KeyCache getInstance()
Returns the singleton instance, instantiating it if it doesn't already exist.
Returns:
the singleton instance, instantiating it if it doesn't already exist.

hexEncode

private static final java.lang.String hexEncode(byte[] bytes)

generateFilename

private java.lang.String generateFilename()
Tries to generate a unique filename.

addKey

public void addKey(GalePublicKey key)
Adds a key to the cache. This will store the key in memory, and then to the first disk cache that: exists AND does not already contain the key. If the key is found in a disk cache while trying to figure out where to store it, this method will not write the key to disk.

addKey

public void addKey(GalePrivateKey key)
Adds a key to the cache. This will store the key in memory, and then to the first disk cache that: exists AND does not already contain the key. If the key is found in a disk cache while trying to figure out where to store it, this method will not write the key to disk.

removePublicFromMemory

public GalePublicKey removePublicFromMemory(Location id)
Removes a key from the memory cache. Does not affect the disk cache.

removePrivateFromMemory

public GalePrivateKey removePrivateFromMemory(Location id)
Removes a key from the memory cache. Does not affect the disk cache.

getKey

public GalePublicKey getKey(java.lang.String id)
Deprecated. use getPublic(Location) instead.

Retrieve a key.

getPublic

public GalePublicKey getPublic(Location id)
Retrieve a public key. This will attempt to find the key in memory. If the key is not in memory, it will attempt to find it in each of its disk caches, in order.

getPrivate

public GalePrivateKey getPrivate(Location id)
Retrieve a private key. This will attempt to find the key in memory. If the key is not in memory, it will attempt to find it in each of its disk caches, in order.
Parameters:
id - the location for which this method should retrieve a private key.
Returns:
the private key corresponding to that location, or null, if it could not be found.

setDefaultDomain

public void setDefaultDomain(java.lang.String defaultDomain)
sets the default domain for locations

setSysDir

public void setSysDir(java.io.File sysDir)
Sets the GALE_SYS_DIR directory

setConfDir

public void setConfDir(java.io.File confDir)
Sets the ~/.gale/ directory

waitForPublic

public void waitForPublic(long timeout,
                          java.lang.String id)
Deprecated. use waitForPublic (long, Location) instead.


waitForPublic

public void waitForPublic(long timeout,
                          Location id)
Waits for a single public key.

waitForFirstPublic

public void waitForFirstPublic(long timeout,
                               Location[] id)
Waits for the first of the given keys to come back for a maximum of timeout milliseconds.

getSearchOrderForPublicKey

public static java.io.File[] getSearchOrderForPublicKey(Location key,
                                                        java.io.File sysDir,
                                                        java.io.File confDir)
Generates the list of files to search for a given public key. For a key named top.sub.bar@dom, this returns the following list:

getSearchOrderForPrivateKey

public static java.io.File[] getSearchOrderForPrivateKey(Location key,
                                                         java.io.File sysDir,
                                                         java.io.File confDir)
Generates the list of files to search for a given public key. For a public key named top.sub.bar@dom, returns the following list:

getWriteOrderForPublicKey

public static java.io.File[] getWriteOrderForPublicKey(Location key,
                                                       java.io.File sysDir,
                                                       java.io.File confDir)
Generates the list of files to attempt to write a public key to. Returns the following list:

getWriteOrderForPrivateKey

public static java.io.File[] getWriteOrderForPrivateKey(Location key,
                                                        java.io.File sysDir,
                                                        java.io.File confDir)
Generates the list of files to attempt to write a private key to. Returns the following list: