Search in sources :

Example 1 with Http2Stream

use of org.glassfish.grizzly.http2.Http2Stream in project grpc-java by grpc.

the class NettyServerHandler method channelInactive.

/**
   * Handler for the Channel shutting down.
   */
@Override
public void channelInactive(ChannelHandlerContext ctx) throws Exception {
    try {
        final Status status = Status.UNAVAILABLE.withDescription("connection terminated for unknown reason");
        // Any streams that are still active must be closed
        connection().forEachActiveStream(new Http2StreamVisitor() {

            @Override
            public boolean visit(Http2Stream stream) throws Http2Exception {
                NettyServerStream.TransportState serverStream = serverStream(stream);
                if (serverStream != null) {
                    serverStream.transportReportStatus(status);
                }
                return true;
            }
        });
    } finally {
        super.channelInactive(ctx);
    }
}
Also used : Status(io.grpc.Status) Http2Exception(io.netty.handler.codec.http2.Http2Exception) Http2StreamVisitor(io.netty.handler.codec.http2.Http2StreamVisitor) Http2Stream(io.netty.handler.codec.http2.Http2Stream)

Example 2 with Http2Stream

use of org.glassfish.grizzly.http2.Http2Stream in project grpc-java by grpc.

the class NettyServerHandler method sendResponseHeaders.

/**
   * Sends the response headers to the client.
   */
private void sendResponseHeaders(ChannelHandlerContext ctx, SendResponseHeadersCommand cmd, ChannelPromise promise) throws Http2Exception {
    // TODO(carl-mastrangelo): remove this check once https://github.com/netty/netty/issues/6296 is
    // fixed.
    int streamId = cmd.stream().id();
    Http2Stream stream = connection().stream(streamId);
    if (stream == null) {
        resetStream(ctx, streamId, Http2Error.CANCEL.code(), promise);
        return;
    }
    if (cmd.endOfStream()) {
        closeStreamWhenDone(promise, streamId);
    }
    encoder().writeHeaders(ctx, streamId, cmd.headers(), 0, cmd.endOfStream(), promise);
}
Also used : Http2Stream(io.netty.handler.codec.http2.Http2Stream)

Example 3 with Http2Stream

use of org.glassfish.grizzly.http2.Http2Stream in project grpc-java by grpc.

the class NettyServerHandler method onHeadersRead.

private void onHeadersRead(ChannelHandlerContext ctx, int streamId, Http2Headers headers) throws Http2Exception {
    if (!teWarningLogged && !TE_TRAILERS.equals(headers.get(TE_HEADER))) {
        logger.warning(String.format("Expected header TE: %s, but %s is received. This means " + "some intermediate proxy may not support trailers", TE_TRAILERS, headers.get(TE_HEADER)));
        teWarningLogged = true;
    }
    try {
        // Verify that the Content-Type is correct in the request.
        verifyContentType(streamId, headers);
        String method = determineMethod(streamId, headers);
        // The Http2Stream object was put by AbstractHttp2ConnectionHandler before calling this
        // method.
        Http2Stream http2Stream = requireHttp2Stream(streamId);
        Metadata metadata = Utils.convertHeaders(headers);
        StatsTraceContext statsTraceCtx = checkNotNull(transportListener.methodDetermined(method, metadata), "statsTraceCtx");
        NettyServerStream.TransportState state = new NettyServerStream.TransportState(this, http2Stream, maxMessageSize, statsTraceCtx);
        String authority = getOrUpdateAuthority((AsciiString) headers.authority());
        NettyServerStream stream = new NettyServerStream(ctx.channel(), state, attributes, authority, statsTraceCtx);
        transportListener.streamCreated(stream, method, metadata);
        state.onStreamAllocated();
        http2Stream.setProperty(streamKey, state);
    } catch (Http2Exception e) {
        throw e;
    } catch (Throwable e) {
        logger.log(Level.WARNING, "Exception in onHeadersRead()", e);
        // Throw an exception that will get handled by onStreamError.
        throw newStreamException(streamId, e);
    }
}
Also used : Http2Exception(io.netty.handler.codec.http2.Http2Exception) StatsTraceContext(io.grpc.internal.StatsTraceContext) Metadata(io.grpc.Metadata) AsciiString(io.netty.util.AsciiString) Http2Stream(io.netty.handler.codec.http2.Http2Stream)

Example 4 with Http2Stream

use of org.glassfish.grizzly.http2.Http2Stream in project grpc-java by grpc.

the class AbstractNettyHandler method sendInitialConnectionWindow.

/**
   * Sends initial connection window to the remote endpoint if necessary.
   */
private void sendInitialConnectionWindow() throws Http2Exception {
    if (ctx.channel().isActive() && initialConnectionWindow > 0) {
        Http2Stream connectionStream = connection().connectionStream();
        int currentSize = connection().local().flowController().windowSize(connectionStream);
        int delta = initialConnectionWindow - currentSize;
        decoder().flowController().incrementWindowSize(connectionStream, delta);
        initialConnectionWindow = -1;
        ctx.flush();
    }
}
Also used : Http2Stream(io.netty.handler.codec.http2.Http2Stream)

Example 5 with Http2Stream

use of org.glassfish.grizzly.http2.Http2Stream in project grpc-java by grpc.

the class NettyClientHandler method forcefulClose.

private void forcefulClose(final ChannelHandlerContext ctx, final ForcefulCloseCommand msg, ChannelPromise promise) throws Exception {
    lifecycleManager.notifyShutdown(Status.UNAVAILABLE.withDescription("Channel requested transport to shut down"));
    close(ctx, promise);
    connection().forEachActiveStream(new Http2StreamVisitor() {

        @Override
        public boolean visit(Http2Stream stream) throws Http2Exception {
            NettyClientStream.TransportState clientStream = clientStream(stream);
            if (clientStream != null) {
                clientStream.transportReportStatus(msg.getStatus(), true, new Metadata());
                resetStream(ctx, stream.id(), Http2Error.CANCEL.code(), ctx.newPromise());
            }
            stream.close();
            return true;
        }
    });
}
Also used : Http2Exception(io.netty.handler.codec.http2.Http2Exception) Http2StreamVisitor(io.netty.handler.codec.http2.Http2StreamVisitor) Metadata(io.grpc.Metadata) Http2Stream(io.netty.handler.codec.http2.Http2Stream)

Aggregations

Http2Stream (io.netty.handler.codec.http2.Http2Stream)21 Http2Exception (io.netty.handler.codec.http2.Http2Exception)8 Test (org.junit.Test)8 Http2StreamVisitor (io.netty.handler.codec.http2.Http2StreamVisitor)5 Metadata (io.grpc.Metadata)4 Http2LocalFlowController (io.netty.handler.codec.http2.Http2LocalFlowController)4 CountDownLatch (java.util.concurrent.CountDownLatch)4 HttpFields (org.eclipse.jetty.http.HttpFields)4 HTTP2Session (org.eclipse.jetty.http2.HTTP2Session)4 HTTP2Stream (org.eclipse.jetty.http2.HTTP2Stream)4 Session (org.eclipse.jetty.http2.api.Session)4 Stream (org.eclipse.jetty.http2.api.Stream)4 ServerSessionListener (org.eclipse.jetty.http2.api.server.ServerSessionListener)4 HeadersFrame (org.eclipse.jetty.http2.frames.HeadersFrame)4 FuturePromise (org.eclipse.jetty.util.FuturePromise)4 Status (io.grpc.Status)2 ByteBuf (io.netty.buffer.ByteBuf)2 CompositeByteBuf (io.netty.buffer.CompositeByteBuf)2 ChannelFuture (io.netty.channel.ChannelFuture)2 DefaultHttp2Connection (io.netty.handler.codec.http2.DefaultHttp2Connection)2