Remove last resolver-specific data from RequestResponse

This commit is contained in:
Travis Burtrum 2019-04-14 01:02:18 -04:00
parent fa9e2b3048
commit 62dac26b00
3 changed files with 4 additions and 25 deletions

View File

@ -11,8 +11,6 @@ public class BaseRequestResponse implements RequestResponse {
private Packet request, response; private Packet request, response;
private String requestPacketKey;
public BaseRequestResponse() { public BaseRequestResponse() {
} }
@ -39,22 +37,11 @@ public class BaseRequestResponse implements RequestResponse {
this.response = response; this.response = response;
} }
@Override
public String getRequestPacketKey() {
return requestPacketKey;
}
@Override
public void setRequestPacketKey(final String requestPacketKey) {
this.requestPacketKey = requestPacketKey;
}
@Override @Override
public String toString() { public String toString() {
return "BaseRequestResponse{" + return "BaseRequestResponse{" +
"request=" + request + "request=" + request +
", response=" + response + ", response=" + response +
", requestPacketKey=" + requestPacketKey +
'}'; '}';
} }
} }

View File

@ -99,8 +99,7 @@ public class CacheResolver extends WrappingResolver {
final long currentTime = currentTimeSeconds(); final long currentTime = currentTimeSeconds();
if (response.isExpired(currentTime)) { if (response.isExpired(currentTime)) {
//System.out.println("cachedPacket isExpired!"); //System.out.println("cachedPacket isExpired!");
requestResponse.setRequestPacketKey(key); final CompletableFuture<E> request = requestAndCache(key, requestResponse, executor);
final CompletableFuture<E> request = requestAndCache(requestResponse, executor);
final CompletableFuture<E> stale = supplyAsyncOnTimeOut(scheduledExecutorService, staleResponseTimeout, TimeUnit.MILLISECONDS, () -> { final CompletableFuture<E> stale = supplyAsyncOnTimeOut(scheduledExecutorService, staleResponseTimeout, TimeUnit.MILLISECONDS, () -> {
requestResponse.setResponse(response.getStaleResponse().setId(requestResponse.getRequest().getId())); requestResponse.setResponse(response.getStaleResponse().setId(requestResponse.getRequest().getId()));
return requestResponse; return requestResponse;
@ -113,8 +112,7 @@ public class CacheResolver extends WrappingResolver {
} }
} }
//System.out.println("no cachedPacket, querying upstream!"); //System.out.println("no cachedPacket, querying upstream!");
requestResponse.setRequestPacketKey(key); return requestAndCache(key, requestResponse, executor);
return requestAndCache(requestResponse, executor);
/* /*
// todo: should not have to do this, some upstreams seem to eat stuff though, figure that out, I think readTimeout fixed this // todo: should not have to do this, some upstreams seem to eat stuff though, figure that out, I think readTimeout fixed this
final CompletableFuture<E> request = requestAndCache(requestResponse); final CompletableFuture<E> request = requestAndCache(requestResponse);
@ -125,12 +123,12 @@ public class CacheResolver extends WrappingResolver {
*/ */
} }
private <E extends RequestResponse> CompletableFuture<E> requestAndCache(final E requestResponse, final Executor executor) { private <E extends RequestResponse> CompletableFuture<E> requestAndCache(final String key, final E requestResponse, final Executor executor) {
final CompletableFuture<E> request = delegate.resolveAsync(requestResponse, executor); final CompletableFuture<E> request = delegate.resolveAsync(requestResponse, executor);
request.thenAcceptAsync(s -> { request.thenAcceptAsync(s -> {
final Packet response = s.getResponse().copy(); // todo: do we need to copy? final Packet response = s.getResponse().copy(); // todo: do we need to copy?
final long currentTime = currentTimeSeconds(); final long currentTime = currentTimeSeconds();
cache.put(s.getRequestPacketKey(), new CachedPacket(response, currentTime, currentTime + response.getLowestTtl())); cache.put(key, new CachedPacket(response, currentTime, currentTime + response.getLowestTtl()));
}, executor); }, executor);
return request; return request;
} }

View File

@ -8,10 +8,4 @@ public interface RequestResponse {
Packet getRequest(); Packet getRequest();
Packet getResponse(); Packet getResponse();
void setResponse(Packet response); void setResponse(Packet response);
/**
* These should only be used by resolvers, may be null
*/
String getRequestPacketKey();
void setRequestPacketKey(String key);
} }