com.sun.faban.harness.agent
Interface FileAgent

All Superinterfaces:
Remote
All Known Implementing Classes:
FileAgentImpl

public interface FileAgent
extends Remote

This is the interface that is implemented by the FileAgent. The FileAgent is used to access any file remotely.

Author:
Ramesh Ramachandran
See Also:
FileService

Field Summary
static int APPEND
          Open for write in append mode.
static int READ
          Open for reading.
static int WRITE
          Open for writing.
 
Method Summary
 boolean doesFileExist(String fileName)
          Checks whether the given remote file exists.
 FileTransfer get(String srcFile, String destFile)
          Gets a file from the local system to the master.
 String getProperty(String configFile, String propName)
          Gets a property from a given file.
 boolean isDirectory(String fileName)
          Checks whether the given remote file exists and is a directory.
 boolean isFile(String fileName)
          Checks whether the given remote file exists and is a normal file.
 FileService open(String file, int mode)
          Open a file for reading and/or writing.
 long push(FileTransfer transfer)
          Pushes a file, as encapsulated in the FileTransfer, from a the master to this agent.
 String readWholeFile(String file)
          Read a file from this machine and return the contents as a String.
 boolean removeFile(String fileName)
          Remove a file.
 boolean removeFiles(String dirName, FileFilter filter)
          Remove files from a directory matched by the filter.
 boolean truncateFile(String fileName)
          Truncates a file to zero-length.
 boolean writeWholeFile(String file, String contents)
          Write the given file to this machine.
 

Field Detail

READ

static final int READ
Open for reading.

See Also:
Constant Field Values

WRITE

static final int WRITE
Open for writing.

See Also:
Constant Field Values

APPEND

static final int APPEND
Open for write in append mode.

See Also:
Constant Field Values
Method Detail

open

FileService open(String file,
                 int mode)
                 throws RemoteException,
                        FileServiceException
Open a file for reading and/or writing.

Parameters:
file - filename
mode - file open mode - READ, WRITE, APPEND
Returns:
FileService - reference to the FileService interface.
Throws:
RemoteException - A communications error occurred.
FileServiceException - Error opening file

readWholeFile

String readWholeFile(String file)
                     throws IOException
Read a file from this machine and return the contents as a String.

Parameters:
file - name of the file
Returns:
String contents of the file
Throws:
IOException - An I/O error occurred

writeWholeFile

boolean writeWholeFile(String file,
                       String contents)
                       throws RemoteException
Write the given file to this machine.

Parameters:
file - path
contents - of the file.
Returns:
boolean true if successful, false if not.
Throws:
RemoteException - A communications error occurred.

removeFile

boolean removeFile(String fileName)
                   throws RemoteException
Remove a file.

Parameters:
fileName - - The pathname for the file.
Returns:
boolean - true if successful, false if not successful or file does not exist.
Throws:
RemoteException - A communications error occurred.

truncateFile

boolean truncateFile(String fileName)
                     throws RemoteException
Truncates a file to zero-length.

Parameters:
fileName - The pathname for the file
Returns:
Whether truncation succeeded
Throws:
RemoteException - An error occurred.

removeFiles

boolean removeFiles(String dirName,
                    FileFilter filter)
                    throws RemoteException
Remove files from a directory matched by the filter.

Parameters:
dirName - The directory path name
filter - The filter
Returns:
True if files are successfully removed. False otherwise
Throws:
RemoteException - A communications error occurred.

getProperty

String getProperty(String configFile,
                   String propName)
                   throws IOException
Gets a property from a given file.

Parameters:
configFile - The config file name
propName - The property key name
Returns:
The property value
Throws:
IOException - If there is an error accessing the config file

doesFileExist

boolean doesFileExist(String fileName)
                      throws RemoteException
Checks whether the given remote file exists.

Parameters:
fileName - The file name to test.
Returns:
true if exists, false otherwise.
Throws:
RemoteException - A communications error occurred.

isFile

boolean isFile(String fileName)
               throws RemoteException
Checks whether the given remote file exists and is a normal file.

Parameters:
fileName - The file name to test.
Returns:
true if file is a normal file, false otherwise.
Throws:
RemoteException - A communications error occurred.

isDirectory

boolean isDirectory(String fileName)
                    throws RemoteException
Checks whether the given remote file exists and is a directory.

Parameters:
fileName - The file name to test.
Returns:
true if file is a directory, false otherwise.
Throws:
RemoteException - A communications error occurred.

push

long push(FileTransfer transfer)
          throws RemoteException
Pushes a file, as encapsulated in the FileTransfer, from a the master to this agent. The serialization of the FileTransfer causes the file to be copied from src to dest over the wire.

Parameters:
transfer - The file transfer description
Returns:
The number of bytes transferred
Throws:
RemoteException - If there is an error in the transfer

get

FileTransfer get(String srcFile,
                 String destFile)
                 throws IOException
Gets a file from the local system to the master. The serialization of the FileTransfer itself causes the file to be copied to the master.

Parameters:
srcFile - The source file on the host the agent is running on
destFile - The destination file on the master
Returns:
The FileTransfer causing this transfer
Throws:
IOException - If there is an error reading or transferring