Package net.sf.basedb.util.jobagent
Class JobAgentServerConnection
java.lang.Object
net.sf.basedb.util.jobagent.JobAgentServerConnection
- All Implemented Interfaces:
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
Modifier and TypeClassDescriptionprivate static class
This class is used for listening to the specified socket for incoming connections.private static class
This class is used for forwarding requests to aRequestHandler
. -
Field Summary
Modifier and TypeFieldDescriptionprivate Thread
private final Logger
private final int
private final RequestHandler
-
Constructor Summary
ConstructorDescriptionJobAgentServerConnection
(int port, RequestHandler requestHandler, Logger logger) Create a new server connection. -
Method Summary
-
Field Details
-
port
private final int port -
requestHandler
-
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
-