com.sun.slamd.server
Class ClientManagerConnection

java.lang.Object
  extended by java.lang.Thread
      extended by com.sun.slamd.server.ClientManagerConnection
All Implemented Interfaces:
java.lang.Runnable

public class ClientManagerConnection
extends java.lang.Thread

This class encapsulates a connection to a client manager, and it is used to keep track of information about them.

Author:
Neil A. Wilson

Nested Class Summary
 
Nested classes/interfaces inherited from class java.lang.Thread
java.lang.Thread.State, java.lang.Thread.UncaughtExceptionHandler
 
Field Summary
 
Fields inherited from class java.lang.Thread
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY
 
Constructor Summary
ClientManagerConnection(SLAMDServer slamdServer, ClientManagerListener listener, java.net.Socket clientManagerSocket)
          Creates a new client manager connection using the provided socket.
 
Method Summary
 void clientConnectionLost()
          Indicates that a client believed to have been started by this client manager has been lost and that the list of active connections should be updated accordingly.
 void disconnect(boolean sendShutdownMessage)
          Closes the connection to the client manager.
 java.lang.String getClientID()
          Retrieves the ID of the client associated with this client manager connection.
 java.lang.String getClientIPAddress()
          Retrieves the IP address of the client manager system.
 java.lang.String getClientVersion()
          Retrieves the software version of the client associated with this client manager connection.
 java.util.Date getEstablishedTime()
          Retrieves the time at which this connection was established.
 int getMaxClients()
          Retrieves the maximum number of clients that may be started for this client manager.
 Message getMessage(int messageID)
          Retrieves the message with the specified message ID from the receive queue.
 int getStartedClients()
          Retrieves the number of clients associated with this client manager that are currently running.
 int nextMessageID()
          Retrieves the message ID that should be used for the next request sent to the client manager.
 void run()
          Create a loop that waits for new communication to arrive from the client manager.
 void startClients(int numClients)
          Requests that the client manager start the specified number of clients.
 void stopClients(int numClients)
          Requests that the client manager start the specified number of clients.
 
Methods inherited from class java.lang.Thread
activeCount, checkAccess, countStackFrames, currentThread, destroy, dumpStack, enumerate, getAllStackTraces, getContextClassLoader, getDefaultUncaughtExceptionHandler, getId, getName, getPriority, getStackTrace, getState, getThreadGroup, getUncaughtExceptionHandler, holdsLock, interrupt, interrupted, isAlive, isDaemon, isInterrupted, join, join, join, resume, setContextClassLoader, setDaemon, setDefaultUncaughtExceptionHandler, setName, setPriority, setUncaughtExceptionHandler, 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
 

Constructor Detail

ClientManagerConnection

public ClientManagerConnection(SLAMDServer slamdServer,
                               ClientManagerListener listener,
                               java.net.Socket clientManagerSocket)
                        throws SLAMDException
Creates a new client manager connection using the provided socket.

Parameters:
slamdServer - The SLAMD server with which this client manager connection is associated.
listener - The client manager listener associated with this connection.
clientManagerSocket - The socket used to communicate with the client manager.
Throws:
SLAMDException - If a problem occurs while creating the client manager connection.
Method Detail

getClientID

public java.lang.String getClientID()
Retrieves the ID of the client associated with this client manager connection.

Returns:
The ID of the client associated with this client manager connection.

getClientIPAddress

public java.lang.String getClientIPAddress()
Retrieves the IP address of the client manager system.

Returns:
The IP address of the client manager system.

getClientVersion

public java.lang.String getClientVersion()
Retrieves the software version of the client associated with this client manager connection.

Returns:
The software version of the client associated with this client manager connection.

getEstablishedTime

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

Returns:
The time at which this connection was established.

getMaxClients

public int getMaxClients()
Retrieves the maximum number of clients that may be started for this client manager.

Returns:
The maximum number of clients that may be started for this client manager.

getStartedClients

public int getStartedClients()
Retrieves the number of clients associated with this client manager that are currently running.

Returns:
The number of clients associated with this client manager that are currently running.

startClients

public void startClients(int numClients)
                  throws SLAMDException
Requests that the client manager start the specified number of clients.

Parameters:
numClients - The number of clients to be started by this client manager.
Throws:
SLAMDException - If the number of clients requested would cause the client manager to start more than the maximum allowed number of clients, or if there is a problem starting any of the clients.

stopClients

public void stopClients(int numClients)
                 throws SLAMDException
Requests that the client manager start the specified number of clients.

Parameters:
numClients - The number of clients to be stopped by this client manager. A negative value will indicate that all clients should be stopped.
Throws:
SLAMDException - If the requested number of clients is greater than the number of clients actually running, or if a problem occurs while trying to stop the clients.

disconnect

public void disconnect(boolean sendShutdownMessage)
Closes the connection to the client manager. The process of closing the connection may optionally include sending a shutdown message to the client manager before the actual disconnect.

Parameters:
sendShutdownMessage - Indicates whether a server shutdown message should be sent to the client manager before the connection is closed.

clientConnectionLost

public void clientConnectionLost()
Indicates that a client believed to have been started by this client manager has been lost and that the list of active connections should be updated accordingly.


nextMessageID

public int nextMessageID()
Retrieves the message ID that should be used for the next request sent to the client manager.

Returns:
The message ID that should be used for the next request sent to the client manager.

getMessage

public Message getMessage(int messageID)
Retrieves the message with the specified message ID from the receive queue.

Parameters:
messageID - The message ID of the message to retrieve.
Returns:
The requested message, or null if an appropriate response does not arrive within an appropriate timeout period.

run

public void run()
Create a loop that waits for new communication to arrive from the client manager. If it is a solicited response (i.e, has a message ID that is an even number), then put it in the message queue to be picked up by an appropriate listener. If it is an unsolicited message (i.e., has an odd number), then try to handle it directly.

Specified by:
run in interface java.lang.Runnable
Overrides:
run in class java.lang.Thread