public class JobAgentServerConnection
extends java.lang.Object
implements java.lang.AutoCloseable
Modifier and Type | Class and 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 a
RequestHandler . |
Modifier and Type | Field and Description |
---|---|
private java.lang.Thread |
listener |
private org.slf4j.Logger |
logger |
private int |
port |
private RequestHandler |
requestHandler |
Constructor and Description |
---|
JobAgentServerConnection(int port,
RequestHandler requestHandler,
org.slf4j.Logger logger)
Create a new server connection.
|
Modifier and Type | Method and 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.
|
private final int port
private final RequestHandler requestHandler
private final org.slf4j.Logger logger
private java.lang.Thread listener
public JobAgentServerConnection(int port, RequestHandler requestHandler, org.slf4j.Logger logger)
open()
method must be called
to start listening for incoming connections.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 wantedpublic void open() throws java.io.IOException
RequestHandler
. If a listener
has already been create thi method does nothing.java.io.IOException
- If there is an errorpublic void close()
close
in interface java.lang.AutoCloseable
public boolean isListening()