Top Description Inners Fields Constructors Methods
io.netty5.channel

public abstract Class AbstractChannel<P extends Channel, L extends SocketAddress, R extends SocketAddress>

extends DefaultAttributeMap
implements Channel
Class Inheritance
All Implemented Interfaces
io.netty5.channel.Channel, io.netty5.channel.IoHandle, java.lang.Comparable, io.netty5.channel.ChannelOutboundInvoker, io.netty5.util.concurrent.FuturePromiseFactory, io.netty5.util.AttributeMap
Known Direct Subclasses
io.netty5.channel.AbstractServerChannel, io.netty5.channel.local.LocalChannel, io.netty5.channel.nio.AbstractNioChannel, io.netty5.channel.embedded.EmbeddedChannel
Imports
io.netty5.buffer.Buffer, .BufferAllocator, .DefaultBufferAllocators, io.netty5.util.Resource, .DefaultAttributeMap, io.netty5.util.concurrent.DefaultPromise, .EventExecutor, .Future, .Promise, io.netty5.util.internal.PlatformDependent, .StringUtil, io.netty5.util.internal.logging.InternalLogger, .InternalLoggerFactory, java.io.IOException, java.net.ConnectException, .InetSocketAddress, .NoRouteToHostException, .PortUnreachableException, .SocketAddress, .SocketException, java.nio.channels.AlreadyConnectedException, .ClosedChannelException, .ConnectionPendingException, .NotYetConnectedException, java.util.Collections, .IdentityHashMap, .NoSuchElementException, .Set, java.util.concurrent.Executor, .RejectedExecutionException, .TimeUnit, java.util.concurrent.atomic.AtomicIntegerFieldUpdater, java.util.function.Function, .Predicate

A skeletal Channel implementation.

Nested and Inner Type Summary

Modifier and TypeClass and Description
private static class
private static class
private static class
private static class
protected static class
protected class
AbstractChannel.ReadSink

Sink that will be used by doReadNow(ReadSink) implementations to perform the actual read from the underlying transport (for example a socket).

protected class
AbstractChannel.WriteSink

Sink that will be used by doWriteNow(WriteSink) implementations.

Field Summary

Modifier and TypeField and Description
private volatile boolean
private volatile boolean
private volatile int
private static final AtomicIntegerFieldUpdater<AbstractChannel<P extends Channel, L extends SocketAddress, R extends SocketAddress>>
private volatile BufferAllocator
private boolean
private final AbstractChannel.ClosePromise
private Promise<Void>
connectPromise

The future of the current connection attempt.

private Future<?>
private volatile int
private volatile ReadBufferAllocator
private static final int
private static final MessageSizeEstimator
private MessageSizeEstimator.Handle
private final EventLoop
private final Runnable
private final ChannelId
private Throwable
private boolean
private boolean
private volatile L
private static final InternalLogger
private volatile MessageSizeEstimator
private boolean
private boolean
neverRegistered

true if the channel has never been registered, false otherwise

private volatile ChannelOutboundBuffer
private final P
private final ChannelPipeline
private ReadBufferAllocator
private volatile ReadHandleFactory
private AbstractChannel<P, L, R>.ReadSink
private volatile boolean
private volatile R
private R
private String
private boolean
strValActive

Cache for the string representation of this channel

private static final Set<ChannelOption<?>>
private final boolean
private volatile int
private static final AtomicIntegerFieldUpdater<AbstractChannel<P extends Channel, L extends SocketAddress, R extends SocketAddress>>
private volatile WriteBufferWaterMark
private volatile WriteHandleFactory
private AbstractChannel<P, L, R>.WriteSink

Constructor Summary

AccessConstructor and Description
protected
AbstractChannel(P
the parent of this channel. null if there's no parent.
parent
,
EventLoop
the EventLoop which will be used.
eventLoop
,
boolean
true if and only if the channel has the disconnect() operation that allows a user to disconnect and then call {
supportingDisconnect
)

Creates a new instance.

protected
AbstractChannel(P
the parent of this channel. null if there's no parent.
parent
,
EventLoop
the EventLoop which will be used.
eventLoop
,
boolean
true if and only if the channel has the disconnect() operation that allows a user to disconnect and then call {
supportingDisconnect
,
ReadHandleFactory
the ReadHandleFactory that is used by default.
defaultReadHandleFactory
,
WriteHandleFactory
the WriteHandleFactory that is used by default.
defaultWriteHandleFactory
)

Creates a new instance.

protected
AbstractChannel(P
the parent of this channel. null if there's no parent.
parent
,
EventLoop
the EventLoop which will be used.
eventLoop
,
boolean
true if and only if the channel has the disconnect() operation that allows a user to disconnect and then call {
supportingDisconnect
,
ReadHandleFactory
the ReadHandleFactory that is used by default.
defaultReadHandleFactory
,
WriteHandleFactory
the WriteHandleFactory that is used by default.
defaultWriteHandleFactory
,
ChannelId
the ChannelId which will be used.
id
)

Creates a new instance.

Method Summary

Modifier and TypeMethod and Description
private static Throwable
annotateConnectException(Throwable cause, SocketAddress remoteAddress)

Appends the remote address to the message of the exceptions caused by connection attempt failure.

private void
private void
bindTransport(final SocketAddress localAddress, final Promise<Void> promise)

public final BufferAllocator
bufferAllocator()

Implements io.netty5.channel.Channel.bufferAllocator.

Return the assigned BufferAllocator which will be used to allocate Buffers.
protected final void
cacheAddresses(L localAddress, R remoteAddress)

private void
private void
private void
close(final Promise<Void> promise, final Throwable cause, final ClosedChannelException closeCause)

private void
public final Future<Void>
closeFuture()

Implements io.netty5.channel.Channel.closeFuture.

Returns the Future which will be notified when this channel is closed.
private void
private void
closeNow(ChannelOutboundBuffer outboundBuffer, boolean wasActive, Promise<Void> promise, Throwable cause, ClosedChannelException closeCause)

private void
protected void
closeTransport(final Promise<Void> promise)

private void
public final int
compareTo(Channel
the object to be compared.
o
)

Implements java.lang.Comparable.compareTo.

Compares this object with the specified object for order.
private void
connectTransport(SocketAddress remoteAddress, SocketAddress localAddress, Promise<Void> promise)

private void
deregister(final Promise<Void> promise, final boolean fireChannelInactive)

private void
deregisterDone(boolean fireChannelInactive, Promise<Void> promise)

private void
private void
protected abstract void
doBind(SocketAddress
the SocketAddress to bound to.
localAddress
)

Bind the Channel to the SocketAddress

protected void
doClearScheduledRead()

Clear any previous scheduled read.

protected abstract void
doClose()

Close the Channel

private void
doClose0(Promise<Void> promise)

protected abstract boolean

Returns:

true if the connect operation was completed, false if finishConnect() will be called later again to try finish connecting.
doConnect
(SocketAddress
the address of the remote peer.
remoteAddress
,
SocketAddress
the local address of this channel.
localAddress
,
Buffer
the initial data that is written during connect (if ChannelOption#TCP_FASTOPEN_CONNECT is supported and configured). If data is written care must be taken to update the reader offset.
initialData
)

Connect to remote peer.

protected abstract void
doDisconnect()

Disconnect this Channel from its remote peer

protected abstract boolean

Returns:

true if the connect operations was completed, false if finishConnect() will be called later again to try finishing the connect operation.
doFinishConnect
(R
the remote address of the peer.
requestedRemoteAddress
)

Finish a connect request.

protected abstract void
doRead(boolean
true if a read was already pending when read() was called.
wasReadPendingAlready
)

Schedule a read operation.

protected abstract boolean

Returns:

true if the channel should be shutdown / closed.
doReadNow
(AbstractChannel<P, L, R>.ReadSink
the ReadSink that should be called with messages that are read from the transport to propagate these.
readSink
)

Try to read a message from the transport and dispatch it via ReadSink#processRead(int, int, Object).

protected abstract void
doShutdown(ChannelShutdownDirection
the direction to shut down.
direction
)

Shutdown one direction of the Channel.

protected abstract void
doWriteNow(AbstractChannel<P, L, R>.WriteSink
the WriteSink that must be completed with the write progress. WriteSink#complete(long, long, int, boolean) or WriteSink#complete(long, Throwable, boolean) must be called exactly once before this method returns non-exceptional.
writeSink
)

Called in a loop when writes should be performed until this method returns false or there are no more messages to write.

private boolean
public final boolean
equals(Object
the reference object with which to compare.
o
)

Overrides java.lang.Object.equals.

Returns true if and only if the specified object is identical with this channel (i.e: this == o).
public final EventLoop
executor()

Implements io.netty5.channel.Channel.executor.

Return the EventLoop this Channel was registered to.
protected Object
filterOutboundMessage(Object
the message to filter / convert.
msg
)

Invoked when a new message is added to to the outbound queue of this AbstractChannel, so that the Channel implementation converts the message to another.

protected final boolean

Returns:

true if the connect operation completed, false otherwise.
finishConnect
()

Should be called once the connect request is ready to be completed and isConnectPending() is true.

private boolean

Returns:

true if ChannelPipeline#fireChannelActive() was called, false otherwise.
fireChannelActiveIfNotActiveBefore
()

Calls ChannelPipeline#fireChannelActive() if it was not done yet.

private void
fireChannelInactiveAndDeregister(final boolean wasActive)

private void
fireChannelWritabilityChangedIfNeeded(boolean notify, boolean notifyLater)

private void
private void
fulfillConnectPromise(Promise<Void> promise, boolean wasActive)

private void
private BufferAllocator
private int
protected <
the value type.
T
>
T

Returns:

the value for the option.
getExtendedOption
(ChannelOption<T> option)

Override to add support for more ChannelOptions.

private MessageSizeEstimator
public final <T> T
getOption(ChannelOption<T> option)

Implements io.netty5.channel.Channel.getOption.

Return the value of the given ChannelOption
private <T extends ReadHandleFactory> T
private WriteBufferWaterMark
private <T extends WriteHandleFactory> T
private void
public final int
hashCode()

Overrides java.lang.Object.hashCode.

Returns the ID of this channel.
public final ChannelId
id()

Implements io.netty5.channel.Channel.id.

Returns the globally unique identifier of this Channel.
private void
private boolean
private boolean
private boolean
protected final boolean

Returns:

true if there is an outstanding connect request.
isConnectPending
()

Returns if a connect operation was issued before, and finishConnect() must be called once the connect operation can be finished.

protected boolean

Returns:

true if supported, false otherwise.
isExtendedOptionSupported
(ChannelOption<?> option)

Override to add support for more ChannelOptions.

public final boolean
isOptionSupported(ChannelOption<?>
the option.
option
)

Implements io.netty5.channel.Channel.isOptionSupported.

Returns true if the given ChannelOption is supported by this Channel implementation.
protected final boolean

Returns:

if a read is pending.
isReadPending
()

Returns true if a read is currently scheduled and pending for later execution.

public final boolean
isRegistered()

Implements io.netty5.channel.IoHandle.isRegistered.

Return true if registered already.
protected final boolean

Returns:

true if supported.
isSupportingDisconnect
()

Returns true if the implementation supports disconnecting and re-connecting, false otherwise.

protected boolean

Returns:

true if write will be done later on by calling writeFlushedNow(), false otherwise.
isWriteFlushedScheduled
()

Returns true if flushed messages should not be tried to write when calling flush().

public final L
localAddress()

Implements io.netty5.channel.Channel.localAddress.

Returns the local address where this channel is bound to.
protected abstract L

Returns:

the local address if any, null otherwise.
localAddress0
()

Returns the SocketAddress which is bound locally.

protected ChannelPipeline
newChannelPipeline()

Returns a new ChannelPipeline instance.

private static ClosedChannelException
protected static Set<ChannelOption<?>>

Returns:

the Set that holds all the options.
newSupportedIdentityOptionsSet
(ChannelOption<?>...
the options.
options
)

Creates a new Set that holds the given ChannelOptions.

public final P
parent()

Implements io.netty5.channel.Channel.parent.

Returns the parent of this channel.
public final ChannelPipeline
protected Future<Executor>
prepareToClose()

Prepares to close the Channel.

protected BufferAllocator

Returns:

the BufferAllocator that is used to allocate Buffers that are used for reading.
readBufferAllocator
()

Return the BufferAllocator that is used to allocate Buffer that are used for reading.

protected final ReadHandleFactory.ReadHandle
protected final void
protected void
readLoopComplete()

Called once the read loop completed for this Channel.

protected final void
readNow()

Reading from the underlying transport now until there is nothing more to read or the ReadHandleFactory.ReadHandle is telling us to stop.

private AbstractChannel<P, L, R>.ReadSink
private void
readTransport(ReadBufferAllocator readBufferAllocator)

private void
registerTransport(final Promise<Void> promise)

public final R
remoteAddress()

Implements io.netty5.channel.Channel.remoteAddress.

Returns the remote address where this channel is connected to.
protected abstract R

Returns:

the remote address if any, null otherwise.
remoteAddress0
()

Return the SocketAddress which the Channel is connected to.

private static void
safeSetFailure(Promise<Void> promise, Throwable cause)

Marks the specified promise as failure.

private static void
safeSetSuccess(Promise<Void> promise)

Marks the specified promise as success.

private static void
private void
setAllowHalfClosure(boolean allowHalfClosure)

private void
setAutoClose(boolean autoClose)

private void
setAutoRead(boolean autoRead)

private void
private void
setConnectTimeoutMillis(int connectTimeoutMillis)

protected <
the value type.
T
>
void
setExtendedOption(ChannelOption<T> option, T value)

Override to add support for more ChannelOptions.

private void
public final <T> Channel
setOption(ChannelOption<T> option, T
the value for the ChannelOption
value
)

Implements io.netty5.channel.Channel.setOption.

Sets a configuration property with the specified name and value.
private void
private void
private void
private boolean
shutdownOutput(final Promise<Void> promise, Throwable
The cause which may provide rational for the shutdown.
cause
)

Shutdown the output portion of the corresponding Channel.

protected final void
shutdownReadSide()

Shutdown the read side of this channel.

private void
private MessageSizeEstimator.Handle
private static Set<ChannelOption<?>>
public String
toString()

Overrides java.lang.Object.toString.

Returns the String representation of this channel.
private long
private void
updateWritabilityIfNeeded(boolean notify, boolean notifyLater)

protected static <
the concreate type of the EventLoopGroup.
T extends EventLoopGroup
>
T

Returns:

the group itself
validateEventLoopGroup
(T
the group to check against
group
,
String
the name of the param that is used when throwing an exception.
name
,
Class<? extends Channel>
the Channel type.
channelType
)

Validate that the EventLoopGroup supports the given channel type.

protected static void
validateFileRegion(DefaultFileRegion
the region to validate.
region
,
long
the requested position
position
)

Validate a DefaultFileRegion

public final long
writableBytes()

Implements io.netty5.channel.Channel.writableBytes.

Returns how many bytes can be written before the Channel becomes 'unwritable'.
protected final void
writeFlushed()

Writing previous flushed messages if isWriteFlushedScheduled() returns false, otherwise do nothing.

protected final void
writeFlushedNow()

Writing previous flushed messages now.

protected final WriteHandleFactory.WriteHandle
protected void
writeLoopComplete(boolean
true if all messages were written during the write loop, false otherwise.
allWritten
)

Called once the write loop completed.

private AbstractChannel<P, L, R>.WriteSink
private void
Inherited from io.netty5.util.DefaultAttributeMap:
attrhasAttr