public abstract class Acceptor<SocketType extends Socket>
extends java.lang.Object
implements java.lang.AutoCloseable
| Modifier and Type | Field and Description |
|---|---|
protected io.netty.bootstrap.ServerBootstrap |
bootstrap |
protected io.netty.channel.Channel |
channel |
protected Callback<SocketType> |
onConnection |
protected IOService |
service |
| Modifier and Type | Method and Description |
|---|---|
SocketType |
accept()
Waits until someone is connected to the acceptor, and returns its
Socket. |
abstract Future<SocketType> |
acceptAsync()
Accepts a connection from any client and returns the
Socket. |
void |
bind(java.net.InetAddress address,
int port)
Binds the acceptor to the
InetAddress and port port. |
void |
bind(int port)
Binds the acceptor to the port
port. |
void |
bind(java.net.SocketAddress address)
Binds the acceptor to the
SocketAddress. |
protected void |
checkSocketCreated(java.lang.String method)
Call this method to check if the socket is created, if it's not,
then throws a
SocketNotCreated exception. |
void |
close() |
Future<java.lang.Void> |
closeAsync()
Stops the acceptor asynchronously.
|
protected <ReturnType> |
createFuture(io.netty.util.concurrent.Future<ReturnType> n) |
protected <ReturnType> |
createFuture(Procedure whenCancelled) |
Future<java.lang.Void> |
onClose()
Returns a
Future that it results when the server is closed |
<T> void |
setChildOption(io.netty.channel.ChannelOption<T> option,
T value)
Before calling any
bind() methods, this can set some default
options for the new sockets created when a client is connected. |
void |
setOnConnectionListener(Callback<SocketType> cbk)
Instead of using
accept() or acceptAsync(), it is
possible to use a listener to receive any new connection to the
acceptor. |
<T> boolean |
setOption(io.netty.channel.ChannelOption<T> option,
T value)
Sets an option for the acceptor
|
void |
waitForClose()
Waits until the acceptor is closed.
|
protected final IOService service
protected io.netty.channel.Channel channel
protected io.netty.bootstrap.ServerBootstrap bootstrap
protected Callback<SocketType extends Socket> onConnection
public void close()
throws java.lang.Exception
close in interface java.lang.AutoCloseablejava.lang.Exceptionpublic Future<java.lang.Void> closeAsync()
Future for the close taskpublic void waitForClose()
public Future<java.lang.Void> onClose()
Future that it results when the server is closedFuture with the close taskpublic void bind(java.net.SocketAddress address)
throws java.lang.InterruptedException
SocketAddress.address - address to bindjava.lang.InterruptedException - if it is interruptedpublic void bind(java.net.InetAddress address,
int port)
throws java.lang.InterruptedException
InetAddress and port port.address - addressport - portjava.lang.InterruptedException - if it is interruptedpublic void bind(int port)
throws java.lang.InterruptedException
port.port - portjava.lang.InterruptedException - if it is interruptedpublic abstract Future<SocketType> acceptAsync()
Socket.Future with the accept taskpublic SocketType accept() throws java.lang.Exception
Socket.Socket of the connectionjava.lang.Exception - if something bad happenedpublic void setOnConnectionListener(Callback<SocketType> cbk)
accept() or acceptAsync(), it is
possible to use a listener to receive any new connection to the
acceptor. It is complementary of the before methods, so if one of the
before methods are called, the new connection will be returned in this
calls, not in the listener.cbk - a listener that will be called when a new connection occurspublic <T> boolean setOption(io.netty.channel.ChannelOption<T> option,
T value)
T - type of the value for the optionoption - optionvalue - value to setpublic <T> void setChildOption(io.netty.channel.ChannelOption<T> option,
T value)
bind() methods, this can set some default
options for the new sockets created when a client is connected.T - type of the value for the optionoption - optionvalue - value to setjava.lang.IllegalStateException - If the server is already boundprotected void checkSocketCreated(java.lang.String method)
SocketNotCreated exception.method - method that was calledprotected <ReturnType> FutureImpl<ReturnType> createFuture(Procedure whenCancelled)
protected <ReturnType> Future<ReturnType> createFuture(io.netty.util.concurrent.Future<ReturnType> n)