no.feide.moria.directory
Class IndexUpdater

java.lang.Object
  extended by java.util.TimerTask
      extended by no.feide.moria.directory.IndexUpdater
All Implemented Interfaces:
java.lang.Runnable

public class IndexUpdater
extends java.util.TimerTask

This is the task responsible for periodically checking for a new index file, and if necessary, update the existing index.

Note that this implementation relies on no.feide.moria.directory.index.SerializableIndex as the index implementation. To change the index implementation, the method readIndex() needs to be modified.


Field Summary
private  java.lang.String filename
          The location of the index file.
private  no.feide.moria.log.MessageLogger log
          Used for logging.
private  DirectoryManager owner
          The instance of Directory Manager that created this task.
private  long timestamp
          The timestamp of the last read index file.
 
Constructor Summary
IndexUpdater(DirectoryManager dm, java.lang.String indexFilename)
          Constructor.
 
Method Summary
protected  DirectoryManagerIndex readIndex()
          Reads an index file and create a new index object.
 void run()
          Performs the periodic update of the DirectoryManager's index, by calling the DirectoryManager.updateIndex(DirectoryManagerIndex) method.
 
Methods inherited from class java.util.TimerTask
cancel, scheduledExecutionTime
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

log

private final no.feide.moria.log.MessageLogger log
Used for logging.


filename

private final java.lang.String filename
The location of the index file.


timestamp

private long timestamp
The timestamp of the last read index file. Initially set to 0 (zero).


owner

private final DirectoryManager owner
The instance of Directory Manager that created this task.

Constructor Detail

IndexUpdater

public IndexUpdater(DirectoryManager dm,
                    java.lang.String indexFilename)
Constructor.

Parameters:
dm - The instance of Directory Manager that created this instance. Required since IndexUpdater uses this object directly to update its index. Cannot be null.
indexFilename - The index filename. Cannot be null.
Throws:
java.lang.NullPointerException - If dm or indexFilename is null.
Method Detail

run

public final void run()
Performs the periodic update of the DirectoryManager's index, by calling the DirectoryManager.updateIndex(DirectoryManagerIndex) method.

Specified by:
run in interface java.lang.Runnable
Specified by:
run in class java.util.TimerTask
See Also:
Runnable.run(), DirectoryManager.updateIndex(DirectoryManagerIndex)

readIndex

protected final DirectoryManagerIndex readIndex()
Reads an index file and create a new index object.

Note that this method is also called by DirectoryManager.setConfig(Properties) to force through an initial update of the index.

Returns:
The newly read index, as an object implementing the DirectoryManagerIndex interface. Will return null if this method has already been used to successfully read an index file, and the file has not been updated since (based on the file's timestamp on disk, as per the File.lastModified() method).
See Also:
File.lastModified(), DirectoryManager.setConfig(java.util.Properties)


Copyright © 2001-2006 UNINETT FAS. All Rights Reserved.