All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.signalfx.connection.RetryStrategy Maven / Gradle / Ivy

package com.signalfx.connection;

import com.signalfx.shaded.apache.http.HttpResponse;
import com.signalfx.shaded.apache.http.HttpStatus;
import com.signalfx.shaded.apache.http.client.ServiceUnavailableRetryStrategy;
import com.signalfx.shaded.apache.http.protocol.HttpContext;

public class RetryStrategy implements ServiceUnavailableRetryStrategy {
    private final int maxRetries;

    public RetryStrategy(final int maxRetries) {
        this.maxRetries = maxRetries;
    }

    @Override
    public boolean retryRequest(final HttpResponse httpResponse, final int executionCount, final HttpContext httpContext) {
        final int statusCode = httpResponse.getStatusLine().getStatusCode();
        return executionCount <= maxRetries && (statusCode == HttpStatus.SC_REQUEST_TIMEOUT || statusCode == HttpStatus.SC_GATEWAY_TIMEOUT || statusCode == 598 || statusCode == -1);
    }

    @Override
    public long getRetryInterval() {
        return 0;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy