DLESE Tools
v1.6.0

org.dlese.dpc.oai.harvester
Class ScheduledHarvestManager

java.lang.Object
  extended by org.dlese.dpc.oai.harvester.ScheduledHarvestManager

public final class ScheduledHarvestManager
extends Object

Runs, logs and manages ScheduledHarvests.

Version:
$Id: ScheduledHarvestManager.java,v 1.23.2.3 2013/05/27 04:05:39 jweather Exp $
Author:
John Weatherley

Constructor Summary
ScheduledHarvestManager(SimpleDataStore dataStore, File initialHarvestDir, SimpleLuceneIndex harvestLogIndex, int timeOutMilliseconds)
          Constructor for the ScheduledHarvestManager
 
Method Summary
 void addScheduledHarvest(ScheduledHarvest sh)
          Adds a ScheduledHarvest to this manager or replaces an existing one with the same ID.
 boolean containsScheduledHarvest(Long shUid)
          Determines whether the given ScheduledHarvest ID is in this manager.
 boolean containsValue(ScheduledHarvest sh)
          Determine whether the given ScheduledHarvest value is in this manager.
static String getDateStamp()
          Return a string for the current time and date, sutiable for display in log files and output to standout:
 File getHarvestDir()
          Gets the harvestDir attribute of the ScheduledHarvestManager object
static Date getHarvestStartDate(String startTimeString)
          Gets the date and time to begin the harvest by parsing a String in 24 hour time format such as 12:24 or 23:15.
 ScheduledHarvest getScheduledHarvest(Long shUid)
          Gets the scheduledHarvest, or null if none exists.
 Hashtable getScheduledHarvests()
          Gets all scheduledHarvests in this this manager.
 void harvestNow(Long shUid, boolean harvestAll, boolean harvestAllIfNoDeletedRecord)
          Harvests the given ScheduledHarvest immediately, if not already running.
 boolean isRunning(Long shUid)
          Determines wheter the given ScheduledHarvest is currently running.
 boolean isRunningOneTimeHarvest(ScheduledHarvest sh)
          Determines whether a given ScheduledHarvest is already running.
 void oneTimeHarvest(ScheduledHarvest sh, Date from, Date until, File harvestDir, boolean harvestAllIfNoDeletedRecord)
          Performs a one-time only harvest in the background.
 void removeInProgresstLogEntries()
          Removes log entries showing entrytype status inprogress and replaces them with an error message indicateing that the given harvest was terminated by a server shut-down or crash.
 void removeScheduledHarvest(Long shUid, boolean deletefiles)
          Removes the given ScheduledHarvest.
static void setDebug(boolean db)
          Sets the debug attribute object
 void setHarvestDir(File harvestDir)
          Sets the harvestDir attribute of the ScheduledHarvestManager object
 void stopAllHarvests()
          Stops all running harvests gracefully.
 void stopTimerThread(Long shUid)
          Stops the timer
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ScheduledHarvestManager

public ScheduledHarvestManager(SimpleDataStore dataStore,
                               File initialHarvestDir,
                               SimpleLuceneIndex harvestLogIndex,
                               int timeOutMilliseconds)
Constructor for the ScheduledHarvestManager

Parameters:
dataStore - The data store that will hold persistent data for this manager.
initialHarvestDir - The initial directory where harvested files will be saved.
harvestLogIndex - The harvest log index used to log harvests.
timeOutMilliseconds - Number of milliseconds the harvester will wait for a response from the data provider before timing out
Method Detail

removeInProgresstLogEntries

public void removeInProgresstLogEntries()
Removes log entries showing entrytype status inprogress and replaces them with an error message indicateing that the given harvest was terminated by a server shut-down or crash. This method should only be called once upon server initialization.


setHarvestDir

public void setHarvestDir(File harvestDir)
Sets the harvestDir attribute of the ScheduledHarvestManager object

Parameters:
harvestDir - The new harvestDir value

getHarvestDir

public File getHarvestDir()
Gets the harvestDir attribute of the ScheduledHarvestManager object

Returns:
The harvestDir value

isRunning

public boolean isRunning(Long shUid)
Determines wheter the given ScheduledHarvest is currently running.

Parameters:
shUid - ScheduledHarvest ID.
Returns:
True if running.

getScheduledHarvests

public Hashtable getScheduledHarvests()
Gets all scheduledHarvests in this this manager.

Returns:
The scheduledHarvests

getScheduledHarvest

public ScheduledHarvest getScheduledHarvest(Long shUid)
Gets the scheduledHarvest, or null if none exists.

Parameters:
shUid - The ID of the item to retrieve.
Returns:
The scheduledHarvest value

addScheduledHarvest

public void addScheduledHarvest(ScheduledHarvest sh)
Adds a ScheduledHarvest to this manager or replaces an existing one with the same ID.

Parameters:
sh - The ScheduledHarvest to add.

removeScheduledHarvest

public void removeScheduledHarvest(Long shUid,
                                   boolean deletefiles)
Removes the given ScheduledHarvest.

Parameters:
shUid - ScheduledHarvest ID to remove
deletefiles - Description of the Parameter

containsScheduledHarvest

public boolean containsScheduledHarvest(Long shUid)
Determines whether the given ScheduledHarvest ID is in this manager.

Parameters:
shUid - ScheduledHarvest ID
Returns:
True if the given ScheduledHarvest ID exists in this manager.

containsValue

public boolean containsValue(ScheduledHarvest sh)
Determine whether the given ScheduledHarvest value is in this manager.

Parameters:
sh - ScheduledHarvest
Returns:
True if the ScheduledHarvest exists in this manager, else false.

harvestNow

public void harvestNow(Long shUid,
                       boolean harvestAll,
                       boolean harvestAllIfNoDeletedRecord)
Harvests the given ScheduledHarvest immediately, if not already running.

Parameters:
shUid - Uid of the ScheduledHarvest.
harvestAll - True to havest all records, false to havest only records changed since the previous harvest.
harvestAllIfNoDeletedRecord - True to harvest all records from scratch if deleted records are not supported

isRunningOneTimeHarvest

public boolean isRunningOneTimeHarvest(ScheduledHarvest sh)
Determines whether a given ScheduledHarvest is already running.

Parameters:
sh - The ScheduledHarvest
Returns:
True if already running, else false.

oneTimeHarvest

public void oneTimeHarvest(ScheduledHarvest sh,
                           Date from,
                           Date until,
                           File harvestDir,
                           boolean harvestAllIfNoDeletedRecord)
Performs a one-time only harvest in the background.

Parameters:
sh - A ScheduledHarvest with appropriate settings.
from - From Date
until - Until Date
harvestDir - Directory where harvested records will be saved.
harvestAllIfNoDeletedRecord - True to harvest all records from scratch if deleted records are not supported

stopAllHarvests

public void stopAllHarvests()
Stops all running harvests gracefully.


stopTimerThread

public void stopTimerThread(Long shUid)
Stops the timer

Parameters:
shUid - The uid of the ScheduledHarvest.

getHarvestStartDate

public static Date getHarvestStartDate(String startTimeString)
                                throws ParseException
Gets the date and time to begin the harvest by parsing a String in 24 hour time format such as 12:24 or 23:15.

Parameters:
startTimeString - The hour and minute in 24 hour time, for example 23:15
Returns:
The Date the harvest will begin
Throws:
ParseException - If unable to parse

getDateStamp

public static String getDateStamp()
Return a string for the current time and date, sutiable for display in log files and output to standout:

Returns:
The dateStamp value

setDebug

public static void setDebug(boolean db)
Sets the debug attribute object

Parameters:
db - The new debug value

DLESE Tools
v1.6.0