com.sun.jersey.api.client.TenacityAsyncWebResource Maven / Gradle / Ivy
package com.sun.jersey.api.client;
import com.google.common.primitives.Ints;
import com.sun.jersey.api.client.async.ITypeListener;
import com.sun.jersey.api.client.config.ClientConfig;
import com.sun.jersey.client.impl.CopyOnWriteHashMap;
import com.yammer.tenacity.core.TenacityCommand;
import com.yammer.tenacity.core.properties.TenacityPropertyKey;
import io.dropwizard.util.Duration;
import javax.ws.rs.core.UriBuilder;
import java.net.URI;
import java.util.Objects;
import java.util.concurrent.Future;
public class TenacityAsyncWebResource extends AsyncWebResource {
protected final TenacityPropertyKey tenacityPropertyKey;
protected final Duration timeoutPadding;
public TenacityAsyncWebResource(Client c,
CopyOnWriteHashMap properties,
URI u,
TenacityPropertyKey tenacityPropertyKey,
Duration timeoutPadding) {
super(c, properties, u);
this.tenacityPropertyKey = tenacityPropertyKey;
this.timeoutPadding = timeoutPadding;
}
public TenacityAsyncWebResource(AsyncWebResource that,
UriBuilder ub,
TenacityPropertyKey tenacityPropertyKey,
Duration timeoutPadding) {
super(that, ub);
this.tenacityPropertyKey = tenacityPropertyKey;
this.timeoutPadding = timeoutPadding;
}
@Override
public Future head() {
setReadTimeoutWithTenacity();
return super.head();
}
@Override
public Future head(ITypeListener l) {
setReadTimeoutWithTenacity();
return super.head(l);
}
@Override
public Future options(Class c) {
setReadTimeoutWithTenacity();
return super.options(c);
}
@Override
public Future options(GenericType gt) {
setReadTimeoutWithTenacity();
return super.options(gt);
}
@Override
public Future options(ITypeListener l) {
setReadTimeoutWithTenacity();
return super.options(l);
}
@Override
public Future get(Class c) throws UniformInterfaceException {
setReadTimeoutWithTenacity();
return super.get(c);
}
@Override
public Future get(GenericType gt) throws UniformInterfaceException {
setReadTimeoutWithTenacity();
return super.get(gt);
}
@Override
public Future get(ITypeListener l) {
setReadTimeoutWithTenacity();
return super.get(l);
}
@Override
public Future> put() throws UniformInterfaceException {
setReadTimeoutWithTenacity();
return super.put();
}
@Override
public Future> put(Object requestEntity) throws UniformInterfaceException {
setReadTimeoutWithTenacity();
return super.put(requestEntity);
}
@Override
public Future put(Class c) throws UniformInterfaceException {
setReadTimeoutWithTenacity();
return super.put(c);
}
@Override
public Future put(GenericType gt) throws UniformInterfaceException {
setReadTimeoutWithTenacity();
return super.put(gt);
}
@Override
public Future put(ITypeListener l) {
setReadTimeoutWithTenacity();
return super.put(l);
}
@Override
public Future put(Class c, Object requestEntity) throws UniformInterfaceException {
setReadTimeoutWithTenacity();
return super.put(c, requestEntity);
}
@Override
public Future put(GenericType gt, Object requestEntity) throws UniformInterfaceException {
setReadTimeoutWithTenacity();
return super.put(gt, requestEntity);
}
@Override
public Future put(ITypeListener l, Object requestEntity) {
setReadTimeoutWithTenacity();
return super.put(l, requestEntity);
}
@Override
public Future> post() throws UniformInterfaceException {
setReadTimeoutWithTenacity();
return super.post();
}
@Override
public Future> post(Object requestEntity) throws UniformInterfaceException {
setReadTimeoutWithTenacity();
return super.post(requestEntity);
}
@Override
public Future post(Class c) throws UniformInterfaceException {
setReadTimeoutWithTenacity();
return super.post(c);
}
@Override
public Future post(GenericType gt) throws UniformInterfaceException {
setReadTimeoutWithTenacity();
return super.post(gt);
}
@Override
public Future post(ITypeListener l) {
setReadTimeoutWithTenacity();
return super.post(l);
}
@Override
public Future post(Class c, Object requestEntity) throws UniformInterfaceException {
setReadTimeoutWithTenacity();
return super.post(c, requestEntity);
}
@Override
public Future post(GenericType gt, Object requestEntity) throws UniformInterfaceException {
setReadTimeoutWithTenacity();
return super.post(gt, requestEntity);
}
@Override
public Future post(ITypeListener l, Object requestEntity) {
setReadTimeoutWithTenacity();
return super.post(l, requestEntity);
}
@Override
public Future> delete() throws UniformInterfaceException {
setReadTimeoutWithTenacity();
return super.delete();
}
@Override
public Future> delete(Object requestEntity) throws UniformInterfaceException {
setReadTimeoutWithTenacity();
return super.delete(requestEntity);
}
@Override
public Future delete(Class c) throws UniformInterfaceException {
setReadTimeoutWithTenacity();
return super.delete(c);
}
@Override
public Future delete(GenericType gt) throws UniformInterfaceException {
setReadTimeoutWithTenacity();
return super.delete(gt);
}
@Override
public Future delete(ITypeListener l) {
setReadTimeoutWithTenacity();
return super.delete(l);
}
@Override
public Future delete(Class c, Object requestEntity) throws UniformInterfaceException {
setReadTimeoutWithTenacity();
return super.delete(c, requestEntity);
}
@Override
public Future delete(GenericType gt, Object requestEntity) throws UniformInterfaceException {
setReadTimeoutWithTenacity();
return super.delete(gt, requestEntity);
}
@Override
public Future delete(ITypeListener l, Object requestEntity) {
setReadTimeoutWithTenacity();
return super.delete(l, requestEntity);
}
@Override
public Future> method(String method) throws UniformInterfaceException {
setReadTimeoutWithTenacity();
return super.method(method);
}
@Override
public Future> method(String method, Object requestEntity) throws UniformInterfaceException {
setReadTimeoutWithTenacity();
return super.method(method, requestEntity);
}
@Override
public Future method(String method, Class c) throws UniformInterfaceException {
setReadTimeoutWithTenacity();
return super.method(method, c);
}
@Override
public Future method(String method, GenericType gt) throws UniformInterfaceException {
setReadTimeoutWithTenacity();
return super.method(method, gt);
}
@Override
public Future method(String method, ITypeListener l) {
setReadTimeoutWithTenacity();
return super.method(method, l);
}
@Override
public Future method(String method, Class c, Object requestEntity) throws UniformInterfaceException {
setReadTimeoutWithTenacity();
return super.method(method, c, requestEntity);
}
@Override
public Future method(String method, GenericType gt, Object requestEntity) throws UniformInterfaceException {
setReadTimeoutWithTenacity();
return super.method(method, gt, requestEntity);
}
@Override
public Future method(String method, ITypeListener l, Object requestEntity) {
setReadTimeoutWithTenacity();
return super.method(method, l, requestEntity);
}
@Override
public UriBuilder getUriBuilder() {
setReadTimeoutWithTenacity();
return super.getUriBuilder();
}
@Override
public Builder getRequestBuilder() {
setReadTimeoutWithTenacity();
return super.getRequestBuilder();
}
@Override
public int hashCode() {
return 31 * super.hashCode() + Objects.hash(tenacityPropertyKey, timeoutPadding);
}
@Override
public boolean equals(Object obj) {
if (this == obj) {
return true;
}
if (obj == null || getClass() != obj.getClass()) {
return false;
}
if (!super.equals(obj)) {
return false;
}
final TenacityAsyncWebResource other = (TenacityAsyncWebResource) obj;
return Objects.equals(this.tenacityPropertyKey, other.tenacityPropertyKey)
&& Objects.equals(this.timeoutPadding, other.timeoutPadding);
}
protected void setReadTimeoutWithTenacity() {
setProperty(ClientConfig.PROPERTY_READ_TIMEOUT, Ints.checkedCast(TenacityCommand
.getCommandProperties(tenacityPropertyKey)
.executionTimeoutInMilliseconds()
.get() + timeoutPadding.toMilliseconds()));
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy