Package io.netty.channel
Class AbstractChannel.AbstractUnsafe
- java.lang.Object
-
- io.netty.channel.AbstractChannel.AbstractUnsafe
-
- All Implemented Interfaces:
Channel.Unsafe
- Direct Known Subclasses:
AbstractNioChannel.AbstractNioUnsafe,AbstractOioChannel.DefaultOioUnsafe,AbstractServerChannel.DefaultServerUnsafe,EmbeddedChannel.EmbeddedUnsafe,FailedChannel.FailedChannelUnsafe,LocalChannel.LocalUnsafe
- Enclosing class:
- AbstractChannel
protected abstract class AbstractChannel.AbstractUnsafe extends java.lang.Object implements Channel.Unsafe
Channel.Unsafeimplementation which sub-classes must extend and use.
-
-
Field Summary
Fields Modifier and Type Field Description private booleaninFlush0private booleanneverRegisteredtrue if the channel has never been registered, false otherwiseprivate ChannelOutboundBufferoutboundBufferprivate RecvByteBufAllocator.HandlerecvHandle
-
Constructor Summary
Constructors Modifier Constructor Description protectedAbstractUnsafe()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected java.lang.ThrowableannotateConnectException(java.lang.Throwable cause, java.net.SocketAddress remoteAddress)Appends the remote address to the message of the exceptions caused by connection attempt failure.private voidassertEventLoop()voidbeginRead()Schedules a read operation that fills the inbound buffer of the firstChannelInboundHandlerin theChannelPipeline.voidbind(java.net.SocketAddress localAddress, ChannelPromise promise)voidclose(ChannelPromise promise)Close theChannelof theChannelPromiseand notify theChannelPromiseonce the operation was complete.private voidclose(ChannelPromise promise, java.lang.Throwable cause, java.nio.channels.ClosedChannelException closeCause, boolean notify)voidcloseForcibly()Closes theChannelimmediately without firing any events.protected voidcloseIfClosed()private voidcloseOutboundBufferForShutdown(ChannelPipeline pipeline, ChannelOutboundBuffer buffer, java.lang.Throwable cause)voidderegister(ChannelPromise promise)Deregister theChannelof theChannelPromisefromEventLoopand notify theChannelPromiseonce the operation was complete.private voidderegister(ChannelPromise promise, boolean fireChannelInactive)voiddisconnect(ChannelPromise promise)Disconnect theChannelof theChannelFutureand notify theChannelPromiseonce the operation was complete.private voiddoClose0(ChannelPromise promise)protected booleanensureOpen(ChannelPromise promise)private voidfireChannelInactiveAndDeregister(boolean wasActive)voidflush()Flush out all write operations scheduled viaChannel.Unsafe.write(Object, ChannelPromise).protected voidflush0()private voidinvokeLater(java.lang.Runnable task)java.net.SocketAddresslocalAddress()Return theSocketAddressto which is bound local ornullif none.private java.nio.channels.ClosedChannelExceptionnewClosedChannelException(java.lang.Throwable cause)ChannelOutboundBufferoutboundBuffer()Returns theChannelOutboundBufferof theChannelwhere the pending write requests are stored.protected java.util.concurrent.ExecutorprepareToClose()Prepares to close theChannel.RecvByteBufAllocator.HandlerecvBufAllocHandle()Return the assignedRecvByteBufAllocator.Handlewhich will be used to allocateByteBuf's when receiving data.voidregister(EventLoop eventLoop, ChannelPromise promise)Register theChannelof theChannelPromiseand notify theChannelFutureonce the registration was complete.private voidregister0(ChannelPromise promise)java.net.SocketAddressremoteAddress()Return theSocketAddressto which is bound remote ornullif none is bound yet.protected voidsafeSetFailure(ChannelPromise promise, java.lang.Throwable cause)Marks the specifiedpromiseas failure.protected voidsafeSetSuccess(ChannelPromise promise)Marks the specifiedpromiseas success.voidshutdownOutput(ChannelPromise promise)Shutdown the output portion of the correspondingChannel.private voidshutdownOutput(ChannelPromise promise, java.lang.Throwable cause)Shutdown the output portion of the correspondingChannel.ChannelPromisevoidPromise()Return a special ChannelPromise which can be reused and passed to the operations inChannel.Unsafe.voidwrite(java.lang.Object msg, ChannelPromise promise)Schedules a write operation.-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface io.netty.channel.Channel.Unsafe
connect
-
-
-
-
Field Detail
-
outboundBuffer
private volatile ChannelOutboundBuffer outboundBuffer
-
recvHandle
private RecvByteBufAllocator.Handle recvHandle
-
inFlush0
private boolean inFlush0
-
neverRegistered
private boolean neverRegistered
true if the channel has never been registered, false otherwise
-
-
Method Detail
-
assertEventLoop
private void assertEventLoop()
-
recvBufAllocHandle
public RecvByteBufAllocator.Handle recvBufAllocHandle()
Description copied from interface:Channel.UnsafeReturn the assignedRecvByteBufAllocator.Handlewhich will be used to allocateByteBuf's when receiving data.- Specified by:
recvBufAllocHandlein interfaceChannel.Unsafe
-
outboundBuffer
public final ChannelOutboundBuffer outboundBuffer()
Description copied from interface:Channel.UnsafeReturns theChannelOutboundBufferof theChannelwhere the pending write requests are stored.- Specified by:
outboundBufferin interfaceChannel.Unsafe
-
localAddress
public final java.net.SocketAddress localAddress()
Description copied from interface:Channel.UnsafeReturn theSocketAddressto which is bound local ornullif none.- Specified by:
localAddressin interfaceChannel.Unsafe
-
remoteAddress
public final java.net.SocketAddress remoteAddress()
Description copied from interface:Channel.UnsafeReturn theSocketAddressto which is bound remote ornullif none is bound yet.- Specified by:
remoteAddressin interfaceChannel.Unsafe
-
register
public final void register(EventLoop eventLoop, ChannelPromise promise)
Description copied from interface:Channel.UnsafeRegister theChannelof theChannelPromiseand notify theChannelFutureonce the registration was complete.- Specified by:
registerin interfaceChannel.Unsafe
-
register0
private void register0(ChannelPromise promise)
-
bind
public final void bind(java.net.SocketAddress localAddress, ChannelPromise promise)Description copied from interface:Channel.Unsafe- Specified by:
bindin interfaceChannel.Unsafe
-
disconnect
public final void disconnect(ChannelPromise promise)
Description copied from interface:Channel.UnsafeDisconnect theChannelof theChannelFutureand notify theChannelPromiseonce the operation was complete.- Specified by:
disconnectin interfaceChannel.Unsafe
-
close
public final void close(ChannelPromise promise)
Description copied from interface:Channel.UnsafeClose theChannelof theChannelPromiseand notify theChannelPromiseonce the operation was complete.- Specified by:
closein interfaceChannel.Unsafe
-
shutdownOutput
@UnstableApi public final void shutdownOutput(ChannelPromise promise)
Shutdown the output portion of the correspondingChannel. For example this will clean up theChannelOutboundBufferand not allow any more writes.
-
shutdownOutput
private void shutdownOutput(ChannelPromise promise, java.lang.Throwable cause)
Shutdown the output portion of the correspondingChannel. For example this will clean up theChannelOutboundBufferand not allow any more writes.- Parameters:
cause- The cause which may provide rational for the shutdown.
-
closeOutboundBufferForShutdown
private void closeOutboundBufferForShutdown(ChannelPipeline pipeline, ChannelOutboundBuffer buffer, java.lang.Throwable cause)
-
close
private void close(ChannelPromise promise, java.lang.Throwable cause, java.nio.channels.ClosedChannelException closeCause, boolean notify)
-
doClose0
private void doClose0(ChannelPromise promise)
-
fireChannelInactiveAndDeregister
private void fireChannelInactiveAndDeregister(boolean wasActive)
-
closeForcibly
public final void closeForcibly()
Description copied from interface:Channel.UnsafeCloses theChannelimmediately without firing any events. Probably only useful when registration attempt failed.- Specified by:
closeForciblyin interfaceChannel.Unsafe
-
deregister
public final void deregister(ChannelPromise promise)
Description copied from interface:Channel.UnsafeDeregister theChannelof theChannelPromisefromEventLoopand notify theChannelPromiseonce the operation was complete.- Specified by:
deregisterin interfaceChannel.Unsafe
-
deregister
private void deregister(ChannelPromise promise, boolean fireChannelInactive)
-
beginRead
public final void beginRead()
Description copied from interface:Channel.UnsafeSchedules a read operation that fills the inbound buffer of the firstChannelInboundHandlerin theChannelPipeline. If there's already a pending read operation, this method does nothing.- Specified by:
beginReadin interfaceChannel.Unsafe
-
write
public final void write(java.lang.Object msg, ChannelPromise promise)Description copied from interface:Channel.UnsafeSchedules a write operation.- Specified by:
writein interfaceChannel.Unsafe
-
flush
public final void flush()
Description copied from interface:Channel.UnsafeFlush out all write operations scheduled viaChannel.Unsafe.write(Object, ChannelPromise).- Specified by:
flushin interfaceChannel.Unsafe
-
flush0
protected void flush0()
-
newClosedChannelException
private java.nio.channels.ClosedChannelException newClosedChannelException(java.lang.Throwable cause)
-
voidPromise
public final ChannelPromise voidPromise()
Description copied from interface:Channel.UnsafeReturn a special ChannelPromise which can be reused and passed to the operations inChannel.Unsafe. It will never be notified of a success or error and so is only a placeholder for operations that take aChannelPromiseas argument but for which you not want to get notified.- Specified by:
voidPromisein interfaceChannel.Unsafe
-
ensureOpen
protected final boolean ensureOpen(ChannelPromise promise)
-
safeSetSuccess
protected final void safeSetSuccess(ChannelPromise promise)
Marks the specifiedpromiseas success. If thepromiseis done already, log a message.
-
safeSetFailure
protected final void safeSetFailure(ChannelPromise promise, java.lang.Throwable cause)
Marks the specifiedpromiseas failure. If thepromiseis done already, log a message.
-
closeIfClosed
protected final void closeIfClosed()
-
invokeLater
private void invokeLater(java.lang.Runnable task)
-
annotateConnectException
protected final java.lang.Throwable annotateConnectException(java.lang.Throwable cause, java.net.SocketAddress remoteAddress)Appends the remote address to the message of the exceptions caused by connection attempt failure.
-
prepareToClose
protected java.util.concurrent.Executor prepareToClose()
Prepares to close theChannel. If this method returns anExecutor, the caller must call theExecutor.execute(Runnable)method with a task that callsAbstractChannel.doClose()on the returnedExecutor. If this method returnsnull,AbstractChannel.doClose()must be called from the caller thread. (i.e.EventLoop)
-
-