com.sun.slamd.server
Class ClientListener

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

public class ClientListener
extends java.lang.Thread
implements ConfigSubscriber

This class implements the client listener that the SLAMD server uses to listen for connections from clients. If fewer than the maximum connections are established, then the connection will be accepted and a new connection thread will be spawned to handle operations on that connection. If the maximum number of connections are already in use, then the new connection will be rejected.


Field Summary
 
Fields inherited from class java.lang.Thread
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY
 
Constructor Summary
ClientListener(SLAMDServer slamdServer)
          Creates a new listener to accept client connections.
 
Method Summary
 void connectionLost(ClientConnection clientConnection)
          Indicates that the specified connection is closing and all refrences to it should be removed.
 boolean connectionsAvailable(Job job)
          Indicates whether the client listener currently has connections available that satisfy the requirements for the indicated job.
 boolean forceDisconnect(java.lang.String clientID)
          Forcefully closes the connection to the specified client and removes all references to it from the SLAMD server.
 void forcefullyDisconnectAll()
          Forcefully closes the connections for all clients connected to the SLAMD server.
 ClientConnection[] getClientConnections(Job job)
          Retrieves the set of client connections for processing the specified job.
 ClientConnection[] getConnectionList()
          Retrieves the set of connections that are currently established.
 int getKeepAliveInterval()
          Retrieves the length of time that should pass between keepalive messages.
 int getMaxClients()
          Retrieves the maximum number of concurrent client connections that should be allowed for this listener.
 int getMaxResponseWaitTime()
          Retrieves the maximum amount of time in seconds that a client connection should wait for a response to a solicited message before returning an error.
 java.lang.String getNewConnectionID()
          Retrieves a connection ID that can be used to uniquely identify each client connection.
 java.lang.String getSubscriberName()
          Retrieves the name that the client listener uses to subscribe to the configuration handler in order to be notified of configuration changes.
 ParameterList getSubscriberParameters()
          Retrieves the set of configuration parameters associated with this configuration subscriber.
 void refreshSubscriberConfiguration()
          Re-reads all configuration information used by the client listener.
 void refreshSubscriberConfiguration(java.lang.String parameterName)
          Re-reads the configuration for the specified parameter if the parameter is applicable to the client listener.
 boolean requestDisconnect(java.lang.String clientID)
          Sends a message to the specified client indicating that it should disconnect from the SLAMD server.
 void requestDisconnectAll()
          Sends a message to each client indicating that it should disconnect itself from the SLAMD server.
 boolean requireAuthentication()
          Indicates whether this client listener requries clients to authenticate.
 void run()
          Creates the server socket and listens for new connections.
 void setAvailableForProcessing(ClientConnection clientConnection)
          Indicates that the specified client connection is available for processing new jobs.
 void startListening()
          Indicates that the listener should start listening for client connections.
 void stopListening()
          Indicates that the listener should stop listening for client connections.
 boolean useSSL()
          Indicates whether this client listener is configured to use SSL.
 void waitForStop()
          This method will not return until the client listener has actually stopped.
 
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
 

Constructor Detail

ClientListener

public ClientListener(SLAMDServer slamdServer)
Creates a new listener to accept client connections.

Parameters:
slamdServer - The SLAMD server with which this listener is associated.
Method Detail

startListening

public void startListening()
Indicates that the listener should start listening for client connections.


stopListening

public void stopListening()
Indicates that the listener should stop listening for client connections. It will also notify all connected clients that the listener is shutting down.


waitForStop

public void waitForStop()
This method will not return until the client listener has actually stopped. Note that it does not stop the listener -- you should first call the stopListening method to signal the listener that it needs to stop.


run

public void run()
Creates the server socket and listens for new connections. If the connection will be accepted, then a new connection thread will be spawned to handle it. If the connection will not be accepted, then it will be rejected here.

Specified by:
run in interface java.lang.Runnable

connectionsAvailable

public boolean connectionsAvailable(Job job)
Indicates whether the client listener currently has connections available that satisfy the requirements for the indicated job.

Parameters:
job - The job for which to make the determination.
Returns:
true if this client listener has an appropriate set of clients available, or false if not.

getClientConnections

public ClientConnection[] getClientConnections(Job job)
Retrieves the set of client connections for processing the specified job.

Parameters:
job - The job for which the connections are to be retrieved.
Returns:
The appropriate set of clients for the specified job, or null if there is not an appropriate set of connections available.

getConnectionList

public ClientConnection[] getConnectionList()
Retrieves the set of connections that are currently established. This is only for use for status info because not all of the connections may be available for processing a new job.

Returns:
The set of connections that are currently established.

getNewConnectionID

public java.lang.String getNewConnectionID()
Retrieves a connection ID that can be used to uniquely identify each client connection.

Returns:
A connection ID that can be used to uniquely identify each client connection.

requireAuthentication

public boolean requireAuthentication()
Indicates whether this client listener requries clients to authenticate.

Returns:
true if clients are required to authenticate, or false if they are not.

requestDisconnect

public boolean requestDisconnect(java.lang.String clientID)
Sends a message to the specified client indicating that it should disconnect from the SLAMD server. If it is currently processing a job, then the client will be given an opportunity to send its results to the SLAMD server.

Parameters:
clientID - The client ID of the client to which the request is to be sent.
Returns:
true if a request was sent to the specified client, or false if not.

requestDisconnectAll

public void requestDisconnectAll()
Sends a message to each client indicating that it should disconnect itself from the SLAMD server. If any clients are currently processing jobs, then those clients will be given an opportunity to send their results to the SLAMD server.


forceDisconnect

public boolean forceDisconnect(java.lang.String clientID)
Forcefully closes the connection to the specified client and removes all references to it from the SLAMD server. If it is currently processing a job, then the job will be notified that the client has disconnected and should not expect any results from that client.

Parameters:
clientID - The client ID of the client to be disconnected.
Returns:
true if the client was disconnected, or false if not.

forcefullyDisconnectAll

public void forcefullyDisconnectAll()
Forcefully closes the connections for all clients connected to the SLAMD server. If any clients are currently processing a job, then no information will be available for that job from those clients.


connectionLost

public void connectionLost(ClientConnection clientConnection)
Indicates that the specified connection is closing and all refrences to it should be removed.

Parameters:
clientConnection - The connection that is shutting down.

setAvailableForProcessing

public void setAvailableForProcessing(ClientConnection clientConnection)
Indicates that the specified client connection is available for processing new jobs. This will be called by the client connection when the client indicates that it has finished processing a job that had been assigned to it.

Parameters:
clientConnection - The connection that is announcing its availability.

getKeepAliveInterval

public int getKeepAliveInterval()
Retrieves the length of time that should pass between keepalive messages. A keepalive message will be sent if there has been no interaction with the client for the specified period of time.

Returns:
The length of time that should pass between keepalive messages.

getMaxClients

public int getMaxClients()
Retrieves the maximum number of concurrent client connections that should be allowed for this listener.

Returns:
The maximum number of concurrent connections that should be allowed for this listener.

getMaxResponseWaitTime

public int getMaxResponseWaitTime()
Retrieves the maximum amount of time in seconds that a client connection should wait for a response to a solicited message before returning an error.

Returns:
The maximum amount of time in seconds that a client connection should wait for a response to a solicited message before returning an error.

useSSL

public boolean useSSL()
Indicates whether this client listener is configured to use SSL.

Returns:
true if this client listener is configured to use SSL, or false if it is not.

getSubscriberName

public java.lang.String getSubscriberName()
Retrieves the name that the client listener uses to subscribe to the configuration handler in order to be notified of configuration changes.

Specified by:
getSubscriberName in interface ConfigSubscriber
Returns:
The name that the client listener uses to subscribe to the configuration handler in order to be notified of configuration changes.

getSubscriberParameters

public ParameterList getSubscriberParameters()
Retrieves the set of configuration parameters associated with this configuration subscriber.

Specified by:
getSubscriberParameters in interface ConfigSubscriber
Returns:
The set of configuration parameters associated with this configuration subscriber.

refreshSubscriberConfiguration

public void refreshSubscriberConfiguration()
                                    throws SLAMDServerException
Re-reads all configuration information used by the client listener. In this case, the only options are the keepalive interval, the maximum number of clients, and the maximum response wait time. The listen port is not dynamically reconfigurable. Additionally, changes made to the keepalive interval, maximum number of connections, and maximum wait time will only apply to new connections established after this point. Existing connections will remain unchanged.

Specified by:
refreshSubscriberConfiguration in interface ConfigSubscriber
Throws:
SLAMDServerException - If there is a problem reading or applying the changes.

refreshSubscriberConfiguration

public void refreshSubscriberConfiguration(java.lang.String parameterName)
                                    throws SLAMDServerException
Re-reads the configuration for the specified parameter if the parameter is applicable to the client listener. In this case, only the keepalive interval, maximum number of client connections, and maximum response wait time are reconfigurable.

Specified by:
refreshSubscriberConfiguration in interface ConfigSubscriber
Parameters:
parameterName - The name of the parameter for which to reread the configuration.
Throws:
SLAMDServerException - If there is a problem reading or applying the specified change.