com.sun.faban.harness.agent
Class FileAgentImpl

java.lang.Object
  extended by java.rmi.server.RemoteObject
      extended by java.rmi.server.RemoteServer
          extended by java.rmi.server.UnicastRemoteObject
              extended by com.sun.faban.harness.agent.FileAgentImpl
All Implemented Interfaces:
FileAgent, Serializable, Remote

public class FileAgentImpl
extends UnicastRemoteObject
implements FileAgent

This is the class that reads/writes files for remote objects.

Author:
Ramesh Ramachandran
See Also:
FileAgent, Serialized Form

Field Summary
 
Fields inherited from class java.rmi.server.RemoteObject
ref
 
Fields inherited from interface com.sun.faban.harness.agent.FileAgent
APPEND, READ, WRITE
 
Constructor Summary
FileAgentImpl()
          Constructs the file agent.
 
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.
static void main(String[] argv)
          Starts a standalong file agent.
 FileService open(String file, int mode)
          This method creates a new FileServiceImpl object and returns a reference to its interface, FileService.
 long push(FileTransfer transfer)
          Pushes a file, as encapsulated in the FileTransfer, from a the master to this agent.
 String readWholeFile(String file)
          Read the contents of a file.
 boolean removeFile(String fileName)
          Removes 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 fileName, String contents)
          Write contents to a file.
 
Methods inherited from class java.rmi.server.UnicastRemoteObject
clone, exportObject, exportObject, exportObject, unexportObject
 
Methods inherited from class java.rmi.server.RemoteServer
getClientHost, getLog, setLog
 
Methods inherited from class java.rmi.server.RemoteObject
equals, getRef, hashCode, toString, toStub
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

FileAgentImpl

public FileAgentImpl()
              throws RemoteException
Constructs the file agent.

Throws:
RemoteException - A communications error occurred.
Method Detail

open

public FileService open(String file,
                        int mode)
                 throws RemoteException,
                        FileServiceException
This method creates a new FileServiceImpl object and returns a reference to its interface, FileService. The caller can then use it to read or write from/to the file.

Specified by:
open in interface FileAgent
Parameters:
file - - The pathname for the file.
mode - - specifies whether the file is opened for reading or for writing. The mode is specified by the FileAgent interface class variables - READ, WRITE, APPEND.
Returns:
FileService - reference to the FileService interface.
Throws:
RemoteException - A communications error occurred.
FileServiceException - Error opening file

readWholeFile

public String readWholeFile(String file)
                     throws IOException
Read the contents of a file. It maybe called by the benchmark specific code or the RunQ to copy files.

Specified by:
readWholeFile in interface FileAgent
Parameters:
file - - The pathname for the file
Returns:
String - Contents of the file as a String object
Throws:
IOException - An I/O error occurred

getProperty

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

Specified by:
getProperty in interface FileAgent
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

writeWholeFile

public boolean writeWholeFile(String fileName,
                              String contents)
Write contents to a file. It maybe called by the benchmark specific code or the RunQ to copy files.

Specified by:
writeWholeFile in interface FileAgent
Parameters:
fileName - - The pathname for the file.
contents - - Contents of the file as a String object.
Returns:
boolean - true if successful, false if not.

removeFile

public boolean removeFile(String fileName)
Removes a file.

Specified by:
removeFile in interface FileAgent
Parameters:
fileName - - The pathname for the file.
Returns:
boolean - true if successful, false if not successful or file does not exist.

truncateFile

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

Specified by:
truncateFile in interface FileAgent
Parameters:
fileName - The pathname for the file
Returns:
Whether truncation succeeded

removeFiles

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

Specified by:
removeFiles in interface FileAgent
Parameters:
dirName - The directory path name
filter - The filter
Returns:
True if files are successfully removed. False otherwise

doesFileExist

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

Specified by:
doesFileExist in interface FileAgent
Parameters:
fileName - The file name to test.
Returns:
true if exists, false otherwise.

isFile

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

Specified by:
isFile in interface FileAgent
Parameters:
fileName - The file name to test.
Returns:
true if file is a normal file, false otherwise.

isDirectory

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

Specified by:
isDirectory in interface FileAgent
Parameters:
fileName - The file name to test.
Returns:
true if file is a directory, false otherwise.

push

public 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.

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

get

public 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.

Specified by:
get in interface FileAgent
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:
RemoteException - If there is an error reading or transferring
IOException - If there is an error reading or transferring

main

public static void main(String[] argv)
Starts a standalong file agent.

Parameters:
argv - Command line arguments, not used