edu.wpi.prc.client
Class PRCClient

java.lang.Object
  extended by edu.wpi.prc.client.PRCClient
All Implemented Interfaces:
java.lang.Runnable

public class PRCClient
extends java.lang.Object
implements java.lang.Runnable

The PRC client acts as a proxy between the PRC server and the science application.

Author:
James Baldassari

Field Summary
static java.lang.String CHECKPOINT_PATH
           
private  int clientPort
           
private  java.lang.Thread clientThread
           
private static java.lang.String CONFIG_FILE_PATH
           
private  java.lang.String eMailAddress
           
private static java.lang.String ERROR_LOG_PATH
           
private static int EXIT_ERROR
           
private static int EXIT_SUCCESS
           
private  boolean isRunning
           
private static java.lang.String LOG_PATH
           
private static PRCClient prcClient
           
private  Project project
           
private static int SCIAPP_RETRY_DELAY
           
private  java.lang.String scienceAppURI
           
private static int SERVER_RETRY_DELAY
           
private  java.lang.String serverURI
           
private static int STARTUP_DELAY
           
private  java.lang.String userName
           
private static java.lang.String WORK_UNIT_DATA_PATH
           
private static java.lang.String WORK_UNIT_ID_PATH
           
private  org.apache.xmlrpc.XmlRpcClient xmlrpcPRCServerClient
           
private  org.apache.xmlrpc.XmlRpcClient xmlrpcScienceAppClient
           
private  org.apache.xmlrpc.WebServer xmlrpcServer
           
 
Constructor Summary
private PRCClient()
          Private constructor prevents explcit instantiation of the PRCClient class.
 
Method Summary
private  boolean addUser(java.lang.String userName, java.lang.String eMailAddress)
          Adds a user to the project.
private  void configureClient()
          Reads configuration from files in the cfg directory.
 void deleteWorkFilesFromDisk()
          Deletes the work unit files from disk.
private  boolean executeUserRPC(java.lang.String methodName, java.lang.String userName, java.lang.String eMailAddress)
          Executes one of the user XML-RPCs.
private  void getConfigurationFromUser()
          Gets user name and e-mail address from user, then writes the configuration file.
 java.lang.String getEMailAddress()
           
 java.lang.String getUserName()
           
 NonPersistentWorkUnit getWorkUnit()
          Requests a new work unit for this user from the project server.
 org.apache.xmlrpc.XmlRpcClient getXmlRpcPRCServerClient()
           
 org.apache.xmlrpc.XmlRpcClient getXmlRpcScienceAppClient()
           
 org.apache.xmlrpc.WebServer getXmlRpcServer()
           
private  void initXmlRpcClient()
          Initializes the XML-RPC clients used for communicating with the project server and science application.
private  void initXmlRpcServer()
          Initializes and starts the XML-RPC server.
static PRCClient instance()
           
 NonPersistentResult invokeScienceApp(NonPersistentWorkUnit wu)
          Runs the science application, then passes it a work unit to compute and waits for the science application to return a result.
 boolean isRunning()
           
static void main(java.lang.String[] args)
          Controls the client.
private  void readClientConfigurationFile()
          Reads the volunteer's user name and e-mail address from the configuration file.
 NonPersistentWorkUnit readWorkUnitFromDisk()
          Reads the work unit files on disk if they exist.
 boolean returnResult(NonPersistentWorkUnit wu, NonPersistentResult r)
          Returns a result to the server.
 void run()
          Starts the XML-RPC server and begins handling client requests.
 void shutdown()
          Performs any tasks necessary to clearnly shut down the client.
private  boolean verifyUser(java.lang.String userName, java.lang.String eMailAddress)
          Determines whether a given user is already a member of the project.
private  void writeWorkUnitToDisk(java.lang.String id, byte[] data)
          Writes the work unit ID and data to disk.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

prcClient

private static PRCClient prcClient

EXIT_SUCCESS

private static final int EXIT_SUCCESS
See Also:
Constant Field Values

EXIT_ERROR

private static final int EXIT_ERROR
See Also:
Constant Field Values

LOG_PATH

private static final java.lang.String LOG_PATH

ERROR_LOG_PATH

private static final java.lang.String ERROR_LOG_PATH

CONFIG_FILE_PATH

private static final java.lang.String CONFIG_FILE_PATH

WORK_UNIT_ID_PATH

private static final java.lang.String WORK_UNIT_ID_PATH

WORK_UNIT_DATA_PATH

private static final java.lang.String WORK_UNIT_DATA_PATH

CHECKPOINT_PATH

public static final java.lang.String CHECKPOINT_PATH

SERVER_RETRY_DELAY

private static final int SERVER_RETRY_DELAY
See Also:
Constant Field Values

SCIAPP_RETRY_DELAY

private static final int SCIAPP_RETRY_DELAY
See Also:
Constant Field Values

STARTUP_DELAY

private static final int STARTUP_DELAY
See Also:
Constant Field Values

clientThread

private java.lang.Thread clientThread

project

private Project project

xmlrpcServer

private org.apache.xmlrpc.WebServer xmlrpcServer

xmlrpcPRCServerClient

private org.apache.xmlrpc.XmlRpcClient xmlrpcPRCServerClient

xmlrpcScienceAppClient

private org.apache.xmlrpc.XmlRpcClient xmlrpcScienceAppClient

clientPort

private int clientPort

serverURI

private java.lang.String serverURI

scienceAppURI

private java.lang.String scienceAppURI

isRunning

private boolean isRunning

userName

private java.lang.String userName

eMailAddress

private java.lang.String eMailAddress
Constructor Detail

PRCClient

private PRCClient()
           throws MissingConfigurationFileException
Private constructor prevents explcit instantiation of the PRCClient class. Initializes the client componenets.

Throws:
MissingConfigurationFileException
Method Detail

configureClient

private void configureClient()
                      throws MissingConfigurationFileException
Reads configuration from files in the cfg directory.

Throws:
MissingConfigurationFileException

readClientConfigurationFile

private void readClientConfigurationFile()
Reads the volunteer's user name and e-mail address from the configuration file. If the configuration file does not exist, the user is prompted for the required information, and then the configuration file is saved to disk.


initXmlRpcServer

private void initXmlRpcServer()
Initializes and starts the XML-RPC server.


initXmlRpcClient

private void initXmlRpcClient()
Initializes the XML-RPC clients used for communicating with the project server and science application.


getConfigurationFromUser

private void getConfigurationFromUser()
Gets user name and e-mail address from user, then writes the configuration file.


addUser

private boolean addUser(java.lang.String userName,
                        java.lang.String eMailAddress)
Adds a user to the project.

Parameters:
userName - The user name to add.
eMailAddress - The user's e-mail address.
Returns:
Returns true if the user was successfully added, false if the user already existed.

verifyUser

private boolean verifyUser(java.lang.String userName,
                           java.lang.String eMailAddress)
Determines whether a given user is already a member of the project.

Parameters:
userName - The user name to search for.
eMailAddress - The e-mail address of the user.
Returns:
Returns true if the user is a member of the project, false otherwise.

executeUserRPC

private boolean executeUserRPC(java.lang.String methodName,
                               java.lang.String userName,
                               java.lang.String eMailAddress)
Executes one of the user XML-RPCs.

Parameters:
methodName - The name of the method to execute.
userName - The user name to search for.
eMailAddress - The user's e-mail address.
Returns:
The return value depends on the outcome of the RPC.

getXmlRpcServer

public org.apache.xmlrpc.WebServer getXmlRpcServer()
Returns:
Returns the xmlrpcServer.

getXmlRpcPRCServerClient

public org.apache.xmlrpc.XmlRpcClient getXmlRpcPRCServerClient()
Returns:
Returns the XML-RPC client for the project server.

getXmlRpcScienceAppClient

public org.apache.xmlrpc.XmlRpcClient getXmlRpcScienceAppClient()
Returns:
Returns the XML-RPC client for the science application.

getUserName

public java.lang.String getUserName()
Returns:
Returns the userName.

getEMailAddress

public java.lang.String getEMailAddress()
Returns:
Returns the eMailAddress.

getWorkUnit

public NonPersistentWorkUnit getWorkUnit()
Requests a new work unit for this user from the project server.

Returns:
The new work unit for this user, or null if the server did not have any work units.

readWorkUnitFromDisk

public NonPersistentWorkUnit readWorkUnitFromDisk()
Reads the work unit files on disk if they exist.

Returns:
Returns the work unit that was read from the disk, or null if none was found.

writeWorkUnitToDisk

private void writeWorkUnitToDisk(java.lang.String id,
                                 byte[] data)
Writes the work unit ID and data to disk.

Parameters:
id - The work unit ID to write.
data - The work unit data to write.

deleteWorkFilesFromDisk

public void deleteWorkFilesFromDisk()
Deletes the work unit files from disk.


invokeScienceApp

public NonPersistentResult invokeScienceApp(NonPersistentWorkUnit wu)
Runs the science application, then passes it a work unit to compute and waits for the science application to return a result.

Parameters:
wu - The work unit for which to compute a result.
Returns:
Returns the result computed by the science application.

returnResult

public boolean returnResult(NonPersistentWorkUnit wu,
                            NonPersistentResult r)
Returns a result to the server.

Parameters:
wu - The WorkUnit for which the result was computed.
r - The result that was computed.
Returns:
Returns true if the result was successfully sent to the server and acknowledged by the server, false otherwise.

isRunning

public boolean isRunning()
Returns:
Returns true if the server is running, false otherwise.

run

public void run()
Starts the XML-RPC server and begins handling client requests.

Specified by:
run in interface java.lang.Runnable

shutdown

public void shutdown()
Performs any tasks necessary to clearnly shut down the client.


instance

public static PRCClient instance()
                          throws MissingConfigurationFileException
Returns:
Returns the singleton instance of the PRCClient class.
Throws:
MissingConfigurationFileException

main

public static void main(java.lang.String[] args)
Controls the client.

Parameters:
args - Command-line arguments.