public abstract class AcceptLoop extends SelectLoop
Modifier and Type | Field and Description |
---|---|
protected SSLContext |
sslContext
SSL context for secure connections.
|
DEFAULT_TIMEOUT, log, selector, stopped, timeout
Constructor and Description |
---|
AcceptLoop(long timeout,
SocketAddress... addresses)
Creates an accept loop bound to the specified socket address(es) with
the given select timeout.
|
AcceptLoop(SocketAddress... addresses)
Creates an accept loop bound to the specified socket address(es) with
default select timeout.
|
Modifier and Type | Method and Description |
---|---|
protected abstract void |
accept(ServerSocketChannel ssc)
Processes the accept event pending on the specified socket channel.
|
void |
cease()
Gracefully stops the loop.
|
protected void |
closeChannels()
Closes the server socket channel(s).
|
protected ServerSocketChannel |
configureChannel(ServerSocketChannel ssc,
SocketAddress address)
Configures the given server socket channel to be in an unblocking mode,
registers it and binds it to the specified socket address.
|
protected void |
createChannels()
Allocates the server socket channel(s) in non-blocking mode, registers
it (them) with the selector and then binds to the configured listen
address(es).
|
protected void |
loop()
I/O event loop.
|
void |
setSslContext(SSLContext context)
Sets the SSL context for secure connections.
|
SSLContext |
sslContext()
Returns the SSL context used for secure connections.
|
getError, openSelector, run, signalStart, waitForFinish, waitForStart
protected SSLContext sslContext
public AcceptLoop(SocketAddress... addresses) throws IOException
addresses
- listen socket address(es)IllegalArgumentException
- if no addresses are specifiedIOException
- if unable to open selectorpublic AcceptLoop(long timeout, SocketAddress... addresses) throws IOException
timeout
- select timeout in millisecondsaddresses
- listen socket address(es)IllegalArgumentException
- if no addresses are specifiedIOException
- if unable to open selectorpublic void setSslContext(SSLContext context)
context
- the SSL contextpublic SSLContext sslContext()
protected abstract void accept(ServerSocketChannel ssc) throws IOException
ssc
- server socket channel with pending accept operationIOException
- if unable to accept the incoming socket connectionprotected void createChannels() throws IOException
IOException
- if channel could not be created or bound to addressprotected ServerSocketChannel configureChannel(ServerSocketChannel ssc, SocketAddress address) throws IOException
ssc
- the server socket channel to configureaddress
- the address to bind toIOException
- if the channel could not be configuredprotected void closeChannels() throws IOException
IOException
- if any channel could not be closedpublic void cease()
This implementation first closes the channels, then terminates the loop.
cease
in class SelectLoop
protected void loop() throws IOException
SelectLoop.stopped
becomes true
via SelectLoop.cease()
invocation.
Also, implementations are expected to SelectLoop.signalStart()
when
ready.
This implementation first allocates server socket channels via
createChannels()
before starting the loop, which simply accepts
any in-bound connections via accept(java.nio.channels.ServerSocketChannel)
method. After breaking
out of the loop, the channels are closed.
loop
in class SelectLoop
IOException
- if unable to properly select channels or an I/O
error is propagated by an event handler.Copyright © 2016. All Rights Reserved.