public abstract class SocketWrapperBase<E>
extends java.lang.Object
Modifier and Type | Class and Description |
---|---|
static class |
SocketWrapperBase.BlockingMode |
static interface |
SocketWrapperBase.CompletionCheck |
static class |
SocketWrapperBase.CompletionHandlerCall |
static class |
SocketWrapperBase.CompletionState |
Modifier and Type | Field and Description |
---|---|
protected java.util.concurrent.LinkedBlockingDeque<ByteBufferHolder> |
bufferedWrites
For "non-blocking" writes use an external set of buffers.
|
protected int |
bufferedWriteSize
The max size of the buffered write buffer
|
static SocketWrapperBase.CompletionCheck |
COMPLETE_WRITE
This utility CompletionCheck will cause the write to fully write
all remaining data.
|
static SocketWrapperBase.CompletionCheck |
COMPLETE_WRITE_WITH_COMPLETION
This utility CompletionCheck will cause the write to fully write
all remaining data.
|
protected java.lang.String |
localAddr |
protected java.lang.String |
localName |
protected int |
localPort |
static SocketWrapperBase.CompletionCheck |
READ_DATA
This utility CompletionCheck will cause the completion handler
to be called once some data has been read.
|
protected java.lang.String |
remoteAddr |
protected java.lang.String |
remoteHost |
protected int |
remotePort |
protected static StringManager |
sm |
protected SocketBufferHandler |
socketBufferHandler
The buffers used for communicating with the socket.
|
Constructor and Description |
---|
SocketWrapperBase(E socket,
AbstractEndpoint<E,?> endpoint) |
Modifier and Type | Method and Description |
---|---|
protected void |
addToBuffers(byte[] buf,
int offset,
int length) |
protected void |
addToBuffers(java.nio.ByteBuffer from) |
boolean |
awaitReadComplete(long timeout,
java.util.concurrent.TimeUnit unit)
If an asynchronous read operation is pending, this method will block
until the operation completes, or the specified amount of time
has passed.
|
boolean |
awaitWriteComplete(long timeout,
java.util.concurrent.TimeUnit unit)
If an asynchronous write operation is pending, this method will block
until the operation completes, or the specified amount of time
has passed.
|
boolean |
canWrite() |
void |
checkError() |
abstract void |
close() |
abstract SendfileDataBase |
createSendfileData(java.lang.String filename,
long pos,
long length) |
int |
decrementKeepAlive() |
abstract void |
doClientAuth(SSLSupport sslSupport)
Require the client to perform CLIENT-CERT authentication if it hasn't
already done so.
|
protected void |
doWrite(boolean block)
Write the contents of the socketWriteBuffer to the socket.
|
protected abstract void |
doWrite(boolean block,
java.nio.ByteBuffer from)
Write the contents of the ByteBuffer to the socket.
|
void |
execute(java.lang.Runnable runnable)
Transfers processing to a container thread.
|
boolean |
flush(boolean block)
Writes as much data as possible from any that remains in the buffers.
|
protected void |
flushBlocking() |
protected boolean |
flushNonBlocking() |
boolean |
getBlockingStatus() |
java.util.concurrent.locks.Lock |
getBlockingStatusReadLock() |
java.util.concurrent.locks.ReentrantReadWriteLock.WriteLock |
getBlockingStatusWriteLock() |
java.lang.Object |
getCurrentProcessor() |
protected AbstractEndpoint<E,?> |
getEndpoint() |
java.io.IOException |
getError() |
java.lang.String |
getLocalAddr() |
java.lang.String |
getLocalName() |
int |
getLocalPort() |
java.lang.String |
getNegotiatedProtocol() |
long |
getReadTimeout() |
java.lang.String |
getRemoteAddr() |
java.lang.String |
getRemoteHost() |
int |
getRemotePort() |
E |
getSocket() |
SocketBufferHandler |
getSocketBufferHandler() |
abstract SSLSupport |
getSslSupport(java.lang.String clientCertProvider) |
long |
getWriteTimeout() |
boolean |
hasAsyncIO()
Allows using NIO2 style read/write only for connectors that can
efficiently support it.
|
boolean |
hasDataToWrite() |
abstract boolean |
isClosed() |
boolean |
isReadPending()
Allows checking if an asynchronous read operation is currently pending.
|
abstract boolean |
isReadyForRead() |
boolean |
isReadyForWrite()
Checks to see if there are any writes pending and if there are calls
registerWriteInterest() to trigger a callback once the pending
writes have completed. |
boolean |
isSecure() |
boolean |
isUpgraded()
Deprecated.
Unused. Will be removed in Tomcat 10.
|
boolean |
isWritePending()
Allows checking if an asynchronous write operation is currently pending.
|
protected abstract void |
populateLocalAddr() |
protected abstract void |
populateLocalName() |
protected abstract void |
populateLocalPort() |
protected int |
populateReadBuffer(byte[] b,
int off,
int len) |
protected int |
populateReadBuffer(java.nio.ByteBuffer to) |
protected abstract void |
populateRemoteAddr() |
protected abstract void |
populateRemoteHost() |
protected abstract void |
populateRemotePort() |
abstract SendfileState |
processSendfile(SendfileDataBase sendfileData)
Starts the sendfile process.
|
void |
processSocket(SocketEvent socketStatus,
boolean dispatch) |
abstract int |
read(boolean block,
byte[] b,
int off,
int len) |
abstract int |
read(boolean block,
java.nio.ByteBuffer to) |
<A> SocketWrapperBase.CompletionState |
read(java.nio.ByteBuffer[] dsts,
int offset,
int length,
SocketWrapperBase.BlockingMode block,
long timeout,
java.util.concurrent.TimeUnit unit,
A attachment,
SocketWrapperBase.CompletionCheck check,
java.nio.channels.CompletionHandler<java.lang.Long,? super A> handler)
Scatter read.
|
<A> SocketWrapperBase.CompletionState |
read(SocketWrapperBase.BlockingMode block,
long timeout,
java.util.concurrent.TimeUnit unit,
A attachment,
SocketWrapperBase.CompletionCheck check,
java.nio.channels.CompletionHandler<java.lang.Long,? super A> handler,
java.nio.ByteBuffer... dsts)
Scatter read.
|
abstract void |
registerReadInterest() |
abstract void |
registerWriteInterest() |
abstract void |
setAppReadBufHandler(ApplicationBufferHandler handler) |
void |
setBlockingStatus(boolean blockingStatus) |
void |
setCurrentProcessor(java.lang.Object currentProcessor) |
void |
setError(java.io.IOException error) |
void |
setKeepAliveLeft(int keepAliveLeft) |
void |
setNegotiatedProtocol(java.lang.String negotiatedProtocol) |
void |
setReadTimeout(long readTimeout)
Set the timeout for reading.
|
void |
setSecure(boolean secure) |
void |
setUpgraded(boolean upgraded)
Deprecated.
Unused. Will be removed in Tomcat 10.
|
void |
setWriteTimeout(long writeTimeout)
Set the timeout for writing.
|
java.lang.Object |
takeCurrentProcessor() |
java.lang.String |
toString()
Overridden for debug purposes.
|
protected static int |
transfer(byte[] from,
int offset,
int length,
java.nio.ByteBuffer to) |
protected static int |
transfer(java.nio.ByteBuffer from,
java.nio.ByteBuffer to) |
void |
unRead(java.nio.ByteBuffer returnedInput)
Return input that has been read to the input buffer for re-reading by the
correct component.
|
void |
write(boolean block,
byte[] buf,
int off,
int len)
Writes the provided data to the socket, buffering any remaining data if
used in non-blocking mode.
|
void |
write(boolean block,
java.nio.ByteBuffer from)
Writes the provided data to the socket, buffering any remaining data if
used in non-blocking mode.
|
<A> SocketWrapperBase.CompletionState |
write(java.nio.ByteBuffer[] srcs,
int offset,
int length,
SocketWrapperBase.BlockingMode block,
long timeout,
java.util.concurrent.TimeUnit unit,
A attachment,
SocketWrapperBase.CompletionCheck check,
java.nio.channels.CompletionHandler<java.lang.Long,? super A> handler)
Gather write.
|
<A> SocketWrapperBase.CompletionState |
write(SocketWrapperBase.BlockingMode block,
long timeout,
java.util.concurrent.TimeUnit unit,
A attachment,
SocketWrapperBase.CompletionCheck check,
java.nio.channels.CompletionHandler<java.lang.Long,? super A> handler,
java.nio.ByteBuffer... srcs)
Gather write.
|
protected void |
writeBlocking(byte[] buf,
int off,
int len)
Transfers the data to the socket write buffer (writing that data to the
socket if the buffer fills up using a blocking write) until all the data
has been transferred and space remains in the socket write buffer.
|
protected void |
writeBlocking(java.nio.ByteBuffer from)
Write the data to the socket (writing that data to the socket using a
blocking write) until all the data has been transferred and space remains
in the socket write buffer.
|
protected void |
writeByteBufferBlocking(java.nio.ByteBuffer from) |
protected boolean |
writeByteBufferNonBlocking(java.nio.ByteBuffer from) |
protected void |
writeNonBlocking(byte[] buf,
int off,
int len)
Transfers the data to the socket write buffer (writing that data to the
socket if the buffer fills up using a non-blocking write) until either
all the data has been transferred and space remains in the socket write
buffer or a non-blocking write leaves data in the socket write buffer.
|
protected void |
writeNonBlocking(java.nio.ByteBuffer from)
Writes the data to the socket (writing that data to the socket using a
non-blocking write) until either all the data has been transferred and
space remains in the socket write buffer or a non-blocking write leaves
data in the socket write buffer.
|
protected static final StringManager sm
protected java.lang.String localAddr
protected java.lang.String localName
protected int localPort
protected java.lang.String remoteAddr
protected java.lang.String remoteHost
protected int remotePort
protected volatile SocketBufferHandler socketBufferHandler
protected final java.util.concurrent.LinkedBlockingDeque<ByteBufferHolder> bufferedWrites
protected int bufferedWriteSize
public static final SocketWrapperBase.CompletionCheck COMPLETE_WRITE
public static final SocketWrapperBase.CompletionCheck COMPLETE_WRITE_WITH_COMPLETION
public static final SocketWrapperBase.CompletionCheck READ_DATA
public SocketWrapperBase(E socket, AbstractEndpoint<E,?> endpoint)
public E getSocket()
public java.lang.Object getCurrentProcessor()
public void setCurrentProcessor(java.lang.Object currentProcessor)
public java.lang.Object takeCurrentProcessor()
protected AbstractEndpoint<E,?> getEndpoint()
public void execute(java.lang.Runnable runnable)
runnable
- The actions to process on a container threadjava.util.concurrent.RejectedExecutionException
- If the runnable cannot be executedpublic java.io.IOException getError()
public void setError(java.io.IOException error)
public void checkError() throws java.io.IOException
java.io.IOException
@Deprecated public boolean isUpgraded()
true
if the connection has been upgraded.@Deprecated public void setUpgraded(boolean upgraded)
upgraded
- true
if the connection has been upgraded.public boolean isSecure()
public void setSecure(boolean secure)
public java.lang.String getNegotiatedProtocol()
public void setNegotiatedProtocol(java.lang.String negotiatedProtocol)
public void setReadTimeout(long readTimeout)
readTimeout
- The timeout in milliseconds. A value of -1 indicates
an infinite timeout.public long getReadTimeout()
public void setWriteTimeout(long writeTimeout)
writeTimeout
- The timeout in milliseconds. A value of zero or less
indicates an infinite timeout.public long getWriteTimeout()
public void setKeepAliveLeft(int keepAliveLeft)
public int decrementKeepAlive()
public java.lang.String getRemoteHost()
protected abstract void populateRemoteHost()
public java.lang.String getRemoteAddr()
protected abstract void populateRemoteAddr()
public int getRemotePort()
protected abstract void populateRemotePort()
public java.lang.String getLocalName()
protected abstract void populateLocalName()
public java.lang.String getLocalAddr()
protected abstract void populateLocalAddr()
public int getLocalPort()
protected abstract void populateLocalPort()
public boolean getBlockingStatus()
public void setBlockingStatus(boolean blockingStatus)
public java.util.concurrent.locks.Lock getBlockingStatusReadLock()
public java.util.concurrent.locks.ReentrantReadWriteLock.WriteLock getBlockingStatusWriteLock()
public SocketBufferHandler getSocketBufferHandler()
public boolean hasDataToWrite()
public boolean isReadyForWrite()
registerWriteInterest()
to trigger a callback once the pending
writes have completed.
Note: Once this method has returned false
it MUST NOT
be called again until the pending write has completed and the
callback has been fired.
TODO: Modify registerWriteInterest()
so the above
restriction is enforced there rather than relying on the caller.
true
if no writes are pending and data can be
written otherwise false
public boolean canWrite()
public java.lang.String toString()
toString
in class java.lang.Object
public abstract int read(boolean block, byte[] b, int off, int len) throws java.io.IOException
java.io.IOException
public abstract int read(boolean block, java.nio.ByteBuffer to) throws java.io.IOException
java.io.IOException
public abstract boolean isReadyForRead() throws java.io.IOException
java.io.IOException
public abstract void setAppReadBufHandler(ApplicationBufferHandler handler)
protected int populateReadBuffer(byte[] b, int off, int len)
protected int populateReadBuffer(java.nio.ByteBuffer to)
public void unRead(java.nio.ByteBuffer returnedInput)
returnedInput
- The input to return to the input buffer.public abstract void close() throws java.io.IOException
java.io.IOException
public abstract boolean isClosed()
public final void write(boolean block, byte[] buf, int off, int len) throws java.io.IOException
block
- true
if a blocking write should be used,
otherwise a non-blocking write will be usedbuf
- The byte array containing the data to be writtenoff
- The offset within the byte array of the data to be writtenlen
- The length of the data to be writtenjava.io.IOException
- If an IO error occurs during the writepublic final void write(boolean block, java.nio.ByteBuffer from) throws java.io.IOException
block
- true
if a blocking write should be used,
otherwise a non-blocking write will be usedfrom
- The ByteBuffer containing the data to be writtenjava.io.IOException
- If an IO error occurs during the writeprotected void writeBlocking(byte[] buf, int off, int len) throws java.io.IOException
buf
- The byte array containing the data to be writtenoff
- The offset within the byte array of the data to be writtenlen
- The length of the data to be writtenjava.io.IOException
- If an IO error occurs during the writeprotected void writeBlocking(java.nio.ByteBuffer from) throws java.io.IOException
from
- The ByteBuffer containing the data to be writtenjava.io.IOException
- If an IO error occurs during the writeprotected void writeByteBufferBlocking(java.nio.ByteBuffer from) throws java.io.IOException
java.io.IOException
protected void writeNonBlocking(byte[] buf, int off, int len) throws java.io.IOException
buf
- The byte array containing the data to be writtenoff
- The offset within the byte array of the data to be writtenlen
- The length of the data to be writtenjava.io.IOException
- If an IO error occurs during the writeprotected void writeNonBlocking(java.nio.ByteBuffer from) throws java.io.IOException
from
- The ByteBuffer containing the data to be writtenjava.io.IOException
- If an IO error occurs during the writeprotected boolean writeByteBufferNonBlocking(java.nio.ByteBuffer from) throws java.io.IOException
java.io.IOException
public boolean flush(boolean block) throws java.io.IOException
block
- true
if a blocking write should be used,
otherwise a non-blocking write will be usedtrue
if data remains to be flushed after this method
completes, otherwise false
. In blocking mode
therefore, the return value should always be false
java.io.IOException
- If an IO error occurs during the writeprotected void flushBlocking() throws java.io.IOException
java.io.IOException
protected boolean flushNonBlocking() throws java.io.IOException
java.io.IOException
protected void doWrite(boolean block) throws java.io.IOException
block
- Should the write be blocking or not?java.io.IOException
- If an I/O error such as a timeout occurs during the
writeprotected abstract void doWrite(boolean block, java.nio.ByteBuffer from) throws java.io.IOException
block
- Should the write be blocking or not?from
- the ByteBuffer containing the data to be writtenjava.io.IOException
- If an I/O error such as a timeout occurs during the
writeprotected void addToBuffers(byte[] buf, int offset, int length)
protected void addToBuffers(java.nio.ByteBuffer from)
public void processSocket(SocketEvent socketStatus, boolean dispatch)
public abstract void registerReadInterest()
public abstract void registerWriteInterest()
public abstract SendfileDataBase createSendfileData(java.lang.String filename, long pos, long length)
public abstract SendfileState processSendfile(SendfileDataBase sendfileData)
sendfileData
- Data representing the file to sendpublic abstract void doClientAuth(SSLSupport sslSupport) throws java.io.IOException
sslSupport
- The SSL/TLS support instance currently being used by
the connection that may need updating after the client
authenticationjava.io.IOException
- If authentication is required then there will be I/O
with the client and this exception will be thrown if
that goes wrongpublic abstract SSLSupport getSslSupport(java.lang.String clientCertProvider)
public boolean hasAsyncIO()
false
public boolean isReadPending()
true
if the endpoint supports asynchronous IO and
a read operation is being processed asynchronouslypublic boolean isWritePending()
true
if the endpoint supports asynchronous IO and
a write operation is being processed asynchronouslypublic boolean awaitReadComplete(long timeout, java.util.concurrent.TimeUnit unit)
timeout
- The maximum amount of time to waitunit
- The unit for the timeouttrue
if the read operation is complete,
false
if the operation is still pending and
the specified timeout has passedpublic boolean awaitWriteComplete(long timeout, java.util.concurrent.TimeUnit unit)
timeout
- The maximum amount of time to waitunit
- The unit for the timeouttrue
if the read operation is complete,
false
if the operation is still pending and
the specified timeout has passedpublic final <A> SocketWrapperBase.CompletionState read(SocketWrapperBase.BlockingMode block, long timeout, java.util.concurrent.TimeUnit unit, A attachment, SocketWrapperBase.CompletionCheck check, java.nio.channels.CompletionHandler<java.lang.Long,? super A> handler, java.nio.ByteBuffer... dsts)
A
- The attachment typeblock
- is the blocking mode that will be used for this operationtimeout
- timeout duration for the readunit
- units for the timeout durationattachment
- an object to attach to the I/O operation that will be
used when calling the completion handlercheck
- for the IO operation completionhandler
- to call when the IO is completedsts
- bufferspublic <A> SocketWrapperBase.CompletionState read(java.nio.ByteBuffer[] dsts, int offset, int length, SocketWrapperBase.BlockingMode block, long timeout, java.util.concurrent.TimeUnit unit, A attachment, SocketWrapperBase.CompletionCheck check, java.nio.channels.CompletionHandler<java.lang.Long,? super A> handler)
A
- The attachment typedsts
- buffersoffset
- in the buffer arraylength
- in the buffer arrayblock
- is the blocking mode that will be used for this operationtimeout
- timeout duration for the readunit
- units for the timeout durationattachment
- an object to attach to the I/O operation that will be
used when calling the completion handlercheck
- for the IO operation completionhandler
- to call when the IO is completepublic final <A> SocketWrapperBase.CompletionState write(SocketWrapperBase.BlockingMode block, long timeout, java.util.concurrent.TimeUnit unit, A attachment, SocketWrapperBase.CompletionCheck check, java.nio.channels.CompletionHandler<java.lang.Long,? super A> handler, java.nio.ByteBuffer... srcs)
A
- The attachment typeblock
- is the blocking mode that will be used for this operationtimeout
- timeout duration for the writeunit
- units for the timeout durationattachment
- an object to attach to the I/O operation that will be
used when calling the completion handlercheck
- for the IO operation completionhandler
- to call when the IO is completesrcs
- bufferspublic <A> SocketWrapperBase.CompletionState write(java.nio.ByteBuffer[] srcs, int offset, int length, SocketWrapperBase.BlockingMode block, long timeout, java.util.concurrent.TimeUnit unit, A attachment, SocketWrapperBase.CompletionCheck check, java.nio.channels.CompletionHandler<java.lang.Long,? super A> handler)
A
- The attachment typesrcs
- buffersoffset
- in the buffer arraylength
- in the buffer arrayblock
- is the blocking mode that will be used for this operationtimeout
- timeout duration for the writeunit
- units for the timeout durationattachment
- an object to attach to the I/O operation that will be
used when calling the completion handlercheck
- for the IO operation completionhandler
- to call when the IO is completeprotected static int transfer(byte[] from, int offset, int length, java.nio.ByteBuffer to)
protected static int transfer(java.nio.ByteBuffer from, java.nio.ByteBuffer to)
Copyright © 2000-1970 Apache Software Foundation. All Rights Reserved.