public class TcpServer extends java.lang.Object implements NettyConnector<NettyInbound,NettyOutbound>
| Modifier and Type | Class and Description |
|---|---|
static class |
TcpServer.Builder |
| Modifier | Constructor and Description |
|---|---|
protected |
TcpServer(ServerOptions options) |
protected |
TcpServer(TcpServer.Builder builder) |
| Modifier and Type | Method and Description |
|---|---|
static TcpServer.Builder |
builder()
Creates a builder for
TcpServer |
static TcpServer |
create()
Bind a new TCP server to "localhost" on a randomly assigned port.
|
static TcpServer |
create(java.util.function.Consumer<? super ServerOptions.Builder<?>> options)
Bind a new TCP server to the bind address and port provided through the options.
|
static TcpServer |
create(int port)
Bind a new TCP server to "localhost" on the given port.
|
static TcpServer |
create(java.lang.String bindAddress)
Bind a new TCP server to the given bind address on a randomly assigned port.
|
static TcpServer |
create(java.lang.String bindAddress,
int port)
Bind a new TCP server to the given bind address and port.
|
protected ContextHandler<io.netty.channel.Channel> |
doHandler(java.util.function.BiFunction<? super NettyInbound,? super NettyOutbound,? extends Publisher<java.lang.Void>> handler,
reactor.core.publisher.MonoSink<NettyContext> sink)
Create a
ContextHandler for ServerBootstrap.childHandler() |
protected io.netty.handler.logging.LoggingHandler |
loggingHandler()
Return the current logging handler for the server
|
reactor.core.publisher.Mono<? extends NettyContext> |
newHandler(java.util.function.BiFunction<? super NettyInbound,? super NettyOutbound,? extends Publisher<java.lang.Void>> handler)
Prepare a
BiFunction IO handler that will react on a new connected state
each
time
the returned Mono is subscribed. |
ServerOptions |
options()
Get a copy of the
ServerOptions currently in effect. |
java.lang.String |
toString() |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitstart, start, startAndAwait, startAndAwaitprotected TcpServer(TcpServer.Builder builder)
protected TcpServer(ServerOptions options)
options - server optionspublic static TcpServer create()
The assigned port can be found once a handler has been bound, using
NettyContext.address() and its getPort() method.
Handlers will run on the same thread they have been receiving IO events.
The type of emitted data or received data is ByteBuf
TcpServerpublic static TcpServer create(java.util.function.Consumer<? super ServerOptions.Builder<?>> options)
NettyOptions.DEFAULT_PORT once to use a global default port.
Handlers will run on the same thread they have been receiving IO events.
The type of emitted data or received data is ByteBuf
options - ServerOptions configuration inputTcpServerpublic static TcpServer create(int port)
NettyOptions.DEFAULT_PORT once to use
a global default port.
Handlers will run on the same thread they have been receiving IO events.
The type of emitted data or received data is ByteBuf
port - the port to listen on loopbackTcpServerpublic static TcpServer create(java.lang.String bindAddress)
The assigned port can be found once a handler has been bound, using
NettyContext.address() and its getPort() method.
Handlers will run on the same thread they have been receiving IO events.
The type of emitted data or received data is ByteBuf
bindAddress - bind address (e.g. "127.0.0.1") to create the server on the
default portTcpServerpublic static TcpServer create(java.lang.String bindAddress, int port)
NettyOptions.DEFAULT_PORT once to use
a global default port.
Handlers will run on the same thread they have been receiving IO events.
The type of emitted data or received data is ByteBuf
bindAddress - bind address (e.g. "127.0.0.1") to create the server on the
passed portport - the port to listen on the passed bind addressTcpServerpublic static TcpServer.Builder builder()
TcpServerpublic final reactor.core.publisher.Mono<? extends NettyContext> newHandler(java.util.function.BiFunction<? super NettyInbound,? super NettyOutbound,? extends Publisher<java.lang.Void>> handler)
NettyConnectorBiFunction IO handler that will react on a new connected state
each
time
the returned Mono is subscribed. This NettyConnector shouldn't assume
any state related to the individual created/cleaned resources.
The IO handler will return Publisher to signal when to terminate the
underlying resource channel.
newHandler in interface NettyConnector<NettyInbound,NettyOutbound>handler - the in/out callback returning a closing publisherMono completing with a Disposable token to dispose
the active handler (server, client connection...) or failing with the connection
error.public ServerOptions options()
ServerOptions currently in effect.public java.lang.String toString()
toString in class java.lang.Objectprotected io.netty.handler.logging.LoggingHandler loggingHandler()
protected ContextHandler<io.netty.channel.Channel> doHandler(java.util.function.BiFunction<? super NettyInbound,? super NettyOutbound,? extends Publisher<java.lang.Void>> handler, reactor.core.publisher.MonoSink<NettyContext> sink)
ContextHandler for ServerBootstrap.childHandler()handler - user provided in/out handlersink - user provided bind handlerContextHandler