Class TcpServer
- java.lang.Object
-
- io.servicetalk.tcp.netty.internal.TcpServer
-
public class TcpServer extends java.lang.ObjectA utility to create a TCP server for tests.
-
-
Constructor Summary
Constructors Constructor Description TcpServer()New instance with default configuration.TcpServer(TcpServerConfig config)New instance.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description ServerContextbind(ExecutionContext executionContext, int port, ConnectionAcceptor connectionAcceptor, java.util.function.Function<NettyConnection<Buffer,Buffer>,Completable> service, ExecutionStrategy executionStrategy)Starts the server at the passedportand invoke the passedservicefor each accepted connection.static intgetServerPort(ServerContext context)Returns the listening port for the server represented byServerContext.
-
-
-
Constructor Detail
-
TcpServer
public TcpServer()
New instance with default configuration.
-
TcpServer
public TcpServer(TcpServerConfig config)
New instance.- Parameters:
config- for the server.
-
-
Method Detail
-
bind
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
Starts the server at the passedportand invoke the passedservicefor each accepted connection. Awaits for the server to start.- Parameters:
executionContext-ExecutionContextto use for incoming connections.port- Port for the server.connectionAcceptor- to use for filtering accepted connections. The returnedServerContextmanages the lifecycle of theconnectionAcceptor, ensuring it is closed when theServerContextis closed.service-Functionthat is invoked for each accepted connection.executionStrategy-ExecutionStrategyto use.- Returns:
ServerContextfor the started server.- Throws:
java.util.concurrent.ExecutionException- If the server start failed.java.lang.InterruptedException- If the calling thread was interrupted waiting for the server to start.
-
getServerPort
public static int getServerPort(ServerContext context)
Returns the listening port for the server represented byServerContext.- Parameters:
context- for the server.- Returns:
- Listening port.
- Throws:
java.lang.ClassCastException- If theSocketAddressreturned byServerContext.listenAddress()is not anInetSocketAddress.
-
-