本文整理汇总了Java中io.netty.handler.codec.PrematureChannelClosureException类的典型用法代码示例。如果您正苦于以下问题:Java PrematureChannelClosureException类的具体用法?Java PrematureChannelClosureException怎么用?Java PrematureChannelClosureException使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
PrematureChannelClosureException类属于io.netty.handler.codec包,在下文中一共展示了PrematureChannelClosureException类的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: exceptionCaught
import io.netty.handler.codec.PrematureChannelClosureException; //导入依赖的package包/类
@Override @SuppressWarnings("unchecked")
public final void exceptionCaught(final ChannelHandlerContext ctx, final Throwable cause)
throws IOException {
final Channel channel = ctx.channel();
final O ioTask = (O) channel.attr(NetStorageDriver.ATTR_KEY_IOTASK).get();
if(ioTask != null) {
if(driver.isInterrupted() || driver.isClosed()) {
ioTask.setStatus(INTERRUPTED);
} else if(cause instanceof PrematureChannelClosureException) {
LogUtil.exception(Level.WARN, cause, "Premature channel closure");
ioTask.setStatus(FAIL_IO);
} else {
LogUtil.exception(Level.WARN, cause, "Client handler failure");
ioTask.setStatus(FAIL_UNKNOWN);
}
if(!driver.isInterrupted()) {
try {
driver.complete(channel, ioTask);
} catch(final Exception e) {
LogUtil.exception(Level.DEBUG, e, "Failed to complete the I/O task");
}
}
}
}
示例2: testIdentifyCloseChannelOnFailure
import io.netty.handler.codec.PrematureChannelClosureException; //导入依赖的package包/类
@Test(expected = PrematureChannelClosureException.class)
public void testIdentifyCloseChannelOnFailure() throws Exception {
Channel channel = mock(Channel.class, Answers.RETURNS_SMART_NULLS.get());
mockWriteHandler = mock(ChannelHandler.class);
DefaultChannelPromise completedFuture = new DefaultChannelPromise(channel);
completedFuture.setSuccess();
DefaultChannelPromise failedFuture = new DefaultChannelPromise(channel);
failedFuture.setFailure(new PrematureChannelClosureException("test"));
ChannelPipeline channelPipeline = mock(ChannelPipeline.class);
when(channelPipeline.addLast(anyString(), any(ChannelHandler.class))).thenReturn(channelPipeline);
when(channelPipeline.addLast(any(EventExecutorGroup.class), anyString(), any(ChannelHandler.class))).thenReturn(channelPipeline);
when(channel.pipeline()).thenReturn(channelPipeline);
when(channel.isActive()).thenReturn(true);
when(channel.writeAndFlush(any())).thenReturn(failedFuture);
when(channel.close()).thenReturn(completedFuture);
when(bootstrap.connect(anyString(), anyInt())).thenReturn(completedFuture);
ClientSessionConfiguration configuration = new ClientSessionConfiguration();
jannelClient.identify(configuration, null);
}
示例3: testFailsOnIncompleteChunkedResponse
import io.netty.handler.codec.PrematureChannelClosureException; //导入依赖的package包/类
@Test
public void testFailsOnIncompleteChunkedResponse() {
HttpClientCodec codec = new HttpClientCodec(4096, 8192, 8192, true);
EmbeddedChannel ch = new EmbeddedChannel(codec);
ch.writeOutbound(releaseLater(
new DefaultFullHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.GET, "http://localhost/")));
assertNotNull(releaseLater(ch.readOutbound()));
assertNull(ch.readInbound());
ch.writeInbound(releaseLater(
Unpooled.copiedBuffer(INCOMPLETE_CHUNKED_RESPONSE, CharsetUtil.ISO_8859_1)));
assertThat(releaseLater(ch.readInbound()), instanceOf(HttpResponse.class));
assertThat(releaseLater(ch.readInbound()), instanceOf(HttpContent.class)); // Chunk 'first'
assertThat(releaseLater(ch.readInbound()), instanceOf(HttpContent.class)); // Chunk 'second'
assertNull(ch.readInbound());
try {
ch.finish();
fail();
} catch (CodecException e) {
assertTrue(e instanceof PrematureChannelClosureException);
}
}
示例4: channelInactive
import io.netty.handler.codec.PrematureChannelClosureException; //导入依赖的package包/类
@Override
public void channelInactive(ChannelHandlerContext ctx)
throws Exception {
super.channelInactive(ctx);
if (failOnMissingResponse) {
long missingResponses = requestResponseCounter.get();
if (missingResponses > 0) {
ctx.fireExceptionCaught(new PrematureChannelClosureException(
"channel gone inactive with " + missingResponses +
" missing response(s)"));
}
}
}
示例5: testFailsOnMissingResponse
import io.netty.handler.codec.PrematureChannelClosureException; //导入依赖的package包/类
@Test
public void testFailsOnMissingResponse() {
HttpClientCodec codec = new HttpClientCodec(4096, 8192, 8192, true);
EmbeddedChannel ch = new EmbeddedChannel(codec);
assertTrue(ch.writeOutbound(new DefaultFullHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.GET,
"http://localhost/")));
assertNotNull(releaseLater(ch.readOutbound()));
try {
ch.finish();
fail();
} catch (CodecException e) {
assertTrue(e instanceof PrematureChannelClosureException);
}
}
示例6: channelInactive
import io.netty.handler.codec.PrematureChannelClosureException; //导入依赖的package包/类
@Override
public void channelInactive(ChannelHandlerContext ctx) throws Exception {
super.channelInactive(ctx);
if (failOnMissingResponse) {
long missingResponses = requestResponseCounter.get();
if (missingResponses > 0) {
ctx.fireExceptionCaught(new PrematureChannelClosureException(
"channel gone inactive with " + missingResponses +
" missing response(s)"));
}
}
}
示例7: channelInactive
import io.netty.handler.codec.PrematureChannelClosureException; //导入依赖的package包/类
@Override
public void channelInactive(ChannelHandlerContext ctx) throws Exception {
super.channelInactive(ctx);
if (failOnMissingResponse) {
long missingResponses = requestResponseCounter.get();
if (missingResponses > 0) {
ctx.fireExceptionCaught(new PrematureChannelClosureException(
"channel gone inactive with " + missingResponses
+ " missing response(s)"));
}
}
}
示例8: onUncaughtException
import io.netty.handler.codec.PrematureChannelClosureException; //导入依赖的package包/类
@Override
public void onUncaughtException(Throwable t) {
callWithLock(() -> {
if (t instanceof PrematureChannelClosureException) {
LOG.error("Lost connection to the mesos master, aborting", t);
notifyStopping();
abort.abort(AbortReason.LOST_MESOS_CONNECTION, Optional.absent());
} else {
LOG.error("Aborting due to error: {}", t.getMessage(), t);
notifyStopping();
abort.abort(AbortReason.MESOS_ERROR, Optional.absent());
}
}, "errorUncaughtException");
}