jpl.mipl.mdms.FileService.komodo.ui.savannah.tools
Class SessionCache

java.lang.Object
  extended by jpl.mipl.mdms.FileService.komodo.ui.savannah.tools.SessionCache

public class SessionCache
extends Object

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

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

 Date              Who              What
 ----------------------------------------------------------------------------
 09/05/0008        Nick             Initial Release
 ============================================================================
 

Version:
$Id: SessionCache.java,v 1.3 2008/09/08 19:37:14 awt Exp $
Author:
Nicholas Toole (Nicholas.T.Toole@jpl.nasa.gov)

Constructor Summary
SessionCache()
          Default constructor - required by JavaBean encoding architecture
SessionCache(String cacheFilename)
          Constructor
SessionCache(String outputDir, int options, String cacheFilename)
          Constructor
 
Method Summary
static boolean canRestoreFromCache()
          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
 String getCurrentDirectory()
          Accessor to file output directory
 String getLastQueryTime()
          Accessor to obtain the last query time in CCSDS formated time string
 boolean getOption(int option)
          Method to return the option value
 int getOptions()
           
protected  void moveFile(File src, File dst)
          Renames source file to destination file.
static SessionCache restoreFromCache()
          Factory method to create a session cache.
 void setCacheFilename(String cacheFilename)
          Method to set the cache file name
 void setCurrentDirectory(String outputDir)
          Method to set the output directory
 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 setOption(int option, boolean value)
           
 void setOptions(int options)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SessionCache

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


SessionCache

public SessionCache(String cacheFilename)
Constructor

Parameters:
outputDir - Output directory
options - Session options
cacheFilename - the cache file name

SessionCache

public SessionCache(String outputDir,
                    int options,
                    String cacheFilename)
Constructor

Parameters:
outputDir - Output directory
options - Session options
cacheFilename - the cache file name
Method Detail

restoreFromCache

public static SessionCache restoreFromCache()
Factory method to create a session cache. //* @param outputDir the file output location. //* @param options Int representing all options off or on

Returns:
SessionCache built from existing cache file, or a new instance

setOptions

public void setOptions(int options)

getOptions

public int getOptions()

setOption

public void setOption(int option,
                      boolean value)

getOption

public boolean getOption(int option)
Method to return the option value

Parameters:
option - the option
Returns:
boolean value for option.

canRestoreFromCache

public static boolean canRestoreFromCache()
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.

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

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

getCurrentDirectory

public String getCurrentDirectory()
Accessor to file output directory

Returns:
the output directory

setCurrentDirectory

public void setCurrentDirectory(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