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

java.lang.Object
  extended by jpl.mipl.mdms.FileService.komodo.api.FileType
All Implemented Interfaces:
Closable

public class FileType
extends Object
implements Closable

Purpose: This class defines all operations that can be performed on a 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       Turek       Initial release.
 06/01/2005       Nick        Initial documentation.
 06/02/2005       Nick        Added subscribePush() method.  
 07/15/2005       Nick        get(String) and get(String[]) required CRC
                              and RESTART to create restart file.  Now, 
                              RESTART alone is sufficient.
 07/25/2005       Nick        subscribe() uses date param, restart time if
                              RESTART, otherwise, current time.
 ============================================================================
 

Version:
$Id: FileType.java,v 1.55 2008/06/26 01:44:54 ntt Exp $
Author:
Thomas Huang (Thomas.Huang@jpl.nasa.gov), Nicholas Toole (Nicholas.T.Toole@jpl.nasa.gov)

Constructor Summary
FileType(Session session, FileTypeInfo ftInfo)
          Constructor
 
Method Summary
protected  void _configureForReplication(jpl.mipl.mdms.FileService.komodo.api.Request cmd)
          If command has replication enabled, then the session is queried for a replication root directory.
 int add(String regexp)
          Method to add with regular expression
 int add(String[] fileNames)
          Method to add a list of files
 int add(String[] fileNames, String comment)
          Method to add a list of files with comment
 int add(String fileName, byte[] buffer, long length, String comment)
          Method to add in-memory file.
 int add(String regexp, String comment)
          Method to add file with regular expression
 int addAndRef(String regexp, String vft, String linkDirectory)
          Method to add and reference files with regular expression.
 int archive(String fileName)
          Method to remove archive notation from a file
 int archive(String fileName, String comment)
          Method to archive a file
 int close()
          Method to close this file type.
 int comment(String fileName)
          Method to remove comment from a file
 int comment(String fileName, String comment)
          Method to add comment to a file
 int delete(String regexp)
          Method to delete a file
static String extractFiletype(String fullFiletype)
          Extracts filetype from a full filetype.
static String extractServerGroup(String fullFiletype)
          Extracts server group from a full filetype.
 int get(String regexp)
          Method to get files according to a regular expression
 int get(String[] fileNames)
          Method to get a file
 int get(String[] fileNames, OutputStream out)
          Method to get a file and return it on the output stream specified.
 int getAfter(Date datetime)
          Method to get files of this file type after a given date.
 int getAfter(Date datetime, String regexp)
          Method to get files of this file type after a given date.
 int getBetween(Date begDate, Date endDate)
          Method to get files of this file type between two dates
 int getBetween(Date begDate, Date endDate, String regexp)
          Method to get files of this file type between two dates
 int getFileFromPath(String filePath)
          Method to get a file from a Komodo server based on an absolute path.
 String getGroup()
          Accessor method to get the name of this file type.
 int getLatest()
          Method to get the latest file
 int getLatest(String regexp)
          Method to get latest file according to a regular expression
 String getName()
          Accessor method to get the name of this file type.
 int getSince(Date datetime)
          Method to get files of this file type since a given date
 int getSince(Date datetime, String regexp)
          Method to get files of this file type since a given date
 int ignore(String[] fileNames)
          Method to ignore a file
static boolean isFullFiletype(String filetype)
          Examines argument string and determines if it satisfies the rules of a full filetype.
 int lock(String mode)
          Method to lock file type
static void main(String[] args)
           
 int memGet(String regexp)
          Method to get files according to a regular expression into memory
 int memGet(String[] fileNames)
          Method to get file in memory
 int memGetBetween(Date begDate, Date endDate)
          Method to get files of this file type between two dates into memory
 int memGetSince(Date datetime)
          Method to get files of this file type since a given date
 int register(String[] fileNames, boolean replace, boolean force, String comment)
          Method to register a file
 int rename(String oldFile, String newFile)
          Method to rename a file
 int replace(String regexp)
          Replace with regular expression
 int replace(String[] fileNames)
          Method to replace a file
 int replace(String[] fileNames, String comment)
          Method to replace a file
 int replace(String fileName, byte[] buffer, long length, String comment)
          Method to replace in-memory file.
 int replace(String regexp, String comment)
          Replace with regular expression
 int show()
          Method to show all files of this file type
 int show(String regexp)
          Method to show files according to regular expression
 int show(String[] fileNames)
          Method to show given files in the server
 int showAfter(Date datetime)
          Method to show files of this file type after a given date
 int showAfter(Date datetime, String regexp)
          Method to show files of this file type after a given date
 int showBetween(Date begDate, Date endDate)
          Method to show files of this file type between two dates
 int showBetween(Date begDate, Date endDate, String regexp)
          Method to show files of this file type between two dates
 int showCapabilities()
          Method to show all the user's file type capabilities on the server associated with this file type.
 int showLatest()
          Method to show the latest file for this type.
 int showLatest(String regexp)
          Method to show files according to regular expression
 int showSince(Date datetime)
          Method to show files of this file type since a given date
 int stopSubscribe()
          Method to subscribe to files of this file type after a given date.
 int subscribe(char operation, boolean commit)
          Method to subscribe to files of this file type.
 int subscribe(Date datetime, String regexp, char operation, boolean commit)
          Method to subscribe to files of this file type after a given date.
static String toFullFiletype(String servergroup, String filetype)
          Forms full filetype name using the servergroup and filetype arguments.
 int unlock(String mode)
          Method to unlock file type
 int unregister(String regexp)
          Method to unregister a file
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

FileType

public FileType(Session session,
                FileTypeInfo ftInfo)
         throws SessionException
Constructor

Parameters:
session - a transfer session, for maintaining file types and connections.
ftInfo - a file type
Throws:
SessionException - when session failure. If unable to connect to server, errno = CONN_FAILED. If authentication error, errno = INVALID_LOGIN.
Method Detail

getName

public final String getName()
Accessor method to get the name of this file type.

Returns:
file type name

getGroup

public final String getGroup()
Accessor method to get the name of this file type.

Returns:
Server Group name

comment

public int comment(String fileName)
            throws SessionException
Method to remove comment from a file

Parameters:
fileName - a file name
Returns:
the transaction id for tracking this command.
Throws:
SessionException - when session failure

comment

public int comment(String fileName,
                   String comment)
            throws SessionException
Method to add comment to a file

Parameters:
fileName - a file name
comment - the comment that goes along with file(s)
Returns:
the transaction id for tracking this command.
Throws:
SessionException - when session failure

archive

public int archive(String fileName)
            throws SessionException
Method to remove archive notation from a file

Parameters:
fileName - a file name
Returns:
the transaction id for tracking this command.
Throws:
SessionException - when session failure

archive

public int archive(String fileName,
                   String comment)
            throws SessionException
Method to archive a file

Parameters:
fileName - a file name
comment - the optional comment for the file
Returns:
the transaction id for tracking this command.
Throws:
SessionException - when session failure

add

public int add(String regexp)
        throws SessionException
Method to add with regular expression

Parameters:
regexp - a regular expression
Returns:
the transaction id for tracking this command.
Throws:
SessionException - when session failure

add

public int add(String regexp,
               String comment)
        throws SessionException
Method to add file with regular expression

Parameters:
regexp - a regular expression
comment - a comment to associated with each file
Returns:
the transaction id for tracking this command.
Throws:
SessionException - when session failure

add

public int add(String[] fileNames)
        throws SessionException
Method to add a list of files

Parameters:
fileNames - an array of file names
Returns:
the transaction id for tracking this command.
Throws:
SessionException - when session failure

add

public int add(String[] fileNames,
               String comment)
        throws SessionException
Method to add a list of files with comment

Parameters:
fileNames - an array of file names
comment - a comment to associated with each file
Returns:
the transaction id for tracking this command.
Throws:
SessionException - when session failure

addAndRef

public int addAndRef(String regexp,
                     String vft,
                     String linkDirectory)
              throws SessionException
Method to add and reference files with regular expression. Server makes the file name unique, and sets a reference to it. The name of the reference is the same as the file name. If linkDirectory is not null, causes Komodo to create a link of the form / , where ref name is the name of the local file. Note: References and file system links take effect at the next vft update. If reference does not exist for the vft, create one. If it does exist, schedule the reference for change at the next VFT update.

Parameters:
regexp - a regular expression
vft - virtual file type in created reference.
linkDirectory - where file system soft link directory.
Returns:
the transaction id for tracking this command.
Throws:
SessionException - when session failure

add

public int add(String fileName,
               byte[] buffer,
               long length,
               String comment)
        throws SessionException
Method to add in-memory file.

Parameters:
fileName - a file name
buffer - in-memory file contents
length - amount of data in the buffer to be sent as a file
comment - a comment to associated with each file, or null
Returns:
the transaction id for tracking this command.
Throws:
SessionException - when session failure

replace

public int replace(String regexp)
            throws SessionException
Replace with regular expression

Parameters:
regexp - a regular expression
Returns:
the transaction id for tracking this command.
Throws:
SessionException - when session failure

replace

public int replace(String regexp,
                   String comment)
            throws SessionException
Replace with regular expression

Parameters:
regexp - a regular expression
comment - a comment to associated with each file
Returns:
the transaction id for tracking this command.
Throws:
SessionException - when session failure

replace

public int replace(String[] fileNames)
            throws SessionException
Method to replace a file

Parameters:
fileNames - an array of file names
Returns:
the transaction id for tracking this command.
Throws:
SessionException - when session failure

replace

public int replace(String[] fileNames,
                   String comment)
            throws SessionException
Method to replace a file

Parameters:
fileNames - an array of file names
comment - a comment to associated with each file
Returns:
the transaction id for tracking this command.
Throws:
SessionException - when session failure

replace

public int replace(String fileName,
                   byte[] buffer,
                   long length,
                   String comment)
            throws SessionException
Method to replace in-memory file.

Parameters:
fileName - a file name
buffer - in-memory file contents
length - amount of data in the buffer to be sent as a file
comment - a comment to associated with each file, or null
Returns:
the transaction id for tracking this command.
Throws:
SessionException - when session failure

delete

public int delete(String regexp)
           throws SessionException
Method to delete a file

Parameters:
regexp - The regular expression file selector
Returns:
the transaction id for tracking this command.
Throws:
SessionException - when session failure

ignore

public int ignore(String[] fileNames)
           throws SessionException
Method to ignore a file

Parameters:
fileNames - an array of file names
Returns:
the transaction id for tracking this command.
Throws:
SessionException - when session failure

rename

public int rename(String oldFile,
                  String newFile)
           throws SessionException
Method to rename a file

Parameters:
oldFile - the old file name
newFile - the new file name
Returns:
the transaction id for tracking this command.
Throws:
SessionException - when session failure

showCapabilities

public int showCapabilities()
                     throws SessionException
Method to show all the user's file type capabilities on the server associated with this file type.

Returns:
the transaction id for tracking this command.
Throws:
SessionException - when session failure

show

public int show()
         throws SessionException
Method to show all files of this file type

Returns:
the transaction id for tracking this command.
Throws:
SessionException - when session failure

show

public int show(String regexp)
         throws SessionException
Method to show files according to regular expression

Parameters:
regexp - a regular expression
Returns:
the transaction id for tracking this command.
Throws:
SessionException - when session failure

show

public int show(String[] fileNames)
         throws SessionException
Method to show given files in the server

Parameters:
fileNames - an array of file names
Returns:
the transaction id for tracking this command.
Throws:
SessionException - when session failure

showSince

public int showSince(Date datetime)
              throws SessionException
Method to show files of this file type since a given date

Parameters:
datetime - the date cutoff for file show
Returns:
the transaction id for tracking this command.
Throws:
SessionException - when session failure

showAfter

public int showAfter(Date datetime)
              throws SessionException
Method to show files of this file type after a given date

Parameters:
datetime - the date cutoff for file show
Returns:
the transaction id for tracking this command.
Throws:
SessionException - when session failure

showAfter

public int showAfter(Date datetime,
                     String regexp)
              throws SessionException
Method to show files of this file type after a given date

Parameters:
datetime - the date cutoff for file show
regexp - the file name regular expression
Returns:
the transaction id for tracking this command.
Throws:
SessionException - when session failure

subscribe

public int subscribe(char operation,
                     boolean commit)
              throws SessionException
Method to subscribe to files of this file type. If cache file for operation exists, persisted time is used. Otherwise current time will be used.

Parameters:
operation - Char constant of operation, one of AUTO{GET|SHOW}FILES. `* @param commit Flag indicating whether Result state will be persisted to restart cache
Returns:
the transaction id for tracking this command.
Throws:
SessionException - when session failure

subscribe

public int subscribe(Date datetime,
                     String regexp,
                     char operation,
                     boolean commit)
              throws SessionException
Method to subscribe to files of this file type after a given date. If datetime parameter is specified, it is used. Otherwise, retrieves last query time from the restart cache if it exists and RESTART is enabled for the session. If not, then current system time is used.

Parameters:
datetime - the date cutoff for file show, can be null
regexp - the file name regular expression
operation - Char constant of operation, one of AUTO{GET|SHOW}FILES.
commit - Flag indicating whether Result state will be persisted to restart cache
Returns:
the transaction id for tracking this command.
Throws:
SessionException - when session failure

stopSubscribe

public int stopSubscribe()
                  throws SessionException
Method to subscribe to files of this file type after a given date. If datetime parameter is specified, it is used. Otherwise, retrieves last query time from the restart cache if it exists and RESTART is enabled for the session. If not, then current system time is used.

Parameters:
datetime - the date cutoff for file show, can be null
regexp - the file name regular expression
Returns:
the transaction id for tracking this command.
Throws:
SessionException - when session failure

showBetween

public int showBetween(Date begDate,
                       Date endDate)
                throws SessionException
Method to show files of this file type between two dates

Parameters:
begDate - the beginning Date
endDate - the last Date
Returns:
the transaction id for tracking this command.
Throws:
SessionException - when session failure

showBetween

public int showBetween(Date begDate,
                       Date endDate,
                       String regexp)
                throws SessionException
Method to show files of this file type between two dates

Parameters:
begDate - the beginning Date
endDate - the last Date
regexp - the file name regular expression
Returns:
the transaction id for tracking this command.
Throws:
SessionException - when session failure

showLatest

public int showLatest()
               throws SessionException
Method to show the latest file for this type.

Returns:
the transaction id for tracking this command.
Throws:
SessionException - when session failure

showLatest

public int showLatest(String regexp)
               throws SessionException
Method to show files according to regular expression

Parameters:
regexp - a regular expression
Returns:
the transaction id for tracking this command.
Throws:
SessionException - when session failure

getFileFromPath

public int getFileFromPath(String filePath)
                    throws SessionException
Method to get a file from a Komodo server based on an absolute path.

Parameters:
filePath - the location to files
Returns:
the transaction id for tracking this command.
Throws:
SessionException - when session failure

get

public int get(String regexp)
        throws SessionException
Method to get files according to a regular expression

Parameters:
regexp - a regular expression
Returns:
the transaction id for tracking this command.
Throws:
SessionException - when session failure

get

public int get(String[] fileNames)
        throws SessionException
Method to get a file

Parameters:
fileNames - an array of file names
Returns:
the transaction id for tracking this command.
Throws:
SessionException - when session failure

get

public int get(String[] fileNames,
               OutputStream out)
        throws SessionException
Method to get a file and return it on the output stream specified.

Parameters:
fileNames - an array of file names
out - the output stream to return the data on. Stream left open on return.
Returns:
the transaction id for tracking this command.
Throws:
SessionException - when session failure

getAfter

public int getAfter(Date datetime)
             throws SessionException
Method to get files of this file type after a given date.

Parameters:
datetime - the date overrides restart file date.
Returns:
the transaction id for tracking this command.
Throws:
SessionException - when session failure

getAfter

public int getAfter(Date datetime,
                    String regexp)
             throws SessionException
Method to get files of this file type after a given date.

Parameters:
datetime - the date overrides restart file date.
regexp - the file name regular expression
Returns:
the transaction id for tracking this command.
Throws:
SessionException - when session failure

getSince

public int getSince(Date datetime)
             throws SessionException
Method to get files of this file type since a given date

Parameters:
datetime - to date cutoff for file get
Returns:
the transaction id for tracking this command.
Throws:
SessionException - when session failure

getSince

public int getSince(Date datetime,
                    String regexp)
             throws SessionException
Method to get files of this file type since a given date

Parameters:
datetime - to date cutoff for file get
regexp - the file name regular expression
Returns:
the transaction id for tracking this command.
Throws:
SessionException - when session failure

getBetween

public int getBetween(Date begDate,
                      Date endDate)
               throws SessionException
Method to get files of this file type between two dates

Parameters:
begDate - the beginning date
endDate - the last date
Returns:
the transaction id for tracking this command.
Throws:
SessionException - when session failure

getBetween

public int getBetween(Date begDate,
                      Date endDate,
                      String regexp)
               throws SessionException
Method to get files of this file type between two dates

Parameters:
begDate - the beginning date
endDate - the last date
regexp - the file name regular expression
Returns:
the transaction id for tracking this command.
Throws:
SessionException - when session failure

getLatest

public int getLatest()
              throws SessionException
Method to get the latest file

Returns:
the transaction id for tracking this command.
Throws:
SessionException - when session failure

getLatest

public int getLatest(String regexp)
              throws SessionException
Method to get latest file according to a regular expression

Parameters:
regexp - a regular expression
Returns:
the transaction id for tracking this command.
Throws:
SessionException - when session failure

memGet

public int memGet(String regexp)
           throws SessionException
Method to get files according to a regular expression into memory

Parameters:
regexp - a regular expression
Returns:
the transaction id for tracking this command.
Throws:
SessionException - when session failure

memGet

public int memGet(String[] fileNames)
           throws SessionException
Method to get file in memory

Parameters:
fileNames - - an array of file names
Returns:
the transaction id for tracking this command.
Throws:
SessionException - when session failure

memGetSince

public int memGetSince(Date datetime)
                throws SessionException
Method to get files of this file type since a given date

Parameters:
datetime - the date cutoff for file get
Returns:
the transaction id for tracking this command.
Throws:
SessionException - when session failure

memGetBetween

public int memGetBetween(Date begDate,
                         Date endDate)
                  throws SessionException
Method to get files of this file type between two dates into memory

Parameters:
begDate - the beginning date
endDate - the last date
Returns:
the transaction id for tracking this command.
Throws:
SessionException - when session failure

lock

public int lock(String mode)
         throws SessionException
Method to lock file type

Parameters:
mode - the lock mode
Returns:
the transaction id for tracking this command.
Throws:
SessionException - when session failure

unlock

public int unlock(String mode)
           throws SessionException
Method to unlock file type

Parameters:
mode - the lock mode
Returns:
the transaction id for tracking this command.
Throws:
SessionException - when session failure

register

public int register(String[] fileNames,
                    boolean replace,
                    boolean force,
                    String comment)
             throws SessionException
Method to register a file

Parameters:
fileNames - an array of file names
replace - flag indicating that file metadata should be re-registered
force - flag indicating that all file metadata should be re-registered, including location
comment - a comment to associated with each file
Returns:
the transaction id for tracking this command.
Throws:
SessionException - when session failure

unregister

public int unregister(String regexp)
               throws SessionException
Method to unregister a file

Parameters:
regexp - The regular expression file selector
Returns:
the transaction id for tracking this command.
Throws:
SessionException - when session failure

close

public int close()
Method to close this file type. Do this by appending the close command at the head of the requests queue. The ServerProxy will then remove any requests for the file type from the queue. If all file types for this server have been closed, then the connection to the server will be gracefully closed.

Specified by:
close in interface Closable
Returns:
the transaction id for tracking this command.

_configureForReplication

protected void _configureForReplication(jpl.mipl.mdms.FileService.komodo.api.Request cmd)
If command has replication enabled, then the session is queried for a replication root directory. If no directory is specified, then the command is unaffected.

Parameters:
cmd - The Request to be configured for replication

extractServerGroup

public static String extractServerGroup(String fullFiletype)
Extracts server group from a full filetype. For example, if the argument is "dev:type3", then "dev" is returned. Also handles case of "dev:", where "dev" would be returned. If no server group can be found, then null is returned

Parameters:
fullFiletype - Full filetype name
Returns:
server group if extracted from argument, null otherwise

extractFiletype

public static String extractFiletype(String fullFiletype)
Extracts filetype from a full filetype. For example, if the argument is "dev:type3", then "type3" is returned. If no filetype can be found, i.e. not a full filetype, then null is returned

Parameters:
fullFiletype - Full filetype name
Returns:
filetype if extracted from argument, null otherwise

toFullFiletype

public static String toFullFiletype(String servergroup,
                                    String filetype)
Forms full filetype name using the servergroup and filetype arguments. For example, toFullFiletype("dev", "type3") returns "dev:type3". Server group can be null, but filetype must be a string of positive-length.

Parameters:
servergroup - Server group, can be null
filetype - Filetype name
Returns:
the full file type name from the arguments

isFullFiletype

public static boolean isFullFiletype(String filetype)
Examines argument string and determines if it satisfies the rules of a full filetype. Rules are: (1) Cannot be null or emptry string. (2) Must be in form [sg]:[ft], where [sg] and [ft] are non-empty strings not starting and ending with ":" respectively.

Parameters:
filetype - Potential full filetype string
Returns:
True if filetype is considered a full filetype, false otherwise.

main

public static void main(String[] args)