use of org.webpieces.httpclient.api.HttpResponseListener in project webpieces by deanhiller.
the class HttpSocketImpl method actuallySendRequest.
private void actuallySendRequest(CompletableFuture<HttpChunkWriter> future, HttpRequest request, HttpResponseListener listener) {
HttpResponseListener l = new CatchResponseListener(listener);
ByteBuffer wrap = parser.marshalToByteBuffer(state, request);
//put this on the queue before the write to be completed from the listener below
responsesToComplete.offer(l);
log.info("sending request now. req=" + request.getRequestLine().getUri());
CompletableFuture<Channel> write = channel.write(wrap);
write.handle((c, t) -> chainToFuture(c, t, future));
}
use of org.webpieces.httpclient.api.HttpResponseListener in project webpieces by deanhiller.
the class HttpSocketImpl method cleanUpPendings.
private void cleanUpPendings(String msg) {
//do we need an isClosing state and cache that future? (I don't think so but time will tell)
while (!responsesToComplete.isEmpty()) {
HttpResponseListener listener = responsesToComplete.poll();
if (listener != null) {
listener.failure(new NioClosedChannelException(msg + " before responses were received"));
}
}
synchronized (this) {
while (!pendingRequests.isEmpty()) {
PendingRequest pending = pendingRequests.poll();
pending.getListener().failure(new NioClosedChannelException(msg + " before requests were sent"));
}
}
}
use of org.webpieces.httpclient.api.HttpResponseListener in project webpieces by deanhiller.
the class HttpSocketImpl method send.
@Override
public CompletableFuture<HttpResponse> send(HttpRequest request) {
CompletableFuture<HttpResponse> future = new CompletableFuture<HttpResponse>();
HttpResponseListener l = new CompletableListener(future);
send(request, l);
return future;
}
Aggregations