2.17.2: 2011-06-17

net.sf.basedb.util.jobagent
Class JobAgentServerConnection

java.lang.Object
  extended by net.sf.basedb.util.jobagent.JobAgentServerConnection

public class JobAgentServerConnection
extends Object

This class is used by job agents to listen for incoming requests from client applications.

Version:
2.0
Author:
nicklas
Last modified
$Date: 2008-09-11 22:08:14 +0200 (Thu, 11 Sep 2008) $

Nested Class Summary
private static class JobAgentServerConnection.ListenerThread
          This class is used for listening to the specified socket for incoming connections.
private static class JobAgentServerConnection.RequestHandlerThread
          This class is used for forwarding requests to a RequestHandler.
 
Field Summary
private  Thread listener
           
private  Logger logger
           
private  int port
           
private  RequestHandler requestHandler
           
 
Constructor Summary
JobAgentServerConnection(int port, RequestHandler requestHandler, Logger logger)
          Create a new server connection.
 
Method Summary
 void close()
          Stop listening for incoming connections.
 boolean isListening()
          Is a listener active or not for this server.
 void open()
          Start listening for incoming connections.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

port

private final int port

requestHandler

private final RequestHandler requestHandler

logger

private final Logger logger

listener

private Thread listener
Constructor Detail

JobAgentServerConnection

public JobAgentServerConnection(int port,
                                RequestHandler requestHandler,
                                Logger logger)
Create a new server connection. The open() method must be called to start listening for incoming connections.

Parameters:
port - The port to listing to for incoming connections
requestHandler - A handler for taking care of incoming requests. The handler must be thread-safe and able to handle multiple requests at the same time
logger - A logger object for logging debug and other information or null if no logging is wanted
Method Detail

open

public void open()
          throws IOException
Start listening for incoming connections. This method starts a new listener thread that answers incoming requests. For each request a new thread is created and control is passed on to the RequestHandler. If a listener has already been create thi method does nothing.

Throws:
IOException - If there is an error

close

public void close()
Stop listening for incoming connections. The thread that listens for incoming connections is killed. Any executing requests are not affected by this method.


isListening

public boolean isListening()
Is a listener active or not for this server.

Returns:
TRUE if a listener is active, FALSE otherwise

2.17.2: 2011-06-17