com.sun.slamd.server
Class ClientConnection

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

public class ClientConnection
extends java.lang.Thread

This class defines a thread that is spawned by the server to handle each 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
ClientConnection(SLAMDServer slamdServer, ClientListener clientListener, java.net.Socket clientConnection, java.lang.String connectionID)
          Creates a new connection that the server will use to communicate with the client.
 
Method Summary
 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.
 Job getJob()
          Retrieves the job that the client is currently processing (if any).
 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 restrictedMode()
          Indicates whether this client is operating in restricted mode, in which case it will only be used to handle jobs for which it has been explicitly requested.
 void run()
          Listens for messages from the client and either handles them or hands them off to be handled elsewhere.
 void sendClassFile(ClassTransferRequestMessage transferRequest)
          Sends a class transfer response message to the client that either contains the requested class information or a response code that indicates why it could not be provided.
 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

ClientConnection

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

Parameters:
slamdServer - The SLAMD server with which this connection is associated.
clientListener - The 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 there is a problem with the client 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.

restrictedMode

public boolean restrictedMode()
Indicates whether this client is operating in restricted mode, in which case it will only be used to handle jobs for which it has been explicitly requested.

Returns:
true if this client is operating in restricted mode, or false if it is not.

getJob

public Job getJob()
Retrieves the job that the client is currently processing (if any).

Returns:
The job that the client is currently processing, or null if it is not processing any job.

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.

sendClassFile

public void sendClassFile(ClassTransferRequestMessage transferRequest)
Sends a class transfer response message to the client that either contains the requested class information or a response code that indicates why it could not be provided.

Parameters:
transferRequest - The class transfer request message for which the response is to be provided.

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.