Top Description Methods
reactor.netty

public Interface Connection

extends DisposableChannel
Known Direct Implementers
reactor.netty.ReactorNetty.SimpleConnection, reactor.netty.channel.ChannelOperations, reactor.netty.resources.DefaultPooledConnectionProvider.PooledConnection, reactor.netty.transport.ServerTransport.DisposableBind
Annotations
@FunctionalInterface
Imports
io.netty.channel.Channel, .ChannelHandler, .ChannelOutboundHandler, reactor.core.Disposable, reactor.core.publisher.Mono, reactor.util.annotation.Nullable

Hold contextual information for the underlying Channel.
Author
Stephane Maldini
Since
0.8

Method Summary

Modifier and TypeMethod and Description
public default Connection

Returns:

this Connection
addHandler
(ChannelHandler
handler instance
handler
)

Deprecated as of 1.0.17.
Add a ChannelHandler with addHandlerFirst if of type of io.netty.channel.ChannelOutboundHandler otherwise with addHandlerLast.
public default Connection

Returns:

this Connection
addHandler
(String
handler name
name
,
ChannelHandler
handler instance
handler
)

Deprecated as of 1.0.17.
Add a ChannelHandler with addHandlerFirst if of type of io.netty.channel.ChannelOutboundHandler otherwise with addHandlerLast.
public default Connection

Returns:

this Connection
addHandlerFirst
(ChannelHandler
handler instance
handler
)

Add a ChannelHandler to the beginning of the "user" io.netty.channel.ChannelPipeline, that is just after the reactor-added codecs.

public default Connection

Returns:

this Connection
addHandlerFirst
(String
handler name
name
,
ChannelHandler
handler instance
handler
)

Add a ChannelHandler to the beginning of the "user" io.netty.channel.ChannelPipeline, that is just after the reactor-added codecs.

public default Connection

Returns:

this Connection
addHandlerLast
(ChannelHandler
handler instance
handler
)

Add a ChannelHandler to the end of the "user" io.netty.channel.ChannelPipeline, that is just before the reactor-added handlers like NettyPipeline#ReactiveBridge.

public default Connection

Returns:

this Connection
addHandlerLast
(String
handler name
name
,
ChannelHandler
handler instance
handler
)

Add a ChannelHandler to the end of the "user" io.netty.channel.ChannelPipeline, that is just before the reactor-added handlers like NettyPipeline#ReactiveBridge.

public default <T extends Connection> T

Returns:

a matching Connection reference or null
as
(Class<T>
connection type to match to
clazz
)

Return an existing Connection that must match the given type wrapper or null.

public default Connection

Returns:

this Connection.
bind
()

Bind the Connection to the channel scope via an attribute.

public static Connection

Returns:

an existing Connection wrapper or create a simple new one
from
(Channel
channel to retrieve the connection reference from
channel
)

Return an existing Connection wrapper or create a simple new one.

public default NettyInbound

Returns:

the NettyInbound read API from this connection.
inbound
()

Return the NettyInbound read API from this connection.

public default boolean

Returns:

whether the underlying Connection will be disposed on terminal handler event
isPersistent
()

Return false if it will force a close on terminal protocol events thus defeating any pooling strategy Return true (default) if it will release on terminal protocol events thus keeping alive the channel if possible.

public default Connection

Returns:

this Connection
markPersistent
(boolean
the boolean flag to mark the Channel as fully disposable or reusable when a user handler has terminated
persist
)

Mark the underlying channel as persistent or not.

public default Connection
onDispose(Disposable
the close event handler
onDispose
)

Overrides default reactor.netty.DisposableChannel.onDispose.

Assigns a Disposable to be invoked when the channel is closed.
public default Connection

Returns:

this
onReadIdle
(long
the idle timeout
idleTimeout
,
Runnable
the idle timeout handler
onReadIdle
)

Assign a Runnable to be invoked when reads have become idle for the given timeout.

public default Mono<Void>

Returns:

a Mono succeeding when a Connection has been terminated
onTerminate
()

Return a Mono succeeding when a Connection is not used anymore by any current operations.

public default Connection

Returns:

this
onWriteIdle
(long
the idle timeout
idleTimeout
,
Runnable
the idle timeout handler
onWriteIdle
)

Assign a Runnable to be invoked when writes have become idle for the given timeout.

public default NettyOutbound

Returns:

the NettyOutbound read API from this connection.
outbound
()

Return the NettyOutbound write API from this connection.

public default boolean

Returns:

true if bound
rebind
(Connection
a new connection reference
connection
)

Bind a new Connection reference or null to the channel attributes only if this instance is currently bound.

public default Connection

Returns:

this Connection
removeHandler
(String
handler name
name
)

Remove a named handler if present and return this context.

public default Connection

Returns:

this Connection
replaceHandler
(String
handler name
name
,
ChannelHandler handler)

Replace a named handler if present and return this context.

Inherited from reactor.netty.DisposableChannel:
addresschanneldisposedisposeNowdisposeNowdisposeSubscriberisDisposedonDispose

Method Detail

addHandlerback to summary
public default Connection addHandler(ChannelHandler handler)

Deprecated

as of 1.0.17. Use addHandlerFirst(ChannelHandler) or addHandlerLast(ChannelHandler). This method will be removed in version 1.2.0.

Add a ChannelHandler with addHandlerFirst if of type of io.netty.channel.ChannelOutboundHandler otherwise with addHandlerLast. Implementation may add more auto handling in particular HTTP based context will prepend an HttpContent body extractor.

[ [reactor codecs], [<- user FIRST HANDLERS added here, user LAST HANDLERS added here ->], [reactor handlers] ]

If effectively added, the handler will be safely removed when the channel is made inactive (pool release). As the Connection object is available once the channel is in active state, events prior this state will not be available (i.e. channelRegistered, initChannel, channelActive, etc.)

Parameters
handler:ChannelHandler

handler instance

Returns:Connection

this Connection

Annotations
@Deprecated
addHandlerback to summary
public default Connection addHandler(String name, ChannelHandler handler)

Deprecated

as of 1.0.17. Use addHandlerFirst(String, ChannelHandler) or addHandlerLast(String, ChannelHandler). This method will be removed in version 1.2.0.

Add a ChannelHandler with addHandlerFirst if of type of io.netty.channel.ChannelOutboundHandler otherwise with addHandlerLast. Implementation may add more auto handling in particular HTTP based context will prepend an HttpContent body extractor.

[ [reactor codecs], [<- user FIRST HANDLERS added here, user LAST HANDLERS added here ->], [reactor handlers] ]

If effectively added, the handler will be safely removed when the channel is made inactive (pool release). As the Connection object is available once the channel is in active state, events prior this state will not be available (i.e. channelRegistered, initChannel, channelActive, etc.)

Parameters
name:String

handler name

handler:ChannelHandler

handler instance

Returns:Connection

this Connection

Annotations
@Deprecated
addHandlerFirstback to summary
public default Connection addHandlerFirst(ChannelHandler handler)

Add a ChannelHandler to the beginning of the "user" io.netty.channel.ChannelPipeline, that is just after the reactor-added codecs. If a handler with a similar name already exists, this operation is skipped.

[ [reactor codecs], [<- user FIRST HANDLERS added here, user LAST HANDLERS added here ->], [reactor handlers] ].

If effectively added, the handler will be safely removed when the channel is made inactive (pool release). As the Connection object is available once the channel is in active state, events prior this state will not be available (i.e. channelRegistered, initChannel, channelActive, etc.)

Parameters
handler:ChannelHandler

handler instance

Returns:Connection

this Connection

addHandlerFirstback to summary
public default Connection addHandlerFirst(String name, ChannelHandler handler)

Add a ChannelHandler to the beginning of the "user" io.netty.channel.ChannelPipeline, that is just after the reactor-added codecs. If a handler with a similar name already exists, this operation is skipped.

[ [reactor codecs], [<- user FIRST HANDLERS added here, user LAST HANDLERS added here ->], [reactor handlers] ]

If effectively added, the handler will be safely removed when the channel is made inactive (pool release). As the Connection object is available once the channel is in active state, events prior this state will not be available (i.e. channelRegistered, initChannel, channelActive, etc.)

Parameters
name:String

handler name

handler:ChannelHandler

handler instance

Returns:Connection

this Connection

addHandlerLastback to summary
public default Connection addHandlerLast(ChannelHandler handler)

Add a ChannelHandler to the end of the "user" io.netty.channel.ChannelPipeline, that is just before the reactor-added handlers like NettyPipeline#ReactiveBridge. If a handler with a similar name already exists, this operation is skipped.

[ [reactor codecs], [<- user FIRST HANDLERS added here, user LAST HANDLERS added here ->], [reactor handlers] ]

If effectively added, the handler will be safely removed when the channel is made inactive (pool release). As the Connection object is available once the channel is in active state, events prior this state will not be available (i.e. channelRegistered, initChannel, channelActive, etc.)

Parameters
handler:ChannelHandler

handler instance

Returns:Connection

this Connection

addHandlerLastback to summary
public default Connection addHandlerLast(String name, ChannelHandler handler)

Add a ChannelHandler to the end of the "user" io.netty.channel.ChannelPipeline, that is just before the reactor-added handlers like NettyPipeline#ReactiveBridge. If a handler with a similar name already exists, this operation is skipped.

[ [reactor codecs], [<- user FIRST HANDLERS added here, user LAST HANDLERS added here ->], [reactor handlers] ]

If effectively added, the handler will be safely removed when the channel is made inactive (pool release). As the Connection object is available once the channel is in active state, events prior this state will not be available (i.e. channelRegistered, initChannel, channelActive, etc.)

Parameters
name:String

handler name

handler:ChannelHandler

handler instance

Returns:Connection

this Connection

asback to summary
public default <T extends Connection> T as(Class<T> clazz)

Return an existing Connection that must match the given type wrapper or null.

Parameters
clazz:Class<T>

connection type to match to

Returns:T

a matching Connection reference or null

Annotations
@Nullable
bindback to summary
public default Connection bind()

Bind the Connection to the channel scope via an attribute. Can be retrieved later by from. If a previous reference Connection was bound, this instance will take precedence.

Returns:Connection

this Connection.

fromback to summary
public static Connection from(Channel channel)

Return an existing Connection wrapper or create a simple new one.

Parameters
channel:Channel

channel to retrieve the connection reference from

Returns:Connection

an existing Connection wrapper or create a simple new one

inboundback to summary
public default NettyInbound inbound()

Return the NettyInbound read API from this connection. If Connection has not been configured with a supporting bridge, receive operations will be unavailable.

Returns:NettyInbound

the NettyInbound read API from this connection.

isPersistentback to summary
public default boolean isPersistent()

Return false if it will force a close on terminal protocol events thus defeating any pooling strategy Return true (default) if it will release on terminal protocol events thus keeping alive the channel if possible.

Returns:boolean

whether the underlying Connection will be disposed on terminal handler event

markPersistentback to summary
public default Connection markPersistent(boolean persist)

Mark the underlying channel as persistent or not. If false, it will force a close on terminal protocol events thus defeating any pooling strategy if true (default), it will release on terminal protocol events thus keeping alive the channel if possible.

Parameters
persist:boolean

the boolean flag to mark the Channel as fully disposable or reusable when a user handler has terminated

Returns:Connection

this Connection

onDisposeback to summary
public default Connection onDispose(Disposable onDispose)

Overrides default reactor.netty.DisposableChannel.onDispose.

Doc from reactor.netty.DisposableChannel.onDispose.

Assigns a Disposable to be invoked when the channel is closed.

Parameters
onDispose:Disposable

the close event handler

Returns:Connection

this

Annotations
@Override
onReadIdleback to summary
public default Connection onReadIdle(long idleTimeout, Runnable onReadIdle)

Assign a Runnable to be invoked when reads have become idle for the given timeout. This replaces any previously set idle callback.

Parameters
idleTimeout:long

the idle timeout

onReadIdle:Runnable

the idle timeout handler

Returns:Connection

this

onTerminateback to summary
public default Mono<Void> onTerminate()

Return a Mono succeeding when a Connection is not used anymore by any current operations. A typical example is when a pooled connection is released or an operations bridge has terminated.

Returns:Mono<Void>

a Mono succeeding when a Connection has been terminated

onWriteIdleback to summary
public default Connection onWriteIdle(long idleTimeout, Runnable onWriteIdle)

Assign a Runnable to be invoked when writes have become idle for the given timeout. This replaces any previously set idle callback.

Parameters
idleTimeout:long

the idle timeout

onWriteIdle:Runnable

the idle timeout handler

Returns:Connection

this

outboundback to summary
public default NettyOutbound outbound()

Return the NettyOutbound write API from this connection. If Connection has not been configured with a supporting bridge, send operations will be unavailable.

Returns:NettyOutbound

the NettyOutbound read API from this connection.

rebindback to summary
public default boolean rebind(Connection connection)

Bind a new Connection reference or null to the channel attributes only if this instance is currently bound.

Parameters
connection:Connection

a new connection reference

Returns:boolean

true if bound

See Also
bind
removeHandlerback to summary
public default Connection removeHandler(String name)

Remove a named handler if present and return this context.

Parameters
name:String

handler name

Returns:Connection

this Connection

replaceHandlerback to summary
public default Connection replaceHandler(String name, ChannelHandler handler)

Replace a named handler if present and return this context. If handler wasn't present, an RuntimeException will be thrown.

Note

if the new handler is of different type, dependent handling like the "extractor" introduced via HTTP-based addHandler might not expect/support the new messages type.

Parameters
name:String

handler name

Returns:Connection

this Connection