com.sun.slamd.client
Class Client

java.lang.Object
  extended byjava.lang.Thread
      extended bycom.sun.slamd.client.Client
All Implemented Interfaces:
java.lang.Runnable

public class Client
extends java.lang.Thread

This class defines a SLAMD client that can connect to the SLAMD server and interact with it to process the various jobs. Note that this version of the SLAMD client will only work on a single job at a time, although that job may spawn as many threads as it needs to operate. Also, this SLAMD client requires a Java version of at least 1.3 because it makes use of shutdown hooks to perform cleanup work when the client is shutting down.


Field Summary
static java.lang.String MAIN_THREAD_NAME
          The name to assign to the main client thread.
static java.lang.String SLAMD_CLIENT_VERSION
          The version of the SLAMD client software being used.
 
Fields inherited from class java.lang.Thread
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY
 
Constructor Summary
Client(java.lang.String serverAddress, int serverPort, int serverStatPort, boolean supportsTimeSync, boolean enableRealTimeStats, int statReportInterval, boolean persistStatistics, java.lang.String persistenceDirectory, int persistenceInterval, boolean restrictedMode, boolean useCustomClassLoader, java.lang.String classPath, boolean useSSL, boolean blindTrust, java.lang.String sslKeyStore, java.lang.String sslKeyStorePassword, java.lang.String sslTrustStore, java.lang.String sslTrustStorePassword, ClientMessageWriter messageWriter)
          Creates a new client that will communicate with the SLAMD server at the specified address and port, and will have the option of using SSL.
Client(java.lang.String serverAddress, int serverPort, int serverStatPort, boolean supportsTimeSync, boolean enableRealTimeStats, int statReportInterval, boolean persistStatistics, java.lang.String persistenceDirectory, int persistenceInterval, boolean useCustomClassLoader, java.lang.String classPath, ClientMessageWriter messageWriter)
          Creates a new client that will communicate with the SLAMD server at the specified address and port.
Client(java.lang.String serverAddress, int serverPort, int serverStatPort, boolean supportsTimeSync, boolean enableRealTimeStats, int statReportInterval, boolean persistStatistics, java.lang.String persistenceDirectory, int persistenceInterval, int authType, java.lang.String authID, java.lang.String authCredentials, boolean restrictedMode, boolean useCustomClassLoader, java.lang.String classPath, boolean useSSL, boolean blindTrust, java.lang.String sslKeyStore, java.lang.String sslKeyStorePassword, java.lang.String sslTrustStore, java.lang.String sslTrustStorePassword, ClientMessageWriter messageWriter)
          Creates a new client that will communicate with the SLAMD server at the specified address and port, and will use the specified authentication type and optionally may use SSL.
Client(java.lang.String serverAddress, int serverPort, int serverStatPort, boolean supportsTimeSync, boolean enableRealTimeStats, int statReportInterval, boolean persistStatistics, java.lang.String persistenceDirectory, int persistenceInterval, int authType, java.lang.String authID, java.lang.String authCredentials, boolean restrictedMode, boolean useCustomClassLoader, java.lang.String classPath, ClientMessageWriter messageWriter)
          Creates a new client that will communicate with the SLAMD server at the specified address and port, and will use the specified authentication type.
 
Method Summary
 boolean aggregateThreadData()
          Indicates whether the client should aggregate the data collected from all the threads before sending the results to the SLAMD server.
 void aggregateThreadData(boolean aggregateThreadData)
          Specifies whether the client should aggregate the data collected from all the threads before sending the results to the SLAMD server.
 void disconnect()
          Disconnects the client from the SLAMD server.
 java.lang.String getAuthenticationID()
          Retrieves the ID that the client used when authenticating to the server.
 int getAuthType()
          Retrieves the type of authentication that the client used.
 java.lang.String getClassPath()
          Retrieves the path to which Java class files sent by the server will be written.
 java.lang.String getClientID()
          Retrieves the user-friendly client ID that should show up in log messages.
 int getMessageID()
          Retrieves the message ID that the client should use for the next message that will be sent to the SLAMD server.
 ClientMessageWriter getMessageWriter()
          Retrieves the message writer associated with this client.
 java.lang.String getServerAddress()
          Retrieves the address of the SLAMD server to which this client is connected.
 int getServerPort()
          Retrieves the port on which the SLAMD client is communicating with the SLAMD server.
 java.lang.String getSSLKeyStore()
          Retrieves the location of the SSL key store that this client is using.
 java.lang.String getSSLTrustStore()
          Retrieves the location of the SSL trust store that this client is using.
static StatPersistenceThread getStatPersistenceThread()
          Retrieves the reference to the thread used for persisting statistical data on disk.
 void handleJobControlRequest(JobControlRequestMessage request)
          Performs any work requested by the provide job control request and sends the appropriate response.
 void handleJobRequest(JobRequestMessage request)
          Configures the client to start processing the new job specified in the job request and sends the appropriate response.
 void handleStatusRequestMessage(StatusRequestMessage request)
          Handles the provided status request by gathering the requested information and sending it back to the server.
 void jobDone()
          Used by the job to indicate to the client that it has completed processing and that the client should gather all the appropriate summary information and send it back to the server.
static void registerPersistentStatistic(StatTracker tracker)
          Registers the provided stat tracker with the persistence thread so that its data will be periodically persisted on disk.
 void run()
          Loop infinitely waiting for a request to come in.
 void sendMessage(Message message)
          Sends the requested message to the SLAMD server.
 void setShutdownListener(ClientShutdownListener shutdownListener)
          Specifies the listener that should be notified when the client stops running.
 int startJob()
          Attempts to start the current job.
 int stopJob(int stopReason, boolean waitForStop)
          Attempts to stop the current job.
 boolean usingSSL()
          Indicates whether the connection between the client and the server is using SSL.
 void writeMessage(java.lang.String message)
          Writes a message that may be seen by clients.
 void writeVerbose(java.lang.String message)
          Writes a verbose message that may be seen by clients if they have enabled verbose messages.
 
Methods inherited from class java.lang.Thread
activeCount, checkAccess, countStackFrames, currentThread, destroy, dumpStack, enumerate, getContextClassLoader, getName, getPriority, getThreadGroup, holdsLock, interrupt, interrupted, isAlive, isDaemon, isInterrupted, join, join, join, resume, setContextClassLoader, setDaemon, setName, setPriority, sleep, sleep, start, stop, stop, suspend, toString, yield
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

SLAMD_CLIENT_VERSION

public static final java.lang.String SLAMD_CLIENT_VERSION
The version of the SLAMD client software being used.

See Also:
Constant Field Values

MAIN_THREAD_NAME

public static final java.lang.String MAIN_THREAD_NAME
The name to assign to the main client thread.

See Also:
Constant Field Values
Constructor Detail

Client

public Client(java.lang.String serverAddress,
              int serverPort,
              int serverStatPort,
              boolean supportsTimeSync,
              boolean enableRealTimeStats,
              int statReportInterval,
              boolean persistStatistics,
              java.lang.String persistenceDirectory,
              int persistenceInterval,
              boolean useCustomClassLoader,
              java.lang.String classPath,
              ClientMessageWriter messageWriter)
       throws ClientException
Creates a new client that will communicate with the SLAMD server at the specified address and port. There will not be any authentication performed, nor will the connection use SSL.

Parameters:
serverAddress - The IP address or DNS hostname of the SLAMD server.
serverPort - The port number on which the SLAMD server is listening for client connections.
serverStatPort - The port number on which the SLAMD server listens for real-time statistical data.
supportsTimeSync - Indicates whether the client should support time synchronization with the server.
enableRealTimeStats - Indicates whether the client should support the collection of real-time statistics for reporting back to the SLAMD server.
statReportInterval - The length of time in seconds between stat updates to the server.
persistStatistics - Indicates whether the client should periodically save statistical data on disk.
persistenceDirectory - The directory in which the persisted data will be written.
persistenceInterval - The interval in seconds between saves of the persistence data.
useCustomClassLoader - Indicates whether to use the custom class loader for loading job classes.
classPath - The path to which Java class files will be written if they are sent from the client to the server using a class transfer response.
messageWriter - The writer to which informational and verbose messages will be written.
Throws:
ClientException - If some problem is encountered while creating the client.

Client

public Client(java.lang.String serverAddress,
              int serverPort,
              int serverStatPort,
              boolean supportsTimeSync,
              boolean enableRealTimeStats,
              int statReportInterval,
              boolean persistStatistics,
              java.lang.String persistenceDirectory,
              int persistenceInterval,
              boolean restrictedMode,
              boolean useCustomClassLoader,
              java.lang.String classPath,
              boolean useSSL,
              boolean blindTrust,
              java.lang.String sslKeyStore,
              java.lang.String sslKeyStorePassword,
              java.lang.String sslTrustStore,
              java.lang.String sslTrustStorePassword,
              ClientMessageWriter messageWriter)
       throws ClientException
Creates a new client that will communicate with the SLAMD server at the specified address and port, and will have the option of using SSL. There will not be any authentication performed.

Parameters:
serverAddress - The IP address or DNS hostname of the SLAMD server.
serverPort - The port number on which the SLAMD server is listening for client connections.
serverStatPort - The port number on which the SLAMD server listens for real-time statistical data.
supportsTimeSync - Indicates whether the client should support time synchronization with the server.
enableRealTimeStats - Indicates whether the client should support the collection of real-time statistics for reporting back to the SLAMD server.
statReportInterval - The length of time in seconds between stat updates to the server.
persistStatistics - Indicates whether the client should periodically save statistical data on disk.
persistenceDirectory - The directory in which the persisted data will be written.
persistenceInterval - The interval in seconds between saves of the persistence data.
restrictedMode - Indicates whether this client will operate in restricted mode, meaning that the server should only ask it to run jobs for which it has been explicitly requested.
useCustomClassLoader - Indicates whether to use the custom class loader for loading job classes.
classPath - The path to which Java class files will be written if they are sent from the client to the server using a class transfer response.
useSSL - Indicates whether SSL will be used on the connection between the client and the server.
blindTrust - Indicates whether the client should blindly trust any SSL certificate presented by the SLAMD server.
sslKeyStore - The location of the JSSE key store that will be used if the communication between the client and the server is SSL-based.
sslKeyStorePassword - The password needed to access the SSL key store.
sslTrustStore - The location of the JSSE trust store that will be used if the communication between the client and the server is SSL-based.
sslTrustStorePassword - The password needed to access the SSL trust store
messageWriter - The writer to which informational and verbose messages will be written.
Throws:
ClientException - If some problem is encountered while creating the client.

Client

public Client(java.lang.String serverAddress,
              int serverPort,
              int serverStatPort,
              boolean supportsTimeSync,
              boolean enableRealTimeStats,
              int statReportInterval,
              boolean persistStatistics,
              java.lang.String persistenceDirectory,
              int persistenceInterval,
              int authType,
              java.lang.String authID,
              java.lang.String authCredentials,
              boolean restrictedMode,
              boolean useCustomClassLoader,
              java.lang.String classPath,
              ClientMessageWriter messageWriter)
       throws ClientException
Creates a new client that will communicate with the SLAMD server at the specified address and port, and will use the specified authentication type. The connection will not use SSL.

Parameters:
serverAddress - The IP address or DNS hostname of the SLAMD server.
serverPort - The port number on which the SLAMD server is listening for client connections.
serverStatPort - The port number on which the SLAMD server listens for real-time statistical data.
supportsTimeSync - Indicates whether the client should support time synchronization with the server.
enableRealTimeStats - Indicates whether the client should support the collection of real-time statistics for reporting back to the SLAMD server.
statReportInterval - The length of time in seconds between stat updates to the server.
persistStatistics - Indicates whether the client should periodically save statistical data on disk.
persistenceDirectory - The directory in which the persisted data will be written.
persistenceInterval - The interval in seconds between saves of the persistence data.
authType - The type of authentication to perform with the SLAMD server.
authID - The ID to use to authenticate to the SLAMD server.
authCredentials - The credentials that will be used to authenticate to the SLAMD server.
restrictedMode - Indicates whether this client should operate in restricted mode.
useCustomClassLoader - Indicates whether to use the custom class loader for loading job classes.
classPath - The path to which Java class files will be written if they are sent from the client to the server using a class transfer response.
messageWriter - The writer to which informational and verbose messages will be written.
Throws:
ClientException - If some problem is encountered while creating the client.

Client

public Client(java.lang.String serverAddress,
              int serverPort,
              int serverStatPort,
              boolean supportsTimeSync,
              boolean enableRealTimeStats,
              int statReportInterval,
              boolean persistStatistics,
              java.lang.String persistenceDirectory,
              int persistenceInterval,
              int authType,
              java.lang.String authID,
              java.lang.String authCredentials,
              boolean restrictedMode,
              boolean useCustomClassLoader,
              java.lang.String classPath,
              boolean useSSL,
              boolean blindTrust,
              java.lang.String sslKeyStore,
              java.lang.String sslKeyStorePassword,
              java.lang.String sslTrustStore,
              java.lang.String sslTrustStorePassword,
              ClientMessageWriter messageWriter)
       throws ClientException
Creates a new client that will communicate with the SLAMD server at the specified address and port, and will use the specified authentication type and optionally may use SSL.

Parameters:
serverAddress - The IP address or DNS hostname of the SLAMD server.
serverPort - The port number on which the SLAMD server is listening for client connections.
serverStatPort - The port number on which the SLAMD server listens for real-time statistical data.
supportsTimeSync - Indicates whether the client should support time synchronization with the server.
enableRealTimeStats - Indicates whether the client should support the collection of real-time statistics for reporting back to the SLAMD server.
statReportInterval - The length of time in seconds between stat updates to the server.
persistStatistics - Indicates whether the client should periodically save statistical data on disk.
persistenceDirectory - The directory in which the persisted data will be written.
persistenceInterval - The interval in seconds between saves of the persistence data.
authType - The type of authentication to perform with the SLAMD server.
authID - The ID to use to authenticate to the SLAMD server.
authCredentials - The credentials that will be used to authenticate to the SLAMD server.
restrictedMode - Indicates whether this client will operate in restricted mode, meaning that the server should only ask it to run jobs for which it has been explicitly requested.
useCustomClassLoader - Indicates whether to use the custom class loader for loading job classes.
classPath - The path to which Java class files will be written if they are sent from the client to the server using a class transfer response.
useSSL - Indicates whether SSL will be used on the connection between the client and the server.
blindTrust - Indicates whether the client should blindly trust any SSL certificate presented by the SLAMD server.
sslKeyStore - The location of the JSSE key store that will be used if the communication between the client and the server is SSL-based.
sslKeyStorePassword - The password needed to access the SSL key store.
sslTrustStore - The location of the JSSE trust store that will be used if the communication between the client and the server is SSL-based.
sslTrustStorePassword - The password needed to access the SSL trust store
messageWriter - The writer to which informational and verbose messages will be written.
Throws:
ClientException - If some problem is encountered while creating the client.
Method Detail

disconnect

public void disconnect()
Disconnects the client from the SLAMD server. This method will not return until the client has actually disconnected.


getMessageWriter

public ClientMessageWriter getMessageWriter()
Retrieves the message writer associated with this client.

Returns:
The message writer associated with this client.

setShutdownListener

public void setShutdownListener(ClientShutdownListener shutdownListener)
Specifies the listener that should be notified when the client stops running.

Parameters:
shutdownListener - The listener that should be notified when the client stops running.

aggregateThreadData

public boolean aggregateThreadData()
Indicates whether the client should aggregate the data collected from all the threads before sending the results to the SLAMD server.

Returns:
true if the client should aggregate the thread data before sending the results to the SLAMD server, or false if the data for each thread is to be reported separagely.

aggregateThreadData

public void aggregateThreadData(boolean aggregateThreadData)
Specifies whether the client should aggregate the data collected from all the threads before sending the results to the SLAMD server.

Parameters:
aggregateThreadData - Specifies whether the client should aggregate the data collected from all the threads before sending the results to the SLAMD server.

usingSSL

public boolean usingSSL()
Indicates whether the connection between the client and the server is using SSL.

Returns:
true if the communication between the client and the server is using SSL, or false if not.

getAuthType

public int getAuthType()
Retrieves the type of authentication that the client used.

Returns:
The type of authentication that the client used.

getServerPort

public int getServerPort()
Retrieves the port on which the SLAMD client is communicating with the SLAMD server.

Returns:
The port on which the client is communicating with the SLAMD server.

getAuthenticationID

public java.lang.String getAuthenticationID()
Retrieves the ID that the client used when authenticating to the server.

Returns:
The ID that the client used when authenticating to the server.

getClassPath

public java.lang.String getClassPath()
Retrieves the path to which Java class files sent by the server will be written.

Returns:
The path to which Java class files sent by the server will be written.

getClientID

public java.lang.String getClientID()
Retrieves the user-friendly client ID that should show up in log messages.

Returns:
The user-friendly client ID that should show up in log messages.

getServerAddress

public java.lang.String getServerAddress()
Retrieves the address of the SLAMD server to which this client is connected.

Returns:
The address fo the SLAMD server to which this client is connected.

getSSLKeyStore

public java.lang.String getSSLKeyStore()
Retrieves the location of the SSL key store that this client is using.

Returns:
The location of the SSL key store that this client is using.

getSSLTrustStore

public java.lang.String getSSLTrustStore()
Retrieves the location of the SSL trust store that this client is using.

Returns:
The location of the SSL trust store that this client is using.

getStatPersistenceThread

public static StatPersistenceThread getStatPersistenceThread()
Retrieves the reference to the thread used for persisting statistical data on disk.

Returns:
The reference to the thread used for persisting statistical data on disk, or null if client-side persistence is not enabled.

registerPersistentStatistic

public static void registerPersistentStatistic(StatTracker tracker)
Registers the provided stat tracker with the persistence thread so that its data will be periodically persisted on disk. This will have no effect if persistence is not enabled.

Parameters:
tracker - The stat tracker to register with the persistence thread.

run

public void run()
Loop infinitely waiting for a request to come in. When a new request does arrive, handle it appropriately and wait for the next request. The process of handling the request should send any appropriate responses and may involve interacting with client threads.


handleJobControlRequest

public void handleJobControlRequest(JobControlRequestMessage request)
Performs any work requested by the provide job control request and sends the appropriate response.

Parameters:
request - The job control request to be processed.

handleJobRequest

public void handleJobRequest(JobRequestMessage request)
Configures the client to start processing the new job specified in the job request and sends the appropriate response.

Parameters:
request - The job request to be processed.

handleStatusRequestMessage

public void handleStatusRequestMessage(StatusRequestMessage request)
Handles the provided status request by gathering the requested information and sending it back to the server.

Parameters:
request - The status request to be processed.

sendMessage

public void sendMessage(Message message)
                 throws java.io.IOException
Sends the requested message to the SLAMD server. The response will be handled asynchronously, so there is no way for something that calls this method to be immediately notified of any response.

Parameters:
message - The message to send to the SLAMD server.
Throws:
java.io.IOException - If a problem occurs while sending the message to the SLAMD server.

startJob

public int startJob()
Attempts to start the current job.

Returns:
The response code associated with the attempt.

stopJob

public int stopJob(int stopReason,
                   boolean waitForStop)
Attempts to stop the current job.

Parameters:
stopReason - The reason that the job is to be stopped.
waitForStop - Indicates whether this method should wait for the job to actually stop before returning, or if it should return as soon as the stop signal has been issued.
Returns:
The result code from the stop operation.

jobDone

public void jobDone()
Used by the job to indicate to the client that it has completed processing and that the client should gather all the appropriate summary information and send it back to the server.


getMessageID

public int getMessageID()
Retrieves the message ID that the client should use for the next message that will be sent to the SLAMD server. The client will use even-numbered message IDs for messages that it originates and the server will use odd-numbered message IDs for messages that it originates. Messages sent in response to a previous request will use the same message ID as the request.

Returns:
The message ID that the client should use for the next message that will be sent to the SLAMD server.

writeMessage

public void writeMessage(java.lang.String message)
Writes a message that may be seen by clients.

Parameters:
message - The message to be written.

writeVerbose

public void writeVerbose(java.lang.String message)
Writes a verbose message that may be seen by clients if they have enabled verbose messages.

Parameters:
message - The message to be written.