本文整理汇总了Java中io.netty.handler.codec.http2.Http2Stream类的典型用法代码示例。如果您正苦于以下问题:Java Http2Stream类的具体用法?Java Http2Stream怎么用?Java Http2Stream使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Http2Stream类属于io.netty.handler.codec.http2包,在下文中一共展示了Http2Stream类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: validateStream
import io.netty.handler.codec.http2.Http2Stream; //导入依赖的package包/类
private ChannelFuture validateStream(ChannelHandlerContext ctx, int streamId) {
final Http2Stream stream = encoder.connection().stream(streamId);
if (stream != null) {
switch (stream.state()) {
case RESERVED_LOCAL:
case OPEN:
case HALF_CLOSED_REMOTE:
break;
default:
// The response has been sent already.
return ctx.newFailedFuture(ClosedPublisherException.get());
}
} else if (encoder.connection().streamMayHaveExisted(streamId)) {
// Stream has been removed because it has been closed completely.
return ctx.newFailedFuture(ClosedPublisherException.get());
}
return null;
}
示例2: forcefulClose
import io.netty.handler.codec.http2.Http2Stream; //导入依赖的package包/类
private void forcefulClose(final ChannelHandlerContext ctx, final ForcefulCloseCommand msg,
ChannelPromise promise) throws Exception {
close(ctx, promise);
connection().forEachActiveStream(new Http2StreamVisitor() {
@Override
public boolean visit(Http2Stream stream) throws Http2Exception {
NettyServerStream.TransportState serverStream = serverStream(stream);
if (serverStream != null) {
serverStream.transportReportStatus(msg.getStatus());
resetStream(ctx, stream.id(), Http2Error.CANCEL.code(), ctx.newPromise());
}
stream.close();
return true;
}
});
}
示例3: forcefulClose
import io.netty.handler.codec.http2.Http2Stream; //导入依赖的package包/类
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
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;
}
});
}
示例4: goingAway
import io.netty.handler.codec.http2.Http2Stream; //导入依赖的package包/类
/**
* Handler for a GOAWAY being either sent or received. Fails any streams created after the
* last known stream.
*/
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, false, new Metadata());
}
stream.close();
}
return true;
}
});
} catch (Http2Exception e) {
throw new RuntimeException(e);
}
}
示例5: windowShouldNotExceedMaxWindowSize
import io.netty.handler.codec.http2.Http2Stream; //导入依赖的package包/类
@Test
public void windowShouldNotExceedMaxWindowSize() throws Exception {
manualSetUp();
makeStream();
AbstractNettyHandler handler = (AbstractNettyHandler) handler();
handler.setAutoTuneFlowControl(true);
Http2Stream connectionStream = connection().connectionStream();
Http2LocalFlowController localFlowController = connection().local().flowController();
int maxWindow = handler.flowControlPing().maxWindow();
handler.flowControlPing().setDataSizeSincePing(maxWindow);
int payload = handler.flowControlPing().payload();
ByteBuf buffer = handler.ctx().alloc().buffer(8);
buffer.writeLong(payload);
channelRead(pingFrame(true, buffer));
assertEquals(maxWindow, localFlowController.initialWindowSize(connectionStream));
}
示例6: onStreamClosed
import io.netty.handler.codec.http2.Http2Stream; //导入依赖的package包/类
@Override
public void onStreamClosed(Http2Stream stream) {
final HttpResponseWrapper res = getResponse(streamIdToId(stream.id()), true);
if (res != null) {
res.close(ClosedSessionException.get());
}
}
示例7: setHttp2Stream
import io.netty.handler.codec.http2.Http2Stream; //导入依赖的package包/类
/**
* Sets the underlying Netty {@link Http2Stream} for this stream. This must be called in the
* context of the transport thread.
*/
public void setHttp2Stream(Http2Stream http2Stream) {
checkNotNull(http2Stream, "http2Stream");
checkState(this.http2Stream == null, "Can only set http2Stream once");
this.http2Stream = http2Stream;
// Now that the stream has actually been initialized, call the listener's onReady callback if
// appropriate.
onStreamAllocated();
}
示例8: TransportState
import io.netty.handler.codec.http2.Http2Stream; //导入依赖的package包/类
public TransportState(
NettyServerHandler handler,
EventLoop eventLoop,
Http2Stream http2Stream,
int maxMessageSize,
StatsTraceContext statsTraceCtx,
TransportTracer transportTracer) {
super(maxMessageSize, statsTraceCtx, transportTracer);
this.http2Stream = checkNotNull(http2Stream, "http2Stream");
this.handler = checkNotNull(handler, "handler");
this.eventLoop = eventLoop;
}
示例9: channelInactive
import io.netty.handler.codec.http2.Http2Stream; //导入依赖的package包/类
/**
* Handler for the Channel shutting down.
*/
@Override
public void channelInactive(ChannelHandlerContext ctx) throws Exception {
try {
if (keepAliveManager != null) {
keepAliveManager.onTransportTermination();
}
if (maxConnectionIdleManager != null) {
maxConnectionIdleManager.onTransportTermination();
}
if (maxConnectionAgeMonitor != null) {
maxConnectionAgeMonitor.cancel(false);
}
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);
}
}
示例10: returnProcessedBytes
import io.netty.handler.codec.http2.Http2Stream; //导入依赖的package包/类
/**
* Returns the given processed bytes back to inbound flow control.
*/
void returnProcessedBytes(Http2Stream http2Stream, int bytes) {
try {
decoder().flowController().consumeBytes(http2Stream, bytes);
} catch (Http2Exception e) {
throw new RuntimeException(e);
}
}
示例11: requireHttp2Stream
import io.netty.handler.codec.http2.Http2Stream; //导入依赖的package包/类
private Http2Stream requireHttp2Stream(int streamId) {
Http2Stream stream = connection().stream(streamId);
if (stream == null) {
// This should never happen.
throw new AssertionError("Stream does not exist: " + streamId);
}
return stream;
}
示例12: returnProcessedBytes
import io.netty.handler.codec.http2.Http2Stream; //导入依赖的package包/类
/**
* Returns the given processed bytes back to inbound flow control.
*/
void returnProcessedBytes(Http2Stream stream, int bytes) {
try {
decoder().flowController().consumeBytes(stream, bytes);
} catch (Http2Exception e) {
throw new RuntimeException(e);
}
}
示例13: channelInactive
import io.netty.handler.codec.http2.Http2Stream; //导入依赖的package包/类
/**
* Handler for the Channel shutting down.
*/
@Override
public void channelInactive(ChannelHandlerContext ctx) throws Exception {
try {
logger.fine("Network channel is closed");
Status status = Status.UNAVAILABLE.withDescription("Network closed for unknown reason");
lifecycleManager.notifyShutdown(status);
try {
cancelPing(lifecycleManager.getShutdownThrowable());
// Report status to the application layer for any open streams
connection().forEachActiveStream(new Http2StreamVisitor() {
@Override
public boolean visit(Http2Stream stream) throws Http2Exception {
NettyClientStream.TransportState clientStream = clientStream(stream);
if (clientStream != null) {
clientStream.transportReportStatus(
lifecycleManager.getShutdownStatus(), false, new Metadata());
}
return true;
}
});
} finally {
lifecycleManager.notifyTerminated(status);
}
} finally {
// Close any open streams
super.channelInactive(ctx);
if (keepAliveManager != null) {
keepAliveManager.onTransportTermination();
}
}
}
示例14: sendInitialConnectionWindow
import io.netty.handler.codec.http2.Http2Stream; //导入依赖的package包/类
/**
* 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();
}
}
示例15: connectionWindowShouldBeOverridden
import io.netty.handler.codec.http2.Http2Stream; //导入依赖的package包/类
@Test
public void connectionWindowShouldBeOverridden() throws Exception {
flowControlWindow = 1048576; // 1MiB
manualSetUp();
Http2Stream connectionStream = connection().connectionStream();
Http2LocalFlowController localFlowController = connection().local().flowController();
int actualInitialWindowSize = localFlowController.initialWindowSize(connectionStream);
int actualWindowSize = localFlowController.windowSize(connectionStream);
assertEquals(flowControlWindow, actualWindowSize);
assertEquals(flowControlWindow, actualInitialWindowSize);
}