public class Listener extends Thread
Thread.State, Thread.UncaughtExceptionHandler
Modifier and Type | Field and Description |
---|---|
(package private) Map<Integer,Acceptor> |
acceptors |
(package private) Map<ServerSocketChannel,ConnectionFactory> |
factories |
private FatalErrorHandler |
fatalErrorHandler |
private static Logger |
log |
private LinkedList<UpdateInterest> |
modifyInterestOpsQueue |
private LinkedList<Connection> |
newConnections |
private List<SelectLoopHook> |
selectLoopPostHooks |
private List<SelectLoopHook> |
selectLoopPreHooks |
private Selector |
selector |
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY
Modifier and Type | Method and Description |
---|---|
Connection |
addNewConnection(Connection newConn)
This method is used by the Acceptor to hand off newly accepted
connections to the Listener.
|
void |
addSelectLoopPostHook(SelectLoopHook hook)
Add pre-select loop hook.
|
void |
addSelectLoopPreHook(SelectLoopHook hook)
Add pre-select loop hook.
|
void |
listen(ConnectionFactory factory,
int port)
Add a listening port and create an Acceptor thread which accepts
new connections on this port.
|
void |
listenNoAcceptor(ConnectionFactory factory,
int port)
Add a listening port without creating a separate acceptor
thread.
|
Listener |
modifyInterestOps(Connection connection,
int op,
boolean set)
This is the preferred way of modifying interest ops, giving a
Connection rather than a SelectionKey as input.
|
Listener |
modifyInterestOps(SelectionKey key,
int op,
boolean set)
Enqueue change to interest set of SelectionKey.
|
Listener |
modifyInterestOpsBatch(Connection connection,
int op,
boolean set)
Batch version of modifyInterestOps().
|
Listener |
modifyInterestOpsBatch(SelectionKey key,
int op,
boolean set)
Does the same as modifyInterestOps(), but does not call
wakeup on the selector.
|
Listener |
modifyInterestOpsDone()
Signal that a batch update of SelectionKey is done and the
selector should be awoken.
|
private void |
performAccept(SelectionKey key)
Accept new connection.
|
private void |
performConnect(SelectionKey key)
Complete asynchronous connect operation.
|
private void |
performRead(SelectionKey key)
Perform read operation on channel which is now ready for reading
|
private void |
performWrite(SelectionKey key)
Perform write operation(s) on channel which is now ready for
writing
|
private void |
processModifyInterestOps()
Process enqueued changes to SelectionKeys.
|
private void |
processNewConnections()
This method is called from the selectLoop() method in order to
process new incoming connections.
|
void |
registerConnection(Connection connection)
Register a connection that was set up outside the listener.
|
void |
run()
Thread entry point
|
private void |
runSelectLoopPostHooks()
Run all the select loop post hooks
|
private void |
runSelectLoopPreHooks()
Run all the select loop pre hooks
|
private void |
selectLoop()
Check channels for readiness and deal with channels that have
pending operations.
|
void |
setFatalErrorHandler(FatalErrorHandler f)
Register a handler for fatal errors.
|
void |
shutdown()
Perform clean shutdown of Listener.
|
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 Logger log
private Selector selector
Map<ServerSocketChannel,ConnectionFactory> factories
private FatalErrorHandler fatalErrorHandler
private List<SelectLoopHook> selectLoopPreHooks
private List<SelectLoopHook> selectLoopPostHooks
private final LinkedList<Connection> newConnections
private final LinkedList<UpdateInterest> modifyInterestOpsQueue
public Listener(String name)
public void setFatalErrorHandler(FatalErrorHandler f)
f
- The FatalErrorHandler instance to be registeredpublic void addSelectLoopPreHook(SelectLoopHook hook)
public void addSelectLoopPostHook(SelectLoopHook hook)
private void runSelectLoopPreHooks()
private void runSelectLoopPostHooks()
public void listen(ConnectionFactory factory, int port) throws IOException
factory
- The connection factory for new connections
on this portport
- The port we are going to listen to.IOException
public void listenNoAcceptor(ConnectionFactory factory, int port) throws IOException
factory
- The connection factory for new connections
on this portport
- The port we are going to listen to.IOException
public Listener modifyInterestOps(Connection connection, int op, boolean set)
this
reference for chainingpublic Listener modifyInterestOpsBatch(Connection connection, int op, boolean set)
this
reference for chainingpublic Listener modifyInterestOps(SelectionKey key, int op, boolean set)
this
reference for chainingpublic Listener modifyInterestOpsBatch(SelectionKey key, int op, boolean set)
this
reference for chainingpublic Listener modifyInterestOpsDone()
this
reference for chainingprivate void processModifyInterestOps()
public void run()
private void selectLoop()
public Connection addNewConnection(Connection newConn)
private void processNewConnections()
private void performAccept(SelectionKey key)
private void performConnect(SelectionKey key)
private void performRead(SelectionKey key)
private void performWrite(SelectionKey key)
public void registerConnection(Connection connection)
public void shutdown()
Copyright © 2018. All rights reserved.