Package org.apache.tomcat.util.net
Class Nio2Channel
- java.lang.Object
- 
- org.apache.tomcat.util.net.Nio2Channel
 
- 
- All Implemented Interfaces:
- java.io.Closeable,- java.lang.AutoCloseable,- java.nio.channels.AsynchronousByteChannel,- java.nio.channels.AsynchronousChannel,- java.nio.channels.Channel
 - Direct Known Subclasses:
- SecureNio2Channel
 
 public class Nio2Channel extends java.lang.Object implements java.nio.channels.AsynchronousByteChannelBase class for a SocketChannel wrapper used by the endpoint. This way, logic for an SSL socket channel remains the same as for a non SSL, making sure we don't need to code for any exception cases.
- 
- 
Field SummaryFields Modifier and Type Field Description protected SocketBufferHandlerbufHandlerprotected static java.nio.ByteBufferemptyBufprotected java.nio.channels.AsynchronousSocketChannelscprotected SocketWrapperBase<Nio2Channel>socketWrapper
 - 
Constructor SummaryConstructors Constructor Description Nio2Channel(SocketBufferHandler bufHandler)
 - 
Method SummaryAll Methods Instance Methods Concrete Methods Modifier and Type Method Description voidclose()Closes this channel.voidclose(boolean force)Close the connection.java.util.concurrent.Future<java.lang.Boolean>flush()voidfree()Free the channel memoryprotected ApplicationBufferHandlergetAppReadBufHandler()SocketBufferHandlergetBufHandler()java.nio.channels.AsynchronousSocketChannelgetIOChannel()inthandshake()Performs SSL handshake hence is a no-op for the non-secure implementation.booleanisClosing()booleanisHandshakeComplete()booleanisOpen()Tells whether or not this channel is open.java.util.concurrent.Future<java.lang.Integer>read(java.nio.ByteBuffer dst)<A> voidread(java.nio.ByteBuffer[] dsts, int offset, int length, long timeout, java.util.concurrent.TimeUnit unit, A attachment, java.nio.channels.CompletionHandler<java.lang.Long,? super A> handler)<A> voidread(java.nio.ByteBuffer dst, long timeout, java.util.concurrent.TimeUnit unit, A attachment, java.nio.channels.CompletionHandler<java.lang.Integer,? super A> handler)<A> voidread(java.nio.ByteBuffer dst, A attachment, java.nio.channels.CompletionHandler<java.lang.Integer,? super A> handler)voidreset(java.nio.channels.AsynchronousSocketChannel channel, SocketWrapperBase<Nio2Channel> socketWrapper)Reset the channel.voidsetAppReadBufHandler(ApplicationBufferHandler handler)java.lang.StringtoString()java.util.concurrent.Future<java.lang.Integer>write(java.nio.ByteBuffer src)<A> voidwrite(java.nio.ByteBuffer[] srcs, int offset, int length, long timeout, java.util.concurrent.TimeUnit unit, A attachment, java.nio.channels.CompletionHandler<java.lang.Long,? super A> handler)<A> voidwrite(java.nio.ByteBuffer src, long timeout, java.util.concurrent.TimeUnit unit, A attachment, java.nio.channels.CompletionHandler<java.lang.Integer,? super A> handler)<A> voidwrite(java.nio.ByteBuffer src, A attachment, java.nio.channels.CompletionHandler<java.lang.Integer,? super A> handler)
 
- 
- 
- 
Field Detail- 
emptyBufprotected static final java.nio.ByteBuffer emptyBuf 
 - 
bufHandlerprotected final SocketBufferHandler bufHandler 
 - 
scprotected java.nio.channels.AsynchronousSocketChannel sc 
 - 
socketWrapperprotected SocketWrapperBase<Nio2Channel> socketWrapper 
 
- 
 - 
Constructor Detail- 
Nio2Channelpublic Nio2Channel(SocketBufferHandler bufHandler) 
 
- 
 - 
Method Detail- 
resetpublic void reset(java.nio.channels.AsynchronousSocketChannel channel, SocketWrapperBase<Nio2Channel> socketWrapper) throws java.io.IOExceptionReset the channel.- Parameters:
- channel- The new async channel to associate with this NIO2 channel
- socketWrapper- The new socket to associate with this NIO2 channel
- Throws:
- java.io.IOException- If a problem was encountered resetting the channel
 
 - 
freepublic void free() Free the channel memory
 - 
closepublic void close() throws java.io.IOExceptionCloses this channel.- Specified by:
- closein interface- java.nio.channels.AsynchronousChannel
- Specified by:
- closein interface- java.lang.AutoCloseable
- Specified by:
- closein interface- java.nio.channels.Channel
- Specified by:
- closein interface- java.io.Closeable
- Throws:
- java.io.IOException- If an I/O error occurs
 
 - 
closepublic void close(boolean force) throws java.io.IOExceptionClose the connection.- Parameters:
- force- Should the underlying socket be forcibly closed?
- Throws:
- java.io.IOException- If closing the secure channel fails.
 
 - 
isOpenpublic boolean isOpen() Tells whether or not this channel is open.- Specified by:
- isOpenin interface- java.nio.channels.Channel
- Returns:
- trueif, and only if, this channel is open
 
 - 
getBufHandlerpublic SocketBufferHandler getBufHandler() 
 - 
getIOChannelpublic java.nio.channels.AsynchronousSocketChannel getIOChannel() 
 - 
isClosingpublic boolean isClosing() 
 - 
isHandshakeCompletepublic boolean isHandshakeComplete() 
 - 
handshakepublic int handshake() throws java.io.IOExceptionPerforms SSL handshake hence is a no-op for the non-secure implementation.- Returns:
- Always returns zero
- Throws:
- java.io.IOException- Never for non-secure channel
 
 - 
toStringpublic java.lang.String toString() - Overrides:
- toStringin class- java.lang.Object
 
 - 
readpublic java.util.concurrent.Future<java.lang.Integer> read(java.nio.ByteBuffer dst) - Specified by:
- readin interface- java.nio.channels.AsynchronousByteChannel
 
 - 
readpublic <A> void read(java.nio.ByteBuffer dst, A attachment, java.nio.channels.CompletionHandler<java.lang.Integer,? super A> handler)- Specified by:
- readin interface- java.nio.channels.AsynchronousByteChannel
 
 - 
readpublic <A> void read(java.nio.ByteBuffer dst, long timeout, java.util.concurrent.TimeUnit unit, A attachment, java.nio.channels.CompletionHandler<java.lang.Integer,? super A> handler)
 - 
readpublic <A> void read(java.nio.ByteBuffer[] dsts, int offset, int length, long timeout, java.util.concurrent.TimeUnit unit, A attachment, java.nio.channels.CompletionHandler<java.lang.Long,? super A> handler)
 - 
writepublic java.util.concurrent.Future<java.lang.Integer> write(java.nio.ByteBuffer src) - Specified by:
- writein interface- java.nio.channels.AsynchronousByteChannel
 
 - 
writepublic <A> void write(java.nio.ByteBuffer src, A attachment, java.nio.channels.CompletionHandler<java.lang.Integer,? super A> handler)- Specified by:
- writein interface- java.nio.channels.AsynchronousByteChannel
 
 - 
writepublic <A> void write(java.nio.ByteBuffer src, long timeout, java.util.concurrent.TimeUnit unit, A attachment, java.nio.channels.CompletionHandler<java.lang.Integer,? super A> handler)
 - 
writepublic <A> void write(java.nio.ByteBuffer[] srcs, int offset, int length, long timeout, java.util.concurrent.TimeUnit unit, A attachment, java.nio.channels.CompletionHandler<java.lang.Long,? super A> handler)
 - 
flushpublic java.util.concurrent.Future<java.lang.Boolean> flush() 
 - 
setAppReadBufHandlerpublic void setAppReadBufHandler(ApplicationBufferHandler handler) 
 - 
getAppReadBufHandlerprotected ApplicationBufferHandler getAppReadBufHandler() 
 
- 
 
-