Search in sources :

Example 11 with Promise

use of org.eclipse.jetty.util.Promise in project jetty.project by eclipse.

the class HttpClientTransportOverFCGI method newConnection.

@Override
public org.eclipse.jetty.io.Connection newConnection(EndPoint endPoint, Map<String, Object> context) throws IOException {
    HttpDestination destination = (HttpDestination) context.get(HTTP_DESTINATION_CONTEXT_KEY);
    @SuppressWarnings("unchecked") Promise<Connection> promise = (Promise<Connection>) context.get(HTTP_CONNECTION_PROMISE_CONTEXT_KEY);
    HttpConnectionOverFCGI connection = newHttpConnection(endPoint, destination, promise);
    if (LOG.isDebugEnabled())
        LOG.debug("Created {}", connection);
    return customize(connection, context);
}
Also used : Promise(org.eclipse.jetty.util.Promise) Connection(org.eclipse.jetty.client.api.Connection) HttpDestination(org.eclipse.jetty.client.HttpDestination)

Example 12 with Promise

use of org.eclipse.jetty.util.Promise in project jetty.project by eclipse.

the class HttpSenderOverHTTP2 method sendHeaders.

@Override
protected void sendHeaders(HttpExchange exchange, final HttpContent content, final Callback callback) {
    Request request = exchange.getRequest();
    String path = relativize(request.getPath());
    HttpURI uri = new HttpURI(request.getScheme(), request.getHost(), request.getPort(), path, null, request.getQuery(), null);
    MetaData.Request metaData = new MetaData.Request(request.getMethod(), uri, HttpVersion.HTTP_2, request.getHeaders());
    HeadersFrame headersFrame = new HeadersFrame(metaData, null, !content.hasContent());
    HttpChannelOverHTTP2 channel = getHttpChannel();
    Promise<Stream> promise = new Promise<Stream>() {

        @Override
        public void succeeded(Stream stream) {
            getHttpChannel().setStream(stream);
            stream.setIdleTimeout(request.getIdleTimeout());
            if (content.hasContent() && !expects100Continue(request)) {
                boolean advanced = content.advance();
                boolean lastContent = content.isLast();
                if (advanced || lastContent) {
                    DataFrame dataFrame = new DataFrame(stream.getId(), content.getByteBuffer(), lastContent);
                    stream.data(dataFrame, callback);
                    return;
                }
            }
            callback.succeeded();
        }

        @Override
        public void failed(Throwable failure) {
            callback.failed(failure);
        }
    };
    // TODO optimize the send of HEADERS and DATA frames.
    channel.getSession().newStream(headersFrame, promise, channel.getStreamListener());
}
Also used : Request(org.eclipse.jetty.client.api.Request) DataFrame(org.eclipse.jetty.http2.frames.DataFrame) HttpURI(org.eclipse.jetty.http.HttpURI) HeadersFrame(org.eclipse.jetty.http2.frames.HeadersFrame) Promise(org.eclipse.jetty.util.Promise) MetaData(org.eclipse.jetty.http.MetaData) Stream(org.eclipse.jetty.http2.api.Stream)

Aggregations

Promise (org.eclipse.jetty.util.Promise)12 Test (org.junit.Test)8 CountDownLatch (java.util.concurrent.CountDownLatch)6 IOException (java.io.IOException)5 ServletException (javax.servlet.ServletException)5 HttpServletRequest (javax.servlet.http.HttpServletRequest)5 HttpServletResponse (javax.servlet.http.HttpServletResponse)5 Connection (org.eclipse.jetty.client.api.Connection)5 EndPoint (org.eclipse.jetty.io.EndPoint)5 FuturePromise (org.eclipse.jetty.util.FuturePromise)5 InetSocketAddress (java.net.InetSocketAddress)4 TimeUnit (java.util.concurrent.TimeUnit)4 AtomicReference (java.util.concurrent.atomic.AtomicReference)4 HttpClientTransportOverHTTP (org.eclipse.jetty.client.http.HttpClientTransportOverHTTP)4 HttpConnectionOverHTTP (org.eclipse.jetty.client.http.HttpConnectionOverHTTP)4 MetaData (org.eclipse.jetty.http.MetaData)4 Session (org.eclipse.jetty.http2.api.Session)4 Stream (org.eclipse.jetty.http2.api.Stream)4 HeadersFrame (org.eclipse.jetty.http2.frames.HeadersFrame)4 AbstractHandler (org.eclipse.jetty.server.handler.AbstractHandler)4