jpl.mipl.mdms.FileService.komodo.api
Class ClientRestartCache

java.lang.Object
  extended by jpl.mipl.mdms.FileService.komodo.api.ClientRestartCache

public class ClientRestartCache
extends Object

Purpose: Client restart cache JavaBean is used to cache file download and query information. The cached data can be persisted in XML format to assist restarting of user query or file download session. The cache data is stored with file name: <servergroup>.<filetype>.<subtype>.<restart|notify>. It is created per file type.

   Copyright 2005, California Institute of Technology.
   ALL RIGHTS RESERVED.
   U.S. Government Sponsorship acknowledge. 2005.
   
 ============================================================================
 Modification History :
 ----------------------

 Date              Who              What
 ----------------------------------------------------------------------------
 01/01/0001        Thomas           Initial Release
 01/10/2006        Nick             Initial documentation.
 01/10/2006        Nick             Added backup capability.  When committing
                                    a backup of existing file is made.  When
                                    restoring, if cannot restore from file,
                                    the backup is checked.
 ============================================================================
 

Version:
$Id: ClientRestartCache.java,v 1.14 2006/11/01 19:49:56 ntt Exp $
Author:
Thomas Huang (Thomas.Huang@jpl.nasa.gov), Nicholas Toole (Nicholas.T.Toole@jpl.nasa.gov)

Constructor Summary
ClientRestartCache()
          Default constructor - required by JavaBean encoding architecture
ClientRestartCache(String servergroup, String filetype, String subtype, Character command, String queryExpression, String cacheFilename)
          Constructor
 
Method Summary
 void addPersist(String filename, long size, long utc)
          Method to add persist informtion used by resume transfer.
 void addPersist(String filename, String vft, long size, long utc)
          Method to add persist infomation used by resume transfer on getVFT
static boolean canRestoreFromCache(String servergroup, String filetype, String subtype, Character command, String classicRegistry, String outputDir)
          Checks if a cache file associated with the parameters exists.
 void commit()
          Method to persist this cache JavaBean in XML format.
protected  void commitBackup()
          Copies existing restart file to a backup version in the name of fault tolerance.
protected  void copyFile(File src, File dst)
          Copies file using standard Java I/O library.
protected  void copyFileNIO(File src, File dst)
          Copies file using NIO package.
 String getCacheFilename()
          Accessor method to return the cache file name
 Character getCommand()
          Accessor method to return the user command
 Hashtable getFilesToResume()
          Accessor method to return internal hashtable used to keep track of file resume transfer information
 String getFileType()
          Accessor method to get file type name
 String getLastQueryExpression()
          Accessor for last file query expression
 String getLastQueryTime()
          Accessor to obtain the last query time in CCSDS formated time string
 String getOutputDir()
          Accessor to file output directory
 String getPersistedCCSDSModTimeString(String filename)
          Method to return the file modification time in CCSDS formated string
 Long getPersistedFileSize(String filename)
          Method to obtain the cached file size
 Date getPersistedModTime(String filename)
          Method to return the file modification time in a Date object
 String getPersistedVFT(String filename)
          Method to get peristed resume transfer information on a VFT reference
 Long getResumeOffset(String filename)
          Method to get resume offset value of a file.
 String getServerGroup()
          Accessor method to return server group name
 String getSubType()
          Accessor method to file sub-type name
protected  void moveFile(File src, File dst)
          Renames source file to destination file.
 void removePersist(String filename)
          Method to remove resume transfer information.
static ClientRestartCache restoreFromCache(String servergroup, String filetype, String subtype, Character command, String queryExpression, String classicRegistry, String outputDir)
          Factory method to create a client restart cache.
 void setCacheFilename(String cacheFilename)
          Method to set the cache file name
 void setCommand(Character command)
          Method to set the user command operator character
 void setFilesToResume(Hashtable filesToResume)
          Method to set file resume transfer internal data structure.
 void setFileType(String filetype)
          Method to set file type name
 void setLastQueryExpression(String lastQueryExpression)
          Method to set last file query expression
 void setLastQueryTime(long utc)
          Method to set the last query time in UTC long integer
 void setLastQueryTime(String ccsds)
          Method to set the last query time in CCSDS-formated time
 void setOutputDir(String outputDir)
          Method to set the output directory
 void setServerGroup(String servergroup)
          Method to set server group name
 void setSubType(String subtype)
          Method to set sub-type name
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ClientRestartCache

public ClientRestartCache()
Default constructor - required by JavaBean encoding architecture


ClientRestartCache

public ClientRestartCache(String servergroup,
                          String filetype,
                          String subtype,
                          Character command,
                          String queryExpression,
                          String cacheFilename)
Constructor

Parameters:
servergroup - the server group
filetype - the file type
subtype - the file sub-type
command - the user command
queryExpression - the file name query expression
cacheFilename - the cache file name
Method Detail

restoreFromCache

public static ClientRestartCache restoreFromCache(String servergroup,
                                                  String filetype,
                                                  String subtype,
                                                  Character command,
                                                  String queryExpression,
                                                  String classicRegistry,
                                                  String outputDir)
Factory method to create a client restart cache. This method also migrates any existing legacy restart file into the new format

Parameters:
servergroup - server group name
filetype - file tye name
subtype - file sub-type name
command - the command (add,get,list..)
queryExpression - the file name query expression
classicRegistry - the classic registry locaion
outputDir - the file output location. For get or autoget, this should be the output directory where new files will be stored. For show or autoshow, this should be the user cache directory (i.e. $HOME/.komdo)
Returns:
ClientRestartCache built from existing cache file, legacy file, or a new instance

canRestoreFromCache

public static boolean canRestoreFromCache(String servergroup,
                                          String filetype,
                                          String subtype,
                                          Character command,
                                          String classicRegistry,
                                          String outputDir)
Checks if a cache file associated with the parameters exists. First checks for a modern restart file. If that cannot be found, then checks for backup. If not found, finally checks for classic restart file. If none exists, then false is returned.

Parameters:
servergroup - Servergroup name
filetype - Filetype name
subtype - Sub-filetype name
command - Character associated with command
outputDir - Output directory path
outputDir - Output directory path
Returns:
True if a cache file is restorable, false otherwise.

addPersist

public void addPersist(String filename,
                       long size,
                       long utc)
Method to add persist informtion used by resume transfer.

Parameters:
filename - the file name
size - the file size
utc - the file modification time

addPersist

public void addPersist(String filename,
                       String vft,
                       long size,
                       long utc)
Method to add persist infomation used by resume transfer on getVFT

Parameters:
filename - the file name
vft - the reference name registered under a VFT
size - the file size
utc - the file modification time

removePersist

public void removePersist(String filename)
Method to remove resume transfer information. Usually afer a successful transfer

Parameters:
filename - the file name

getPersistedVFT

public String getPersistedVFT(String filename)
Method to get peristed resume transfer information on a VFT reference

Parameters:
filename - the file anme
Returns:
the reference name

getResumeOffset

public Long getResumeOffset(String filename)
Method to get resume offset value of a file. If file is declared in cache, exists and is not dir, then the file length is returned. Otherwise, null is returned.

Parameters:
filename - the file name
Returns:
the offset value, or null

getPersistedFileSize

public Long getPersistedFileSize(String filename)
Method to obtain the cached file size

Parameters:
filename - the file name
Returns:
the file size

getPersistedCCSDSModTimeString

public String getPersistedCCSDSModTimeString(String filename)
Method to return the file modification time in CCSDS formated string

Parameters:
filename - the file name
Returns:
the CCSDS-formated file modification string

getPersistedModTime

public Date getPersistedModTime(String filename)
Method to return the file modification time in a Date object

Parameters:
filename - the file name
Returns:
the Date object

getCacheFilename

public String getCacheFilename()
Accessor method to return the cache file name

Returns:
the cache file name

setCacheFilename

public void setCacheFilename(String cacheFilename)
Method to set the cache file name

Parameters:
cacheFilename - the cache file name

getCommand

public Character getCommand()
Accessor method to return the user command

Returns:
the user command character

setCommand

public void setCommand(Character command)
Method to set the user command operator character

Parameters:
command - the command operator

getServerGroup

public String getServerGroup()
Accessor method to return server group name

Returns:
the server group name

setServerGroup

public void setServerGroup(String servergroup)
Method to set server group name

Parameters:
servergroup - the server group name

getFileType

public String getFileType()
Accessor method to get file type name

Returns:
the file type name

setFileType

public void setFileType(String filetype)
Method to set file type name

Parameters:
filetype - the file type name

getSubType

public String getSubType()
Accessor method to file sub-type name

Returns:
the sub-type name

setSubType

public void setSubType(String subtype)
Method to set sub-type name

Parameters:
subtype - the sub type name

getFilesToResume

public Hashtable getFilesToResume()
Accessor method to return internal hashtable used to keep track of file resume transfer information

Returns:
the hashtable

setFilesToResume

public void setFilesToResume(Hashtable filesToResume)
Method to set file resume transfer internal data structure.

Parameters:
filesToResume - the hashtable

getLastQueryTime

public String getLastQueryTime()
Accessor to obtain the last query time in CCSDS formated time string

Returns:
the last query time

setLastQueryTime

public void setLastQueryTime(long utc)
Method to set the last query time in UTC long integer

Parameters:
utc - the UTC long integer

setLastQueryTime

public void setLastQueryTime(String ccsds)
Method to set the last query time in CCSDS-formated time

Parameters:
ccsds - the CCSDS formated time

getLastQueryExpression

public String getLastQueryExpression()
Accessor for last file query expression

Returns:
the last file query expression

setLastQueryExpression

public void setLastQueryExpression(String lastQueryExpression)
Method to set last file query expression

Parameters:
lastQueryExpression - the last file query expression

getOutputDir

public String getOutputDir()
Accessor to file output directory

Returns:
the output directory

setOutputDir

public void setOutputDir(String outputDir)
Method to set the output directory

Parameters:
outputDir - the output directory

commit

public void commit()
            throws SessionException
Method to persist this cache JavaBean in XML format.

Throws:
SessionException

commitBackup

protected void commitBackup()
Copies existing restart file to a backup version in the name of fault tolerance. When cache is restored from file, it will first check the usual filename. If unsuccessful, it will then check for the backup version, which will be out-of-date, but not as much so as starting over. Finally, if that is unsuccessful, a classic cache file is checked. If all fails, then a cache is created from no persisted state.


moveFile

protected void moveFile(File src,
                        File dst)
                 throws IOException
Renames source file to destination file.

Parameters:
src - Source file
dst - Destination file
Throws:
IOException

copyFile

protected void copyFile(File src,
                        File dst)
                 throws IOException
Copies file using standard Java I/O library.

Parameters:
src - Source file
dst - Destination file
Throws:
IOException

copyFileNIO

protected void copyFileNIO(File src,
                           File dst)
                    throws IOException
Copies file using NIO package.

Parameters:
src - Source file
dst - Destination file
Throws:
IOException