public class SocketAcceptorThread extends Thread
Provides a thread that will wait for incoming connections for 3rd party processes and notify
any listeners (of type INewClientSocketListener
) when those connections are made. Multiple
listeners are supported.
Thread.State, Thread.UncaughtExceptionHandler
Modifier and Type | Field and Description |
---|---|
private Process |
bindToPort |
private static org.slf4j.Logger |
log |
private List<INewClientSocketListener> |
newConnectionListeners |
private ServerSocket |
serverSocket |
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY
Constructor and Description |
---|
SocketAcceptorThread(Process bindToPort) |
Modifier and Type | Method and Description |
---|---|
void |
addNewConnectionListener(INewClientSocketListener listener) |
static ServerSocket |
openServerSocket(Process bindToPort)
Opens the
ServerSocket on the specified port |
void |
removeConnectionListener(INewClientSocketListener listener) |
void |
run() |
private void |
waitForClient()
Blocks the thread and waits for a new inbound client to connect.
|
activeCount, checkAccess, clone, countStackFrames, currentThread, destroy, dumpStack, enumerate, getAllStackTraces, getContextClassLoader, getDefaultUncaughtExceptionHandler, getId, getName, getPriority, getStackTrace, getState, getThreadGroup, getUncaughtExceptionHandler, holdsLock, interrupt, interrupted, isAlive, isDaemon, isInterrupted, join, join, join, resume, setContextClassLoader, setDaemon, setDefaultUncaughtExceptionHandler, setName, setPriority, setUncaughtExceptionHandler, sleep, sleep, start, stop, stop, suspend, toString, yield
private static final org.slf4j.Logger log
private final Process bindToPort
private final ServerSocket serverSocket
private final List<INewClientSocketListener> newConnectionListeners
public SocketAcceptorThread(Process bindToPort) throws IllegalArgumentException, FailedToBindToPortException
public void addNewConnectionListener(INewClientSocketListener listener)
public void removeConnectionListener(INewClientSocketListener listener)
private void waitForClient()
Blocks the thread and waits for a new inbound client to connect.
NOTE: No exception is thrown in the case a client connection cannot be created.
ServerSocket.accept()
public static ServerSocket openServerSocket(Process bindToPort) throws FailedToBindToPortException
ServerSocket
on the specified portbindToPort
- The port to bind the server socket toFailedToBindToPortException
- If the server socket fails to bind to the specified port.Copyright © 2017. All rights reserved.