Search in sources :

Example 1 with HttpResponseListener

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));
}
Also used : Channel(org.webpieces.nio.api.channels.Channel) TCPChannel(org.webpieces.nio.api.channels.TCPChannel) ByteBuffer(java.nio.ByteBuffer) HttpResponseListener(org.webpieces.httpclient.api.HttpResponseListener)

Example 2 with HttpResponseListener

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"));
        }
    }
}
Also used : NioClosedChannelException(org.webpieces.nio.api.exceptions.NioClosedChannelException) HttpResponseListener(org.webpieces.httpclient.api.HttpResponseListener)

Example 3 with HttpResponseListener

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;
}
Also used : CompletableFuture(java.util.concurrent.CompletableFuture) HttpResponse(org.webpieces.httpparser.api.dto.HttpResponse) HttpResponseListener(org.webpieces.httpclient.api.HttpResponseListener)

Aggregations

HttpResponseListener (org.webpieces.httpclient.api.HttpResponseListener)3 ByteBuffer (java.nio.ByteBuffer)1 CompletableFuture (java.util.concurrent.CompletableFuture)1 HttpResponse (org.webpieces.httpparser.api.dto.HttpResponse)1 Channel (org.webpieces.nio.api.channels.Channel)1 TCPChannel (org.webpieces.nio.api.channels.TCPChannel)1 NioClosedChannelException (org.webpieces.nio.api.exceptions.NioClosedChannelException)1