public class TcpServer
extends java.lang.Object
Constructor and Description |
---|
TcpServer()
New instance with default configuration.
|
TcpServer(TcpServerConfig config)
New instance.
|
Modifier and Type | Method and Description |
---|---|
ServerContext |
bind(ExecutionContext executionContext,
int port,
ConnectionAcceptor connectionAcceptor,
java.util.function.Function<NettyConnection<Buffer,Buffer>,Completable> service,
ExecutionStrategy executionStrategy)
Starts the server at the passed
port and invoke the passed service for each accepted connection. |
static int |
getServerPort(ServerContext context)
Returns the listening port for the server represented by
ServerContext . |
public TcpServer()
public TcpServer(TcpServerConfig config)
config
- for the server.public ServerContext bind(ExecutionContext executionContext, int port, @Nullable ConnectionAcceptor connectionAcceptor, java.util.function.Function<NettyConnection<Buffer,Buffer>,Completable> service, ExecutionStrategy executionStrategy) throws java.util.concurrent.ExecutionException, java.lang.InterruptedException
port
and invoke the passed service
for each accepted connection.
Awaits for the server to start.executionContext
- ExecutionContext
to use for incoming connections.port
- Port for the server.connectionAcceptor
- to use for filtering accepted connections. The returned ServerContext
manages
the lifecycle of the connectionAcceptor
, ensuring it is closed when the ServerContext
is closed.service
- Function
that is invoked for each accepted connection.executionStrategy
- ExecutionStrategy
to use.ServerContext
for the started server.java.util.concurrent.ExecutionException
- If the server start failed.java.lang.InterruptedException
- If the calling thread was interrupted waiting for the server to start.public static int getServerPort(ServerContext context)
ServerContext
.context
- for the server.java.lang.ClassCastException
- If the SocketAddress
returned by ServerContext.listenAddress()
is
not an InetSocketAddress
.