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 Summary
Fields Modifier and Type Field Description protected SocketBufferHandlerbufHandlerprotected static java.nio.ByteBufferemptyBufprotected java.nio.channels.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.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
-
emptyBuf
protected static final java.nio.ByteBuffer emptyBuf
-
bufHandler
protected final SocketBufferHandler bufHandler
-
sc
protected java.nio.channels.AsynchronousSocketChannel sc
-
socketWrapper
protected SocketWrapperBase<Nio2Channel> socketWrapper
-
-
Constructor Detail
-
Nio2Channel
public Nio2Channel(SocketBufferHandler bufHandler)
-
-
Method Detail
-
reset
public 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 channelsocketWrapper- The new socket to associate with this NIO2 channel- Throws:
java.io.IOException- If a problem was encountered resetting the channel
-
free
public void free()
Free the channel memory
-
close
public void close() throws java.io.IOExceptionCloses this channel.- Specified by:
closein interfacejava.nio.channels.AsynchronousChannel- Specified by:
closein interfacejava.lang.AutoCloseable- Specified by:
closein interfacejava.nio.channels.Channel- Specified by:
closein interfacejava.io.Closeable- Throws:
java.io.IOException- If an I/O error occurs
-
close
public 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.
-
isOpen
public boolean isOpen()
Tells whether or not this channel is open.- Specified by:
isOpenin interfacejava.nio.channels.Channel- Returns:
trueif, and only if, this channel is open
-
getBufHandler
public SocketBufferHandler getBufHandler()
-
getIOChannel
public java.nio.channels.AsynchronousSocketChannel getIOChannel()
-
isClosing
public boolean isClosing()
-
isHandshakeComplete
public boolean isHandshakeComplete()
-
handshake
public 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
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
read
public java.util.concurrent.Future<java.lang.Integer> read(java.nio.ByteBuffer dst)
- Specified by:
readin interfacejava.nio.channels.AsynchronousByteChannel
-
read
public <A> void read(java.nio.ByteBuffer dst, A attachment, java.nio.channels.CompletionHandler<java.lang.Integer,? super A> handler)- Specified by:
readin interfacejava.nio.channels.AsynchronousByteChannel
-
read
public <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)
-
read
public <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)
-
write
public java.util.concurrent.Future<java.lang.Integer> write(java.nio.ByteBuffer src)
- Specified by:
writein interfacejava.nio.channels.AsynchronousByteChannel
-
write
public <A> void write(java.nio.ByteBuffer src, A attachment, java.nio.channels.CompletionHandler<java.lang.Integer,? super A> handler)- Specified by:
writein interfacejava.nio.channels.AsynchronousByteChannel
-
write
public <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)
-
write
public <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)
-
flush
public java.util.concurrent.Future<java.lang.Boolean> flush()
-
setAppReadBufHandler
public void setAppReadBufHandler(ApplicationBufferHandler handler)
-
getAppReadBufHandler
protected ApplicationBufferHandler getAppReadBufHandler()
-
-