Package net.sf.basedb.util.jobagent
Class JobAgentServerConnection
java.lang.Object
net.sf.basedb.util.jobagent.JobAgentServerConnection
- All Implemented Interfaces:
AutoCloseable
public class JobAgentServerConnection extends Object implements AutoCloseable
This class is used by job agents to listen for incoming
requests from client applications.
- Version:
- 2.0
- Author:
- nicklas
- Last modified
- $Date: 2018-12-12 15:41:10 +0100 (on, 12 dec 2018) $
-
Nested Class Summary
Nested Classes Modifier and Type Class Description 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 aRequestHandler
. -
Field Summary
Fields Modifier and Type Field Description private Thread
listener
private org.slf4j.Logger
logger
private int
port
private RequestHandler
requestHandler
-
Constructor Summary
Constructors Constructor Description JobAgentServerConnection(int port, RequestHandler requestHandler, org.slf4j.Logger logger)
Create a new server connection. -
Method Summary
Modifier and Type Method Description 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.
-
Field Details
-
port
private final int port -
requestHandler
-
logger
private final org.slf4j.Logger logger -
listener
-
-
Constructor Details
-
JobAgentServerConnection
Create a new server connection. Theopen()
method must be called to start listening for incoming connections.- Parameters:
port
- The port to listing to for incoming connectionsrequestHandler
- A handler for taking care of incoming requests. The handler must be thread-safe and able to handle multiple requests at the same timelogger
- A logger object for logging debug and other information or null if no logging is wanted
-
-
Method Details
-
open
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 theRequestHandler
. 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.- Specified by:
close
in interfaceAutoCloseable
-
isListening
public boolean isListening()Is a listener active or not for this server.- Returns:
- TRUE if a listener is active, FALSE otherwise
-