Package io.netty.channel.nio
Class AbstractNioChannel
- java.lang.Object
-
- io.netty.util.DefaultAttributeMap
-
- io.netty.channel.AbstractChannel
-
- io.netty.channel.nio.AbstractNioChannel
-
- All Implemented Interfaces:
Channel,ChannelOutboundInvoker,AttributeMap,java.lang.Comparable<Channel>
- Direct Known Subclasses:
AbstractNioByteChannel,AbstractNioMessageChannel
public abstract class AbstractNioChannel extends AbstractChannel
Abstract base class forChannelimplementations which use a Selector based approach.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description protected classAbstractNioChannel.AbstractNioUnsafestatic interfaceAbstractNioChannel.NioUnsafeSpecialChannel.Unsafesub-type which allows to access the underlyingSelectableChannel-
Nested classes/interfaces inherited from class io.netty.channel.AbstractChannel
AbstractChannel.AbstractUnsafe
-
Nested classes/interfaces inherited from interface io.netty.channel.Channel
Channel.Unsafe
-
-
Field Summary
Fields Modifier and Type Field Description private java.nio.channels.SelectableChannelchprivate java.lang.RunnableclearReadPendingRunnableprivate ChannelPromiseconnectPromiseThe future of the current connection attempt.private java.util.concurrent.ScheduledFuture<?>connectTimeoutFutureprivate static InternalLoggerloggerprotected intreadInterestOp(package private) booleanreadPendingprivate java.net.SocketAddressrequestedRemoteAddress(package private) java.nio.channels.SelectionKeyselectionKey
-
Constructor Summary
Constructors Modifier Constructor Description protectedAbstractNioChannel(Channel parent, java.nio.channels.SelectableChannel ch, int readInterestOp)Create a new instance
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Deprecated Methods Modifier and Type Method Description protected voidclearReadPending()Set read pending tofalse.private voidclearReadPending0()protected voiddoBeginRead()Schedule a read operation.protected voiddoClose()Close theChannelprotected abstract booleandoConnect(java.net.SocketAddress remoteAddress, java.net.SocketAddress localAddress)Connect to the remote peerprotected voiddoDeregister()protected abstract voiddoFinishConnect()Finish the connectprotected voiddoRegister()NioEventLoopeventLoop()protected booleanisCompatible(EventLoop loop)Returntrueif the givenEventLoopis compatible with this instance.booleanisOpen()Returnstrueif theChannelis open and may get active laterprotected booleanisReadPending()Deprecated.No longer supported.protected java.nio.channels.SelectableChanneljavaChannel()protected ByteBufnewDirectBuffer(ByteBuf buf)Returns an off-heap copy of the specifiedByteBuf, and releases the original one.protected ByteBufnewDirectBuffer(ReferenceCounted holder, ByteBuf buf)Returns an off-heap copy of the specifiedByteBuf, and releases the specified holder.protected java.nio.channels.SelectionKeyselectionKey()Return the currentSelectionKeyprotected voidsetReadPending(boolean readPending)Deprecated.UseclearReadPending()if appropriate instead.private voidsetReadPending0(boolean readPending)AbstractNioChannel.NioUnsafeunsafe()Returns an internal-use-only object that provides unsafe operations.-
Methods inherited from class io.netty.channel.AbstractChannel
alloc, bind, bind, bytesBeforeUnwritable, bytesBeforeWritable, close, close, closeFuture, compareTo, connect, connect, connect, connect, deregister, deregister, disconnect, disconnect, doBind, doDisconnect, doShutdownOutput, doWrite, equals, filterOutboundMessage, flush, hashCode, id, invalidateLocalAddress, invalidateRemoteAddress, isRegistered, isWritable, localAddress, localAddress0, newChannelPipeline, newFailedFuture, newId, newProgressivePromise, newPromise, newSucceededFuture, newUnsafe, parent, pipeline, read, remoteAddress, remoteAddress0, toString, validateFileRegion, voidPromise, write, write, writeAndFlush, writeAndFlush
-
Methods inherited from class io.netty.util.DefaultAttributeMap
attr, hasAttr
-
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface io.netty.util.AttributeMap
attr, hasAttr
-
-
-
-
Field Detail
-
logger
private static final InternalLogger logger
-
ch
private final java.nio.channels.SelectableChannel ch
-
readInterestOp
protected final int readInterestOp
-
selectionKey
volatile java.nio.channels.SelectionKey selectionKey
-
readPending
boolean readPending
-
clearReadPendingRunnable
private final java.lang.Runnable clearReadPendingRunnable
-
connectPromise
private ChannelPromise connectPromise
The future of the current connection attempt. If not null, subsequent connection attempts will fail.
-
connectTimeoutFuture
private java.util.concurrent.ScheduledFuture<?> connectTimeoutFuture
-
requestedRemoteAddress
private java.net.SocketAddress requestedRemoteAddress
-
-
Constructor Detail
-
AbstractNioChannel
protected AbstractNioChannel(Channel parent, java.nio.channels.SelectableChannel ch, int readInterestOp)
Create a new instance- Parameters:
parent- the parentChannelby which this instance was created. May benullch- the underlyingSelectableChannelon which it operatesreadInterestOp- the ops to set to receive data from theSelectableChannel
-
-
Method Detail
-
isOpen
public boolean isOpen()
Description copied from interface:ChannelReturnstrueif theChannelis open and may get active later
-
unsafe
public AbstractNioChannel.NioUnsafe unsafe()
Description copied from interface:ChannelReturns an internal-use-only object that provides unsafe operations.- Specified by:
unsafein interfaceChannel- Overrides:
unsafein classAbstractChannel
-
javaChannel
protected java.nio.channels.SelectableChannel javaChannel()
-
eventLoop
public NioEventLoop eventLoop()
Description copied from interface:Channel- Specified by:
eventLoopin interfaceChannel- Overrides:
eventLoopin classAbstractChannel
-
selectionKey
protected java.nio.channels.SelectionKey selectionKey()
Return the currentSelectionKey
-
isReadPending
@Deprecated protected boolean isReadPending()
Deprecated.No longer supported. No longer supported.
-
setReadPending
@Deprecated protected void setReadPending(boolean readPending)
Deprecated.UseclearReadPending()if appropriate instead. No longer supported.
-
clearReadPending
protected final void clearReadPending()
Set read pending tofalse.
-
setReadPending0
private void setReadPending0(boolean readPending)
-
clearReadPending0
private void clearReadPending0()
-
isCompatible
protected boolean isCompatible(EventLoop loop)
Description copied from class:AbstractChannelReturntrueif the givenEventLoopis compatible with this instance.- Specified by:
isCompatiblein classAbstractChannel
-
doRegister
protected void doRegister() throws java.lang.ExceptionDescription copied from class:AbstractChannelIs called after theChannelis registered with itsEventLoopas part of the register process. Sub-classes may override this method- Overrides:
doRegisterin classAbstractChannel- Throws:
java.lang.Exception
-
doDeregister
protected void doDeregister() throws java.lang.ExceptionDescription copied from class:AbstractChannel- Overrides:
doDeregisterin classAbstractChannel- Throws:
java.lang.Exception
-
doBeginRead
protected void doBeginRead() throws java.lang.ExceptionDescription copied from class:AbstractChannelSchedule a read operation.- Specified by:
doBeginReadin classAbstractChannel- Throws:
java.lang.Exception
-
doConnect
protected abstract boolean doConnect(java.net.SocketAddress remoteAddress, java.net.SocketAddress localAddress) throws java.lang.ExceptionConnect to the remote peer- Throws:
java.lang.Exception
-
doFinishConnect
protected abstract void doFinishConnect() throws java.lang.ExceptionFinish the connect- Throws:
java.lang.Exception
-
newDirectBuffer
protected final ByteBuf newDirectBuffer(ReferenceCounted holder, ByteBuf buf)
Returns an off-heap copy of the specifiedByteBuf, and releases the specified holder. The caller must ensure that the holder releases the originalByteBufwhen the holder is released by this method. Note that this method does not create an off-heap copy if the allocation / deallocation cost is too high, but just returns the originalByteBuf..
-
doClose
protected void doClose() throws java.lang.ExceptionDescription copied from class:AbstractChannelClose theChannel- Specified by:
doClosein classAbstractChannel- Throws:
java.lang.Exception
-
-