Package org.apache.hc.core5.http.impl.io
Class MonitoringResponseOutOfOrderStrategy
- java.lang.Object
-
- org.apache.hc.core5.http.impl.io.MonitoringResponseOutOfOrderStrategy
-
- All Implemented Interfaces:
ResponseOutOfOrderStrategy
@Contract(threading=IMMUTABLE) public final class MonitoringResponseOutOfOrderStrategy extends java.lang.Object implements ResponseOutOfOrderStrategy
AResponseOutOfOrderStrategy
implementation which checks for premature responses everychunkSize
bytes. An 8 KiB chunk size is used by default based on testing using values between 4 KiB and 128 KiB. This is optimized for correctness and results in a maximum upload speed of 8 MiB/s untilmaxChunksToCheck
is reached.- Since:
- 5.1
-
-
Field Summary
Fields Modifier and Type Field Description private long
chunkSize
private static int
DEFAULT_CHUNK_SIZE
static MonitoringResponseOutOfOrderStrategy
INSTANCE
private long
maxChunksToCheck
-
Constructor Summary
Constructors Constructor Description MonitoringResponseOutOfOrderStrategy()
Instantiates a defaultMonitoringResponseOutOfOrderStrategy
.MonitoringResponseOutOfOrderStrategy(long chunkSize)
Instantiates aMonitoringResponseOutOfOrderStrategy
with unlimitedmaxChunksToCheck
.MonitoringResponseOutOfOrderStrategy(long chunkSize, long maxChunksToCheck)
Instantiates aMonitoringResponseOutOfOrderStrategy
.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
isEarlyResponseDetected(ClassicHttpRequest request, HttpClientConnection connection, java.io.InputStream inputStream, long totalBytesSent, long nextWriteSize)
Called before each write to the to a socketOutputStream
with the number of bytes that have already been sent, and the size of the write that will occur if this check does not encounter an out of order response.private boolean
nextWriteStartsNewChunk(long totalBytesSent, long nextWriteSize)
java.lang.String
toString()
-
-
-
Field Detail
-
DEFAULT_CHUNK_SIZE
private static final int DEFAULT_CHUNK_SIZE
- See Also:
- Constant Field Values
-
INSTANCE
public static final MonitoringResponseOutOfOrderStrategy INSTANCE
-
chunkSize
private final long chunkSize
-
maxChunksToCheck
private final long maxChunksToCheck
-
-
Constructor Detail
-
MonitoringResponseOutOfOrderStrategy
public MonitoringResponseOutOfOrderStrategy()
Instantiates a defaultMonitoringResponseOutOfOrderStrategy
.INSTANCE
may be used instead.
-
MonitoringResponseOutOfOrderStrategy
public MonitoringResponseOutOfOrderStrategy(long chunkSize)
Instantiates aMonitoringResponseOutOfOrderStrategy
with unlimitedmaxChunksToCheck
.- Parameters:
chunkSize
- The chunk size after which a response check is executed.
-
MonitoringResponseOutOfOrderStrategy
public MonitoringResponseOutOfOrderStrategy(long chunkSize, long maxChunksToCheck)
Instantiates aMonitoringResponseOutOfOrderStrategy
.- Parameters:
chunkSize
- The chunk size after which a response check is executed.maxChunksToCheck
- The maximum number of chunks to check, allowing expensive checks to be avoided after a sufficient portion of the request entity has been transferred.
-
-
Method Detail
-
isEarlyResponseDetected
public boolean isEarlyResponseDetected(ClassicHttpRequest request, HttpClientConnection connection, java.io.InputStream inputStream, long totalBytesSent, long nextWriteSize) throws java.io.IOException
Description copied from interface:ResponseOutOfOrderStrategy
Called before each write to the to a socketOutputStream
with the number of bytes that have already been sent, and the size of the write that will occur if this check does not encounter an out of order response.- Specified by:
isEarlyResponseDetected
in interfaceResponseOutOfOrderStrategy
- Parameters:
request
- The current request.connection
- The connection used to send the current request.inputStream
- The response stream, this may be used to check for an early response.totalBytesSent
- Number of bytes that have already been sent.nextWriteSize
- The size of a socket write operation that will follow this check.- Returns:
- True if an early response was detected, otherwise false.
- Throws:
java.io.IOException
- in case of a network failure while checking for an early response.
-
nextWriteStartsNewChunk
private boolean nextWriteStartsNewChunk(long totalBytesSent, long nextWriteSize)
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
-