com.sun.slamd.server
Class ResourceMonitorClientConnection

java.lang.Object
  extended byjava.lang.Thread
      extended bycom.sun.slamd.server.ResourceMonitorClientConnection
All Implemented Interfaces:
java.lang.Runnable

public class ResourceMonitorClientConnection
extends java.lang.Thread

This class defines a thread that is spawned by the server to handle each resource monitor client connection. It takes care of reading messages in from the client and provides methods for sending messages to the client.


Field Summary
 
Fields inherited from class java.lang.Thread
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY
 
Constructor Summary
ResourceMonitorClientConnection(SLAMDServer slamdServer, ResourceMonitorClientListener clientListener, java.net.Socket clientConnection, java.lang.String connectionID)
          Creates a new resource monitor connection that the server will use to communicate with the client.
 
Method Summary
 void addJobInProgress(Job job)
          Adds the provided job to the list of jobs in progress.
 java.lang.String getClientID()
          Retrieves the client ID that the client has chosen for itself.
 java.lang.String getClientIPAddress()
          Retrieves the IP address of the client associated with this connection.
 java.lang.String getConnectionID()
          Retrieves the connection ID assigned to this client connection by the SLAMD server.
 java.util.Date getEstablishedTime()
          Retrieves the time at which this connection was established.
 java.lang.String[] getJobIDsInProgress()
          Retrieves the list of jobs for which this client is collecting resource utilization data.
 Job getJobInProgress(java.lang.String jobID)
          Retrieves information about the specified job in progress.
 Job[] getJobsInProgress()
          Retrieves the list of jobs for which this client is collecting resource utilization data.
 int getMessageID()
          Retrieves the message ID to use in the next message originating from the server.
 Message getResponse(int messageID, int messageType)
          Retrieves a message with the specified message ID and type from the queue used to hold responses to solicited messages.
 java.lang.String getStatusString()
          Retrieves a string with basic status information about the current state of the client.
 boolean jobInProgress()
          Indicates whether at least one job is in progress.
 void removeJobInProgress(Job job)
          Removes the provided job from the list of jobs in progress.
 void run()
          Listens for messages from the client and either handles them or hands them off to be handled elsewhere.
 JobControlResponseMessage sendJobControlRequest(Job job, int controlType)
          Sends a job control request to the client for the specified job.
 JobResponseMessage sendJobRequest(Job job, int clientNumber)
          Sends a job request message to the client.
 void sendMessage(Message message)
          Sends the specified message to the client.
 void sendServerShutdownMessage(boolean closeSocket)
          Sends a message to the client that indicates the server is shutting down, and then optionally closes the connection to the client.
 StatusResponseMessage sendStatusRequestMessage()
          Sends a status request message to the client as a general status request.
 StatusResponseMessage sendStatusRequestMessage(java.lang.String jobID)
          Sends a status request message to the client requesting information about the specified job.
 java.lang.String toString()
          Retrieves a string with information about this client connection.
 
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, yield
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

ResourceMonitorClientConnection

public ResourceMonitorClientConnection(SLAMDServer slamdServer,
                                       ResourceMonitorClientListener clientListener,
                                       java.net.Socket clientConnection,
                                       java.lang.String connectionID)
                                throws SLAMDException
Creates a new resource monitor connection that the server will use to communicate with the client.

Parameters:
slamdServer - The SLAMD server with which this connection is associated.
clientListener - The resource monitor client listener that accepted this connection.
clientConnection - The socket that is used to communicate with the client.
connectionID - The unique identifier associated with the client.
Throws:
SLAMDException - If a problem occurs setting up the connection.
Method Detail

getConnectionID

public java.lang.String getConnectionID()
Retrieves the connection ID assigned to this client connection by the SLAMD server.

Returns:
The connection ID assigned to this client connection by the SLAMD server.

getClientID

public java.lang.String getClientID()
Retrieves the client ID that the client has chosen for itself.

Returns:
The client ID that the client has chosen for itself.

getEstablishedTime

public java.util.Date getEstablishedTime()
Retrieves the time at which this connection was established.

Returns:
The time at which this connection was established.

getClientIPAddress

public java.lang.String getClientIPAddress()
Retrieves the IP address of the client associated with this connection.

Returns:
The IP address of the client associated with this connection.

jobInProgress

public boolean jobInProgress()
Indicates whether at least one job is in progress.

Returns:
true if at least one job is in progress, or false if there are no jobs in progress.

getJobsInProgress

public Job[] getJobsInProgress()
Retrieves the list of jobs for which this client is collecting resource utilization data.

Returns:
The list of jobs for which this client is collecting resource utilization data.

getJobIDsInProgress

public java.lang.String[] getJobIDsInProgress()
Retrieves the list of jobs for which this client is collecting resource utilization data.

Returns:
The list of jobs for which this client is collecting resource utilization data.

getJobInProgress

public Job getJobInProgress(java.lang.String jobID)
Retrieves information about the specified job in progress.

Parameters:
jobID - The job ID of the job for which to retrieve information.
Returns:
Information about the specified job in progress, or null if no information is available.

addJobInProgress

public void addJobInProgress(Job job)
Adds the provided job to the list of jobs in progress.

Parameters:
job - The job to add to the list of jobs in progress.

removeJobInProgress

public void removeJobInProgress(Job job)
Removes the provided job from the list of jobs in progress.

Parameters:
job - The job to remove from the list of jobs in progress.

run

public void run()
Listens for messages from the client and either handles them or hands them off to be handled elsewhere.


sendMessage

public void sendMessage(Message message)
Sends the specified message to the client.

Parameters:
message - The message to send to the client.

getMessageID

public int getMessageID()
Retrieves the message ID to use in the next message originating from the server.

Returns:
The message ID to use in the next message originating from the server.

getResponse

public Message getResponse(int messageID,
                           int messageType)
Retrieves a message with the specified message ID and type from the queue used to hold responses to solicited messages. This will wait for a configurable maximum amount of time for the message to appear before returning null.

Parameters:
messageID - The message ID for the message that is expected.
messageType - The type of message that is expected.
Returns:
The message with the specified message ID and type from the queue used to hold responses to solicited messages.

sendJobRequest

public JobResponseMessage sendJobRequest(Job job,
                                         int clientNumber)
Sends a job request message to the client.

Parameters:
job - The information that should be included in the job request.
clientNumber - The client number for this client.
Returns:
The response from the client.

sendJobControlRequest

public JobControlResponseMessage sendJobControlRequest(Job job,
                                                       int controlType)
Sends a job control request to the client for the specified job.

Parameters:
job - The job with which the request is associated.
controlType - The type of operation being requested.
Returns:
The response from the client.

sendStatusRequestMessage

public StatusResponseMessage sendStatusRequestMessage()
Sends a status request message to the client as a general status request. This request will not be for job-specific information.

Returns:
The status response message corresponding to this status request.

sendStatusRequestMessage

public StatusResponseMessage sendStatusRequestMessage(java.lang.String jobID)
Sends a status request message to the client requesting information about the specified job.

Parameters:
jobID - The ID of the job for which to request status information.
Returns:
The status response message corresponding to this status request.

sendServerShutdownMessage

public void sendServerShutdownMessage(boolean closeSocket)
Sends a message to the client that indicates the server is shutting down, and then optionally closes the connection to the client.

Parameters:
closeSocket - Indicates whether the connection to the client should be closed.

toString

public java.lang.String toString()
Retrieves a string with information about this client connection.

Returns:
A string with information about this client connection.

getStatusString

public java.lang.String getStatusString()
Retrieves a string with basic status information about the current state of the client.

Returns:
A string with basic status information about the current state of the client.