Package org.apache.tomcat.util.net
Class Nio2Channel
- java.lang.Object
-
- org.apache.tomcat.util.net.Nio2Channel
-
- All Implemented Interfaces:
Closeable,AutoCloseable,AsynchronousByteChannel,AsynchronousChannel,Channel
- Direct Known Subclasses:
SecureNio2Channel
public class Nio2Channel extends Object implements AsynchronousByteChannel
Base 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 Summary
Fields Modifier and Type Field Description protected SocketBufferHandlerbufHandlerprotected static ByteBufferemptyBufprotected AsynchronousSocketChannelscprotected SocketWrapperBase<Nio2Channel>socketWrapper
-
Constructor Summary
Constructors Constructor Description Nio2Channel(SocketBufferHandler bufHandler)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidclose()Closes this channel.voidclose(boolean force)Close the connection.Future<Boolean>flush()voidfree()Free the channel memoryprotected ApplicationBufferHandlergetAppReadBufHandler()SocketBufferHandlergetBufHandler()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.Future<Integer>read(ByteBuffer dst)<A> voidread(ByteBuffer[] dsts, int offset, int length, long timeout, TimeUnit unit, A attachment, CompletionHandler<Long,? super A> handler)<A> voidread(ByteBuffer dst, long timeout, TimeUnit unit, A attachment, CompletionHandler<Integer,? super A> handler)<A> voidread(ByteBuffer dst, A attachment, CompletionHandler<Integer,? super A> handler)voidreset(AsynchronousSocketChannel channel, SocketWrapperBase<Nio2Channel> socketWrapper)Reset the channel.voidsetAppReadBufHandler(ApplicationBufferHandler handler)StringtoString()Future<Integer>write(ByteBuffer src)<A> voidwrite(ByteBuffer[] srcs, int offset, int length, long timeout, TimeUnit unit, A attachment, CompletionHandler<Long,? super A> handler)<A> voidwrite(ByteBuffer src, long timeout, TimeUnit unit, A attachment, CompletionHandler<Integer,? super A> handler)<A> voidwrite(ByteBuffer src, A attachment, CompletionHandler<Integer,? super A> handler)
-
-
-
Field Detail
-
emptyBuf
protected static final ByteBuffer emptyBuf
-
bufHandler
protected final SocketBufferHandler bufHandler
-
sc
protected AsynchronousSocketChannel sc
-
socketWrapper
protected SocketWrapperBase<Nio2Channel> socketWrapper
-
-
Constructor Detail
-
Nio2Channel
public Nio2Channel(SocketBufferHandler bufHandler)
-
-
Method Detail
-
reset
public void reset(AsynchronousSocketChannel channel, SocketWrapperBase<Nio2Channel> socketWrapper) throws IOException
Reset the channel.- Parameters:
channel- The new async channel to associate with this NIO2 channelsocketWrapper- The new socket to associate with this NIO2 channel- Throws:
IOException- If a problem was encountered resetting the channel
-
free
public void free()
Free the channel memory
-
close
public void close() throws IOExceptionCloses this channel.- Specified by:
closein interfaceAsynchronousChannel- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceChannel- Specified by:
closein interfaceCloseable- Throws:
IOException- If an I/O error occurs
-
close
public void close(boolean force) throws IOExceptionClose the connection.- Parameters:
force- Should the underlying socket be forcibly closed?- Throws:
IOException- If closing the secure channel fails.
-
isOpen
public boolean isOpen()
Tells whether or not this channel is open.
-
getBufHandler
public SocketBufferHandler getBufHandler()
-
getIOChannel
public AsynchronousSocketChannel getIOChannel()
-
isClosing
public boolean isClosing()
-
isHandshakeComplete
public boolean isHandshakeComplete()
-
handshake
public int handshake() throws IOExceptionPerforms SSL handshake hence is a no-op for the non-secure implementation.- Returns:
- Always returns zero
- Throws:
IOException- Never for non-secure channel
-
read
public Future<Integer> read(ByteBuffer dst)
- Specified by:
readin interfaceAsynchronousByteChannel
-
read
public <A> void read(ByteBuffer dst, A attachment, CompletionHandler<Integer,? super A> handler)
- Specified by:
readin interfaceAsynchronousByteChannel
-
read
public <A> void read(ByteBuffer dst, long timeout, TimeUnit unit, A attachment, CompletionHandler<Integer,? super A> handler)
-
read
public <A> void read(ByteBuffer[] dsts, int offset, int length, long timeout, TimeUnit unit, A attachment, CompletionHandler<Long,? super A> handler)
-
write
public Future<Integer> write(ByteBuffer src)
- Specified by:
writein interfaceAsynchronousByteChannel
-
write
public <A> void write(ByteBuffer src, A attachment, CompletionHandler<Integer,? super A> handler)
- Specified by:
writein interfaceAsynchronousByteChannel
-
write
public <A> void write(ByteBuffer src, long timeout, TimeUnit unit, A attachment, CompletionHandler<Integer,? super A> handler)
-
write
public <A> void write(ByteBuffer[] srcs, int offset, int length, long timeout, TimeUnit unit, A attachment, CompletionHandler<Long,? super A> handler)
-
setAppReadBufHandler
public void setAppReadBufHandler(ApplicationBufferHandler handler)
-
getAppReadBufHandler
protected ApplicationBufferHandler getAppReadBufHandler()
-
-