com.ls.lars.communication
Class SocketListener

java.lang.Object
  |
  +--com.ls.lars.communication.SocketListener
All Implemented Interfaces:
Runnable, Serializable
Direct Known Subclasses:
JSecureSocketListener, JSocketListener

public class SocketListener
extends Object
implements Runnable, Serializable

manages incoming client requests via sockets

Version:
$Revision: 1.9 $
Author:
Last modified by $Author: MFehrenbach $
See Also:
Serialized Form

Field Summary
protected  Map connectionParameters
          contains the connection parameters for this Listener, e.g the compression settings
protected  Thread listenerThread
          reference to this thread (needed for proper thread termination)
protected  ILogger logger
          the reference to the owning agent's log file (initally set to SystemLogger.getLogger())
protected  int port
          port number of the server socket
static int socketListenerThreadId
          thread id for socket listeners
 
Constructor Summary
SocketListener(int port)
          Constructor, that sets the agent and port.
 
Method Summary
protected  com.ls.lars.communication.SocketMessenger createClientSocketMessenger(Socket clientSocket)
          creates a client socket messenger (here: a SocketMessenger)
 int nextSocketListenerId()
          returns the next unique (within this Java Virtual Machine) id to be used in a socket listener name
 void run()
          Creates the server socket.
 void setConnectionParameters(Map connectionParameters)
          Sets the connection parameters e.g. compression settings, secure settings, ...
 void setLog(ILogger log)
          Sets the ILogger for the listener.
 void start()
          starts the listener thread and sets the thread name
 void stop()
          stops listener thread in a safe way
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

socketListenerThreadId

public static int socketListenerThreadId
thread id for socket listeners

listenerThread

protected Thread listenerThread
reference to this thread (needed for proper thread termination)

logger

protected ILogger logger
the reference to the owning agent's log file (initally set to SystemLogger.getLogger())

port

protected int port
port number of the server socket

connectionParameters

protected Map connectionParameters
contains the connection parameters for this Listener, e.g the compression settings
Constructor Detail

SocketListener

public SocketListener(int port)
Constructor, that sets the agent and port.
Parameters:
listenerAgent - agent which belongs to this listener
port - port number on which the listener should listen
Method Detail

setLog

public void setLog(ILogger log)
Sets the ILogger for the listener. Should be called directly after creating the listener.
Parameters:
log - reference to the ILogger of the owning agent

start

public void start()
           throws ProgrammingException
starts the listener thread and sets the thread name
Throws:
ProgrammingException - If this listener was already started before

stop

public void stop()
stops listener thread in a safe way

run

public void run()
Creates the server socket. Afterwards it retrieves incoming client socket requests, creates a socket messenger for them and adds these to the message router.
Specified by:
run in interface Runnable

setConnectionParameters

public void setConnectionParameters(Map connectionParameters)
Sets the connection parameters e.g. compression settings, secure settings, ... .
Parameters:
connectionParameters - contains any Map with any parameters

createClientSocketMessenger

protected com.ls.lars.communication.SocketMessenger createClientSocketMessenger(Socket clientSocket)
creates a client socket messenger (here: a SocketMessenger)
Parameters:
clientSocket - socket by that the client is connected to the server
Returns:
the created SocketMessenger

nextSocketListenerId

public int nextSocketListenerId()
returns the next unique (within this Java Virtual Machine) id to be used in a socket listener name
Returns:
the next socket number