edu.wpi.prc.example.java.generator
Class WorkGeneratorClient

java.lang.Object
  extended by edu.wpi.prc.example.java.common.Client
      extended by edu.wpi.prc.example.java.generator.WorkGeneratorClient

public class WorkGeneratorClient
extends Client

The WorkGeneratorClient is an XML-RPC client with added functionality that is needed by the work unit generator. It has methods for sending new work units to the server, retrieving the last work unit that was added, and retrieving the number of new (ingress) work units that the server has.

Author:
James Baldassari

Field Summary
private static WorkGeneratorClient client
           
private static java.lang.String DEFAULT_SERVER_ADDRESS
           
private static int EXIT_ERROR
           
private static java.lang.String GET_LAST_WU_RPC_NAME
           
private static java.lang.String GET_NUM_WU_RPC_NAME
           
private static java.lang.String SEND_WU_RPC_NAME
           
 
Constructor Summary
private WorkGeneratorClient(java.lang.String serverAddress)
          Constructor specifying the address of the project server.
 
Method Summary
 WorkUnit getLastWorkUnit()
          Retrieves the last work unit that was generated from the server.
 int getNumWorkUnits()
          Retrieves the number of ingress (new) work units in the transitioner.
static WorkGeneratorClient instance()
           
 int sendWorkUnit(byte[] data)
          Sends a new work unit to the server.
 int sendWorkUnit(byte[] data, int priority, int points)
          Sends a new work unit to the server.
 int sendWorkUnit(byte[] data, int priority, int points, double expirationTime)
          Sends a new work unit to the server.
 int sendWorkUnit(java.lang.String workUnitID, byte[] data, int priority, int points)
          Sends a new work unit to the server.
 int sendWorkUnit(java.lang.String workUnitID, byte[] data, int priority, int points, double expirationTime)
          Sends a new work unit to the server.
private  int sendWorkUnit(java.util.Vector params, java.lang.String errorMessage)
          Executes the server.addWorkUnit RPC with the given parameter list.
private  void shutdown()
          Exits the entire process because an unrecoverable error occurred.
 
Methods inherited from class edu.wpi.prc.example.java.common.Client
executeRPC, executeRPCUntilSuccess, setServerAddress
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

EXIT_ERROR

private static final int EXIT_ERROR
See Also:
Constant Field Values

GET_LAST_WU_RPC_NAME

private static final java.lang.String GET_LAST_WU_RPC_NAME
See Also:
Constant Field Values

GET_NUM_WU_RPC_NAME

private static final java.lang.String GET_NUM_WU_RPC_NAME
See Also:
Constant Field Values

SEND_WU_RPC_NAME

private static final java.lang.String SEND_WU_RPC_NAME
See Also:
Constant Field Values

DEFAULT_SERVER_ADDRESS

private static final java.lang.String DEFAULT_SERVER_ADDRESS
See Also:
Constant Field Values

client

private static WorkGeneratorClient client
Constructor Detail

WorkGeneratorClient

private WorkGeneratorClient(java.lang.String serverAddress)
Constructor specifying the address of the project server. This constructor is private because WorkGeneratorClient is a singleton.

Parameters:
serverAddress - The address (host:port) of the project server.
Method Detail

sendWorkUnit

private int sendWorkUnit(java.util.Vector params,
                         java.lang.String errorMessage)
Executes the server.addWorkUnit RPC with the given parameter list.

Parameters:
params - The parameters to the server.addWorkUnit RPC.
errorMessage - The message to be displayed if an error occurs.
Returns:
Returns the number of clients that are blocked waiting for work units.

getLastWorkUnit

public WorkUnit getLastWorkUnit()
                         throws RPCHandlerException
Retrieves the last work unit that was generated from the server.

Returns:
Returns a WorkUnit object containing all information returned by the server.
Throws:
RPCHandlerException

sendWorkUnit

public int sendWorkUnit(java.lang.String workUnitID,
                        byte[] data,
                        int priority,
                        int points,
                        double expirationTime)
Sends a new work unit to the server.

Parameters:
workUnitID - The ID of the work unit.
data - A byte array containing the work unit data.
priority - The priority of the work unit. The minimum priority is zero, and higher values correspond to higher priorities.
points - The number of points to give a volunteer upon returning a valid result for this work unit.
expirationTime - The number of seconds until this work unit should expire. If the work unit is not retired before this amount of time elapses, the work unit will be recycled into the ingress queue and will be distributed to other volunteers.
Returns:
Returns the number of clients that are blocked waiting for work units.

sendWorkUnit

public int sendWorkUnit(java.lang.String workUnitID,
                        byte[] data,
                        int priority,
                        int points)
Sends a new work unit to the server.

Parameters:
workUnitID - The ID of the work unit.
data - A byte array containing the work unit data.
priority - The priority of the work unit. The minimum priority is zero, and higher values correspond to higher priorities.
points - The number of points to give a volunteer upon returning a valid result for this work unit.
Returns:
Returns the number of clients that are blocked waiting for work units.

sendWorkUnit

public int sendWorkUnit(byte[] data,
                        int priority,
                        int points,
                        double expirationTime)
Sends a new work unit to the server.

Parameters:
data - A byte array containing the work unit data.
priority - The priority of the work unit. The minimum priority is zero, and higher values correspond to higher priorities.
points - The number of points to give a volunteer upon returning a valid result for this work unit.
expirationTime - The number of seconds until this work unit should expire. If the work unit is not retired before this amount of time elapses, the work unit will be recycled into the ingress queue and will be distributed to other volunteers.
Returns:
Returns the number of clients that are blocked waiting for work units.

sendWorkUnit

public int sendWorkUnit(byte[] data,
                        int priority,
                        int points)
Sends a new work unit to the server.

Parameters:
data - A byte array containing the work unit data.
priority - The priority of the work unit. The minimum priority is zero, and higher values correspond to higher priorities.
points - The number of points to give a volunteer upon returning a valid result for this work unit.
Returns:
Returns the number of clients that are blocked waiting for work units.

sendWorkUnit

public int sendWorkUnit(byte[] data)
Sends a new work unit to the server.

Parameters:
data - A byte array containing the work unit data.
Returns:
Returns the number of clients that are blocked waiting for work units.

getNumWorkUnits

public int getNumWorkUnits()
Retrieves the number of ingress (new) work units in the transitioner. As this number approaches zero, more work units should be generated.

Returns:
The number of ingress work units in the transitioner.

shutdown

private void shutdown()
Exits the entire process because an unrecoverable error occurred.


instance

public static WorkGeneratorClient instance()
Returns:
Returns the singleton instance of this class.