Top Description Inners Fields Constructors Methods
reactor.netty5.tcp

public abstract Class TcpServer

extends ServerTransport<TcpServer, TcpServerConfig>
Class Inheritance
Known Direct Subclasses
reactor.netty5.tcp.TcpServerBind
Imports
java.net.SocketAddress, java.util.Objects, java.util.function.BiFunction, .Consumer, .Supplier, io.netty5.channel.EventLoopGroup, io.netty5.channel.group.ChannelGroup, io.netty5.handler.logging.LogLevel, io.netty5.handler.ssl.JdkSslContext, .OpenSsl, .SslContext, io.netty5.handler.ssl.util.SelfSignedCertificate, org.reactivestreams.Publisher, reactor.core.publisher.Mono, reactor.netty5.Connection, .DisposableServer, .NettyInbound, .NettyOutbound, reactor.netty5.channel.ChannelMetricsRecorder, reactor.netty5.resources.LoopResources, reactor.netty5.transport.ServerTransport, reactor.util.Logger, .Loggers

A TcpServer allows building in a safe immutable way a TCP server that is materialized and connecting when bind() is ultimately called.

Example:

TcpServer.create()
         .doOnBind(startMetrics)
         .doOnBound(startedMetrics)
         .doOnUnbound(stopMetrics)
         .host("127.0.0.1")
         .port(1234)
         .bind()
         .block()

Authors
Stephane Maldini, Violeta Georgieva

Nested and Inner Type Summary

Modifier and TypeClass and Description
pack-priv static class

Field Summary

Modifier and TypeField and Description
pack-priv static final Logger

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public TcpServer
bindAddress(Supplier<? extends SocketAddress>
A supplier of the address to bind to.
bindAddressSupplier
)

Overrides reactor.netty5.transport.Transport.bindAddress.

Set a new local address to which this transport should bind on subscribe.
public TcpServer
channelGroup(ChannelGroup channelGroup)

Overrides reactor.netty5.transport.Transport.channelGroup.

Provide a ChannelGroup to hold all active connected channels.
public static TcpServer

Returns:

a new TcpServer
create
()

Prepare a TcpServer

public TcpServer
doOnBind(Consumer<? super TcpServerConfig>
a consumer observing connected events
doOnBind
)

Overrides reactor.netty5.transport.ServerTransport.doOnBind.

Set or add a callback called when ServerTransport is about to start listening for incoming traffic.
public TcpServer
doOnBound(Consumer<? super DisposableServer>
a consumer observing connected events
doOnBound
)

Overrides reactor.netty5.transport.ServerTransport.doOnBound.

Set or add a callback called after DisposableServer has been started.
public TcpServer
doOnConnection(Consumer<? super Connection>
a consumer observing remote connections
doOnConnection
)

Overrides reactor.netty5.transport.ServerTransport.doOnConnection.

Set or add a callback called on new remote Connection.
public TcpServer
doOnUnbound(Consumer<? super DisposableServer>
a consumer observing unbound events
doOnUnbound
)

Overrides reactor.netty5.transport.ServerTransport.doOnUnbound.

Set or add a callback called after DisposableServer has been shutdown.
public TcpServer

Returns:

a new TcpServer
handle
(BiFunction<? super NettyInbound, ? super NettyOutbound, ? extends Publisher<Void>>
an I/O handler that can dispose underlying connection when Publisher terminates.
handler
)

Attaches an I/O handler to react on a connected client

public TcpServer
host(String
the host to bind to.
host
)

Overrides reactor.netty5.transport.ServerTransport.host.

The host to which this server should bind.
public TcpServer
metrics(boolean
true enables metrics collection; false disables it
enable
)

Overrides reactor.netty5.transport.Transport.metrics.

Whether to enable metrics to be collected and registered in Micrometer's globalRegistry.
public TcpServer
metrics(boolean
if true enables the metrics on the Transport.
enable
,
Supplier<? extends ChannelMetricsRecorder>
a supplier for the ChannelMetricsRecorder
recorder
)

Overrides reactor.netty5.transport.Transport.metrics.

Specifies whether the metrics are enabled on the Transport.
public TcpServer

Returns:

a new TcpServer
noSSL
()

Removes any previously applied SSL configuration customization

public TcpServer
port(int
The port to bind to.
port
)

Overrides reactor.netty5.transport.ServerTransport.port.

The port to which this server should bind.
public TcpServer
runOn(EventLoopGroup
an eventLoopGroup to share
eventLoopGroup
)

Overrides reactor.netty5.transport.Transport.runOn.

Run IO loops on the given EventLoopGroup.
public TcpServer
runOn(LoopResources
a LoopResources accepting native runtime expectation and returning an eventLoopGroup
channelResources
)

Overrides reactor.netty5.transport.Transport.runOn.

Run IO loops on a supplied EventLoopGroup from the LoopResources container.
public TcpServer
runOn(LoopResources
a new loop resources
loopResources
,
boolean
should prefer running on epoll, kqueue or similar instead of java NIO
preferNative
)

Overrides reactor.netty5.transport.Transport.runOn.

Run IO loops on a supplied EventLoopGroup from the LoopResources container.
public TcpServer

Returns:

a new TcpServer
secure
(Consumer<? super SslProvider.SslContextSpec>
builder callback for further customization of SslContext.
sslProviderBuilder
)

Apply an SSL configuration customization via the passed builder.

public TcpServer

Returns:

a new TcpServer
secure
(SslProvider
The provider to set when configuring SSL
sslProvider
)

Applies an SSL configuration via the passed SslProvider.

public Mono<Void>

Returns:

a Mono representing the completion of the warmup
warmup
()

Overrides reactor.netty5.transport.ServerTransport.warmup.

Based on the actual configuration, returns a Mono that triggers:
  • an initialization of the event loop groups
  • loads the necessary native libraries for the transport
  • loads the necessary native libraries for the security if there is such
public TcpServer
wiretap(boolean
specifies whether the wire logger configuration will be added to the pipeline
enable
)

Overrides reactor.netty5.transport.Transport.wiretap.

Apply or remove a wire logger configuration using Transport category (logger), DEBUG logger level and AdvancedBufferFormat#HEX_DUMP for Buffer format, which means both events and content will be logged and the content will be in hex format.
public TcpServer
wiretap(String
the logger category
category
)

Overrides reactor.netty5.transport.Transport.wiretap.

Apply a wire logger configuration using the specified category (logger), DEBUG logger level and AdvancedBufferFormat#HEX_DUMP for Buffer format, which means both events and content will be logged and the content will be in hex format.
public TcpServer
wiretap(String
the logger category
category
,
LogLevel
the logger level
level
)

Overrides reactor.netty5.transport.Transport.wiretap.

Apply a wire logger configuration using the specified category (logger), logger level and AdvancedBufferFormat#HEX_DUMP for Buffer format, which means both events and content will be logged and the content will be in hex format.
Inherited from reactor.netty5.transport.ServerTransport:
bindbindNowbindNowbindUntilJavaShutdownchildAttrchildObservechildOption

Field Detail

logback to summary
pack-priv static final Logger log

Hides reactor.netty5.transport.ServerTransport.log.

Constructor Detail

TcpServerback to summary
public TcpServer()

Method Detail

bindAddressback to summary
public TcpServer bindAddress(Supplier<? extends SocketAddress> bindAddressSupplier)

Overrides reactor.netty5.transport.Transport.bindAddress.

Doc from reactor.netty5.transport.Transport.bindAddress.

Set a new local address to which this transport should bind on subscribe.

Parameters
bindAddressSupplier:Supplier<? extends SocketAddress>

A supplier of the address to bind to.

Returns:TcpServer

a new Transport

Annotations
@Override
channelGroupback to summary
public TcpServer channelGroup(ChannelGroup channelGroup)

Overrides reactor.netty5.transport.Transport.channelGroup.

Doc from reactor.netty5.transport.Transport.channelGroup.

Provide a ChannelGroup to hold all active connected channels.

Graceful Shutdown:

When a ChannelGroup is set, calls to DisposableChannel#disposeNow() and DisposableChannel#disposeNow(Duration) not only stop accepting new requests but also additionally wait for all active requests, in the ChannelGroup, to complete, within the given timeout.

Parameters
channelGroup:ChannelGroup

a ChannelGroup

Returns:TcpServer

a new Transport reference

Annotations
@Override
createback to summary
public static TcpServer create()

Prepare a TcpServer

Returns:TcpServer

a new TcpServer

doOnBindback to summary
public TcpServer doOnBind(Consumer<? super TcpServerConfig> doOnBind)

Overrides reactor.netty5.transport.ServerTransport.doOnBind.

Doc from reactor.netty5.transport.ServerTransport.doOnBind.

Set or add a callback called when ServerTransport is about to start listening for incoming traffic.

Parameters
doOnBind:Consumer<? super TcpServerConfig>

a consumer observing connected events

Returns:TcpServer

a new ServerTransport reference

Annotations
@Override
doOnBoundback to summary
public TcpServer doOnBound(Consumer<? super DisposableServer> doOnBound)

Overrides reactor.netty5.transport.ServerTransport.doOnBound.

Doc from reactor.netty5.transport.ServerTransport.doOnBound.

Set or add a callback called after DisposableServer has been started.

Parameters
doOnBound:Consumer<? super DisposableServer>

a consumer observing connected events

Returns:TcpServer

a new ServerTransport reference

Annotations
@Override
doOnConnectionback to summary
public TcpServer doOnConnection(Consumer<? super Connection> doOnConnection)

Overrides reactor.netty5.transport.ServerTransport.doOnConnection.

Doc from reactor.netty5.transport.ServerTransport.doOnConnection.

Set or add a callback called on new remote Connection.

Parameters
doOnConnection:Consumer<? super Connection>

a consumer observing remote connections

Returns:TcpServer

a new ServerTransport reference

Annotations
@Override
doOnUnboundback to summary
public TcpServer doOnUnbound(Consumer<? super DisposableServer> doOnUnbound)

Overrides reactor.netty5.transport.ServerTransport.doOnUnbound.

Doc from reactor.netty5.transport.ServerTransport.doOnUnbound.

Set or add a callback called after DisposableServer has been shutdown.

Parameters
doOnUnbound:Consumer<? super DisposableServer>

a consumer observing unbound events

Returns:TcpServer

a new ServerTransport reference

Annotations
@Override
handleback to summary
public TcpServer handle(BiFunction<? super NettyInbound, ? super NettyOutbound, ? extends Publisher<Void>> handler)

Attaches an I/O handler to react on a connected client

Parameters
handler:BiFunction<? super NettyInbound, ? super NettyOutbound, ? extends Publisher<Void>>

an I/O handler that can dispose underlying connection when Publisher terminates.

Returns:TcpServer

a new TcpServer

hostback to summary
public TcpServer host(String host)

Overrides reactor.netty5.transport.ServerTransport.host.

Doc from reactor.netty5.transport.ServerTransport.host.

The host to which this server should bind.

Parameters
host:String

the host to bind to.

Returns:TcpServer

a new ServerTransport reference

Annotations
@Override
metricsback to summary
public TcpServer metrics(boolean enable)

Overrides reactor.netty5.transport.Transport.metrics.

Doc from reactor.netty5.transport.Transport.metrics.

Whether to enable metrics to be collected and registered in Micrometer's globalRegistry. Applications can separately register their own filters. For example, to put an upper bound on the number of tags produced:

MeterFilter filter = ... ;
Metrics.globalRegistry.config().meterFilter(MeterFilter.maximumAllowableTags(prefix, 100, filter));

By default this is not enabled.

Parameters
enable:boolean

true enables metrics collection; false disables it

Returns:TcpServer

a new Transport reference

Annotations
@Override
metricsback to summary
public TcpServer metrics(boolean enable, Supplier<? extends ChannelMetricsRecorder> recorder)

Overrides reactor.netty5.transport.Transport.metrics.

Doc from reactor.netty5.transport.Transport.metrics.

Specifies whether the metrics are enabled on the Transport. All generated metrics are provided to the specified recorder which is only instantiated if metrics are being enabled (the instantiation is not lazy, but happens immediately, while configuring the Transport).

Parameters
enable:boolean

if true enables the metrics on the Transport.

recorder:Supplier<? extends ChannelMetricsRecorder>

a supplier for the ChannelMetricsRecorder

Returns:TcpServer

a new Transport reference

Annotations
@Override
noSSLback to summary
public TcpServer noSSL()

Removes any previously applied SSL configuration customization

Returns:TcpServer

a new TcpServer

portback to summary
public TcpServer port(int port)

Overrides reactor.netty5.transport.ServerTransport.port.

Doc from reactor.netty5.transport.ServerTransport.port.

The port to which this server should bind.

Parameters
port:int

The port to bind to.

Returns:TcpServer

a new ServerTransport reference

Annotations
@Override
runOnback to summary
public TcpServer runOn(EventLoopGroup eventLoopGroup)

Overrides reactor.netty5.transport.Transport.runOn.

Doc from reactor.netty5.transport.Transport.runOn.

Run IO loops on the given EventLoopGroup.

Parameters
eventLoopGroup:EventLoopGroup

an eventLoopGroup to share

Returns:TcpServer

a new Transport reference

Annotations
@Override
runOnback to summary
public TcpServer runOn(LoopResources channelResources)

Overrides reactor.netty5.transport.Transport.runOn.

Doc from reactor.netty5.transport.Transport.runOn.

Run IO loops on a supplied EventLoopGroup from the LoopResources container. Will prefer native (epoll/kqueue) implementation if available unless the environment property reactor.netty5.native is set to false.

Parameters
channelResources:LoopResources

a LoopResources accepting native runtime expectation and returning an eventLoopGroup

Returns:TcpServer

a new Transport reference

Annotations
@Override
runOnback to summary
public TcpServer runOn(LoopResources loopResources, boolean preferNative)

Overrides reactor.netty5.transport.Transport.runOn.

Doc from reactor.netty5.transport.Transport.runOn.

Run IO loops on a supplied EventLoopGroup from the LoopResources container.

Parameters
loopResources:LoopResources

a new loop resources

preferNative:boolean

should prefer running on epoll, kqueue or similar instead of java NIO

Returns:TcpServer

a new Transport reference

Annotations
@Override
secureback to summary
public TcpServer secure(Consumer<? super SslProvider.SslContextSpec> sslProviderBuilder)

Apply an SSL configuration customization via the passed builder. The builder will produce the SslContext to be passed to with a default value of 10 seconds handshake timeout unless the environment property reactor.netty5.tcp.sslHandshakeTimeout is set. If SelfSignedCertificate needs to be used, the sample below can be used. Note that SelfSignedCertificate should not be used in production.

SelfSignedCertificate cert = new SelfSignedCertificate();
    TcpSslContextSpec tcpSslContextSpec =
            TcpSslContextSpec.forServer(cert.certificate(), cert.privateKey());
    secure(sslContextSpec -> sslContextSpec.sslContext(tcpSslContextSpec));

Parameters
sslProviderBuilder:Consumer<? super SslProvider.SslContextSpec>

builder callback for further customization of SslContext.

Returns:TcpServer

a new TcpServer

secureback to summary
public TcpServer secure(SslProvider sslProvider)

Applies an SSL configuration via the passed SslProvider. If SelfSignedCertificate needs to be used, the sample below can be used. Note that SelfSignedCertificate should not be used in production.

SelfSignedCertificate cert = new SelfSignedCertificate();
    TcpSslContextSpec tcpSslContextSpec =
            TcpSslContextSpec.forServer(cert.certificate(), cert.privateKey());
    secure(sslContextSpec -> sslContextSpec.sslContext(tcpSslContextSpec));

Parameters
sslProvider:SslProvider

The provider to set when configuring SSL

Returns:TcpServer

a new TcpServer

warmupback to summary
public Mono<Void> warmup()

Overrides reactor.netty5.transport.ServerTransport.warmup.

Based on the actual configuration, returns a Mono that triggers:

  • an initialization of the event loop groups
  • loads the necessary native libraries for the transport
  • loads the necessary native libraries for the security if there is such
By default, when method is not used, the bind operation absorbs the extra time needed to load resources.
Returns:Mono<Void>

a Mono representing the completion of the warmup

Annotations
@Override
Since
1.0.3
wiretapback to summary
public TcpServer wiretap(boolean enable)

Overrides reactor.netty5.transport.Transport.wiretap.

Doc from reactor.netty5.transport.Transport.wiretap.

Apply or remove a wire logger configuration using Transport category (logger), DEBUG logger level and AdvancedBufferFormat#HEX_DUMP for Buffer format, which means both events and content will be logged and the content will be in hex format.

Parameters
enable:boolean

specifies whether the wire logger configuration will be added to the pipeline

Returns:TcpServer

a new Transport reference

Annotations
@Override
wiretapback to summary
public TcpServer wiretap(String category)

Overrides reactor.netty5.transport.Transport.wiretap.

Doc from reactor.netty5.transport.Transport.wiretap.

Apply a wire logger configuration using the specified category (logger), DEBUG logger level and AdvancedBufferFormat#HEX_DUMP for Buffer format, which means both events and content will be logged and the content will be in hex format.

Parameters
category:String

the logger category

Returns:TcpServer

a new Transport reference

Annotations
@Override
wiretapback to summary
public TcpServer wiretap(String category, LogLevel level)

Overrides reactor.netty5.transport.Transport.wiretap.

Doc from reactor.netty5.transport.Transport.wiretap.

Apply a wire logger configuration using the specified category (logger), logger level and AdvancedBufferFormat#HEX_DUMP for Buffer format, which means both events and content will be logged and the content will be in hex format.

Parameters
category:String

the logger category

level:LogLevel

the logger level

Returns:TcpServer

a new Transport reference

Annotations
@Override
reactor.netty5.tcp back to summary

pack-priv final Class TcpServer.OnConnectionHandle

extends Object
implements Consumer<Connection>
Class Inheritance
All Implemented Interfaces
java.util.function.Consumer

Field Summary

Modifier and TypeField and Description
pack-priv final BiFunction<? super NettyInbound, ? super NettyOutbound, ? extends Publisher<Void>>

Constructor Summary

AccessConstructor and Description
pack-priv
OnConnectionHandle(BiFunction<? super NettyInbound, ? super NettyOutbound, ? extends Publisher<Void>> handler)

Method Summary

Modifier and TypeMethod and Description
public void
accept(Connection
the input argument
c
)

Implements java.util.function.Consumer.accept.

Performs this operation on the given argument.
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

handlerback to summary
pack-priv final BiFunction<? super NettyInbound, ? super NettyOutbound, ? extends Publisher<Void>> handler

Constructor Detail

OnConnectionHandleback to summary
pack-priv OnConnectionHandle(BiFunction<? super NettyInbound, ? super NettyOutbound, ? extends Publisher<Void>> handler)

Method Detail

acceptback to summary
public void accept(Connection c)

Implements java.util.function.Consumer.accept.

Doc from java.util.function.Consumer.accept.

Performs this operation on the given argument.

Parameters
c:Connection

the input argument

Annotations
@Override