1 /** 2 * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. 3 * SPDX-License-Identifier: Apache-2.0. 4 */ 5 package software.amazon.awssdk.crt.http; 6 7 /** 8 * This class provides access to basic http connection monitoring controls in lieu of the more traditional 9 * timeouts. 10 * 11 * The user can set a throughput threshold (in bytes per second) for the a connection to be considered healthy. If 12 * the connection falls below this threshold for a configurable amount of time, then the connection is considered 13 * unhealthy and shut down. Throughput/health is only measured when the connection has work (read or write) that 14 * needs to be done. 15 */ 16 public class HttpMonitoringOptions { 17 18 /** 19 * minimum amount of throughput, in bytes per second, for a connection to be considered healthy. 20 */ 21 private long minThroughputBytesPerSecond; 22 23 /** 24 * How long, in seconds, a connection is allowed to be unhealthy before getting shut down. Must be at least 25 * two. 26 */ 27 private int allowableThroughputFailureIntervalSeconds; 28 29 /** 30 * Creates a new set of monitoring options 31 */ HttpMonitoringOptions()32 public HttpMonitoringOptions() { 33 } 34 35 /** 36 * Sets a throughput threshold for connections. Throughput below this value will be considered unhealthy. 37 * @param minThroughputBytesPerSecond minimum amount of throughput, in bytes per second, for a connection to be 38 * considered healthy. 39 */ setMinThroughputBytesPerSecond(long minThroughputBytesPerSecond)40 public void setMinThroughputBytesPerSecond(long minThroughputBytesPerSecond) { 41 if (minThroughputBytesPerSecond < 0) { 42 throw new IllegalArgumentException("Http monitoring minimum throughput must be non-negative"); 43 } 44 this.minThroughputBytesPerSecond = minThroughputBytesPerSecond; 45 } 46 47 /** 48 * @return minimum amount of throughput, in bytes per second, for a connection to be considered healthy. 49 */ getMinThroughputBytesPerSecond()50 public long getMinThroughputBytesPerSecond() { return minThroughputBytesPerSecond; } 51 52 /** 53 * Sets how long, in seconds, a connection is allowed to be unhealthy before getting shut down. Must be at 54 * least two. 55 * @param allowableThroughputFailureIntervalSeconds How long, in seconds, a connection is allowed to be unhealthy 56 * before getting shut down. 57 */ setAllowableThroughputFailureIntervalSeconds(int allowableThroughputFailureIntervalSeconds)58 public void setAllowableThroughputFailureIntervalSeconds(int allowableThroughputFailureIntervalSeconds) { 59 if (allowableThroughputFailureIntervalSeconds < 2) { 60 throw new IllegalArgumentException("Http monitoring failure interval must be at least two"); 61 } 62 this.allowableThroughputFailureIntervalSeconds = allowableThroughputFailureIntervalSeconds; 63 } 64 65 /** 66 * @return How long, in seconds, a connection is allowed to be unhealthy before getting shut down. Must be at 67 * least two. 68 */ getAllowableThroughputFailureIntervalSeconds()69 public int getAllowableThroughputFailureIntervalSeconds() { return allowableThroughputFailureIntervalSeconds; } 70 71 72 } 73