Example usage for io.netty.handler.codec.http2 Http2Stream id

List of usage examples for io.netty.handler.codec.http2 Http2Stream id

Introduction

In this page you can find the example usage for io.netty.handler.codec.http2 Http2Stream id.

Prototype

int id();

Source Link

Document

Gets the unique identifier for this stream within the connection.

Usage

From source file:com.linecorp.armeria.client.Http2ResponseDecoder.java

License:Apache License

@Override
public void onStreamClosed(Http2Stream stream) {
    final HttpResponseWrapper res = getResponse(streamIdToId(stream.id()), true);
    if (res != null) {
        res.close(ClosedSessionException.get());
    }/*  ww  w.j  a  v a2 s .  c om*/
}

From source file:com.linecorp.armeria.common.http.Http2GoAwayListener.java

License:Apache License

@Override
public void onStreamRemoved(Http2Stream stream) {
    if (stream.id() == 1) {
        logger.debug("{} HTTP/2 upgrade stream removed: {}", ch, stream.state());
    }//from   w  w w  .  ja  v  a2  s.c  o m
}

From source file:com.linecorp.armeria.server.Http2RequestDecoder.java

License:Apache License

@Override
public void onStreamRemoved(Http2Stream stream) {
    final DecodedHttpRequest req = requests.remove(stream.id());
    if (req != null) {
        // Ignored if the stream has already been closed.
        req.close(ClosedSessionException.get());
    }/*from   w  w  w .j a  v a2  s  . co m*/
}

From source file:com.turo.pushy.apns.ApnsClientHandler.java

License:Open Source License

private void handleEndOfStream(final ChannelHandlerContext context, final Http2Stream stream,
        final Http2Headers headers, final ByteBuf data) {

    final PushNotificationPromise<ApnsPushNotification, PushNotificationResponse<ApnsPushNotification>> responsePromise = stream
            .getProperty(this.responsePromisePropertyKey);

    final ApnsPushNotification pushNotification = responsePromise.getPushNotification();

    final HttpResponseStatus status = HttpResponseStatus.parseLine(headers.status());

    if (HttpResponseStatus.OK.equals(status)) {
        responsePromise.trySuccess(new SimplePushNotificationResponse<>(responsePromise.getPushNotification(),
                true, getApnsIdFromHeaders(headers), null, null));
    } else {/*w w w . j  a  v  a2  s .c  o m*/
        if (data != null) {
            final ErrorResponse errorResponse = GSON.fromJson(data.toString(StandardCharsets.UTF_8),
                    ErrorResponse.class);
            this.handleErrorResponse(context, stream.id(), headers, pushNotification, errorResponse);
        } else {
            log.warn("Gateway sent an end-of-stream HEADERS frame for an unsuccessful notification.");
        }
    }
}

From source file:com.turo.pushy.apns.ApnsClientHandler.java

License:Open Source License

@Override
public void onStreamAdded(final Http2Stream stream) {
    stream.setProperty(ApnsClientHandler.this.responsePromisePropertyKey,
            this.unattachedResponsePromisesByStreamId.remove(stream.id()));
}

From source file:com.turo.pushy.apns.server.MockApnsServerHandler.java

License:Open Source License

private void handleEndOfStream(final ChannelHandlerContext context, final Http2Stream stream) {
    final Http2Headers headers = stream.getProperty(this.headersPropertyKey);
    final ByteBuf payload = stream.getProperty(this.payloadPropertyKey);
    final ChannelPromise writePromise = context.newPromise();

    final UUID apnsId;
    {// w ww.j a v  a  2  s .  co  m
        final CharSequence apnsIdSequence = headers.get(APNS_ID_HEADER);

        UUID apnsIdFromHeaders;

        try {
            apnsIdFromHeaders = apnsIdSequence != null ? FastUUID.parseUUID(apnsIdSequence) : UUID.randomUUID();
        } catch (final IllegalArgumentException e) {
            log.error("Failed to parse `apns-id` header: {}", apnsIdSequence, e);
            apnsIdFromHeaders = UUID.randomUUID();
        }

        apnsId = apnsIdFromHeaders;
    }

    try {
        this.pushNotificationHandler.handlePushNotification(headers, payload);

        this.write(context, new AcceptNotificationResponse(stream.id(), apnsId), writePromise);
        this.listener.handlePushNotificationAccepted(headers, payload);
    } catch (final RejectedNotificationException e) {
        final Date deviceTokenExpirationTimestamp = e instanceof UnregisteredDeviceTokenException
                ? ((UnregisteredDeviceTokenException) e).getDeviceTokenExpirationTimestamp()
                : null;

        this.write(context, new RejectNotificationResponse(stream.id(), apnsId, e.getRejectionReason(),
                deviceTokenExpirationTimestamp), writePromise);
        this.listener.handlePushNotificationRejected(headers, payload, e.getRejectionReason(),
                deviceTokenExpirationTimestamp);
    } catch (final Exception e) {
        this.write(context, new RejectNotificationResponse(stream.id(), apnsId,
                RejectionReason.INTERNAL_SERVER_ERROR, null), writePromise);
        this.listener.handlePushNotificationRejected(headers, payload, RejectionReason.INTERNAL_SERVER_ERROR,
                null);
    } finally {
        if (stream.getProperty(this.payloadPropertyKey) != null) {
            ((ByteBuf) stream.getProperty(this.payloadPropertyKey)).release();
        }

        this.flush(context);
    }
}

From source file:io.grpc.netty.NettyClientHandler.java

License:Apache License

private void forcefulClose(final ChannelHandlerContext ctx, final ForcefulCloseCommand msg,
        ChannelPromise promise) throws Exception {
    // close() already called by NettyClientTransport, so just need to clean up streams
    connection().forEachActiveStream(new Http2StreamVisitor() {
        @Override// ww w . j av a  2s  .  c  om
        public boolean visit(Http2Stream stream) throws Http2Exception {
            NettyClientStream.TransportState clientStream = clientStream(stream);
            Tag tag = clientStream != null ? clientStream.tag() : PerfMark.createTag();
            PerfMark.startTask("NettyClientHandler.forcefulClose", tag);
            PerfMark.linkIn(msg.getLink());
            try {
                if (clientStream != null) {
                    clientStream.transportReportStatus(msg.getStatus(), true, new Metadata());
                    resetStream(ctx, stream.id(), Http2Error.CANCEL.code(), ctx.newPromise());
                }
                stream.close();
                return true;
            } finally {
                PerfMark.stopTask("NettyClientHandler.forcefulClose", tag);
            }
        }
    });
    promise.setSuccess();
}

From source file:io.grpc.netty.NettyClientHandler.java

License:Apache License

/**
 * Handler for a GOAWAY being received. Fails any streams created after the
 * last known stream./*from   w ww  . ja  va2 s.c om*/
 */
private void goingAway(Status status) {
    lifecycleManager.notifyShutdown(status);
    final Status goAwayStatus = lifecycleManager.getShutdownStatus();
    final int lastKnownStream = connection().local().lastStreamKnownByPeer();
    try {
        connection().forEachActiveStream(new Http2StreamVisitor() {
            @Override
            public boolean visit(Http2Stream stream) throws Http2Exception {
                if (stream.id() > lastKnownStream) {
                    NettyClientStream.TransportState clientStream = clientStream(stream);
                    if (clientStream != null) {
                        clientStream.transportReportStatus(goAwayStatus, RpcProgress.REFUSED, false,
                                new Metadata());
                    }
                    stream.close();
                }
                return true;
            }
        });
    } catch (Http2Exception e) {
        throw new RuntimeException(e);
    }
}

From source file:io.grpc.netty.NettyServerHandler.java

License:Apache License

private void forcefulClose(final ChannelHandlerContext ctx, final ForcefulCloseCommand msg,
        ChannelPromise promise) throws Exception {
    super.close(ctx, promise);
    connection().forEachActiveStream(new Http2StreamVisitor() {
        @Override/*from  w  ww  .  j av a 2 s .  co m*/
        public boolean visit(Http2Stream stream) throws Http2Exception {
            NettyServerStream.TransportState serverStream = serverStream(stream);
            if (serverStream != null) {
                PerfMark.startTask("NettyServerHandler.forcefulClose", serverStream.tag());
                PerfMark.linkIn(msg.getLink());
                try {
                    serverStream.transportReportStatus(msg.getStatus());
                    resetStream(ctx, stream.id(), Http2Error.CANCEL.code(), ctx.newPromise());
                } finally {
                    PerfMark.stopTask("NettyServerHandler.forcefulClose", serverStream.tag());
                }
            }
            stream.close();
            return true;
        }
    });
}

From source file:io.vertx.core.http.impl.Http2ConnectionBase.java

License:Open Source License

synchronized void onStreamwritabilityChanged(Http2Stream s) {
    VertxHttp2Stream stream = streams.get(s.id());
    if (stream != null) {
        context.executeFromIO(stream::onWritabilityChanged);
    }/*w w  w.jav  a2  s .  c  o m*/
}