Java源码示例:io.netty.handler.timeout.WriteTimeoutException
示例1
@Override
public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) {
if (cause instanceof WriteTimeoutException) {
}
this.oneNetClientContext.closeDirectly(clientSession);
ctx.close();
}
示例2
private Throwable decorateException(Throwable originalCause) {
if (isAcquireTimeoutException(originalCause)) {
return new Throwable(getMessageForAcquireTimeoutException(), originalCause);
} else if (isTooManyPendingAcquiresException(originalCause)) {
return new Throwable(getMessageForTooManyAcquireOperationsError(), originalCause);
} else if (originalCause instanceof ReadTimeoutException) {
return new IOException("Read timed out", originalCause);
} else if (originalCause instanceof WriteTimeoutException) {
return new IOException("Write timed out", originalCause);
} else if (originalCause instanceof ClosedChannelException) {
return new IOException(getMessageForClosedChannel(), originalCause);
}
return originalCause;
}
示例3
private Throwable wrapException(Throwable originalCause) {
if (originalCause instanceof ReadTimeoutException) {
return new IOException("Read timed out", originalCause);
} else if (originalCause instanceof WriteTimeoutException) {
return new IOException("Write timed out", originalCause);
}
return originalCause;
}
示例4
@Override
@SuppressWarnings("deprecation")
public void exceptionCaught(ChannelHandlerContext ctx, Throwable t) {
if (t instanceof WriteTimeoutException) {
super.exceptionCaught(ctx, new UploadTimeoutException(path, contentLength));
} else if (t instanceof TooLongFrameException) {
super.exceptionCaught(ctx, new IOException(t));
} else {
super.exceptionCaught(ctx, t);
}
}
示例5
@Override
public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) {
String message = null;
if(cause instanceof ConnectTimeoutException || (cause instanceof ConnectException && cause.getMessage().contains("connection timed out"))) {
message = "Connection timed out.";
} else if(cause instanceof ReadTimeoutException) {
message = "Read timed out.";
} else if(cause instanceof WriteTimeoutException) {
message = "Write timed out.";
} else {
message = cause.toString();
}
this.disconnect(message, cause);
}
示例6
@SuppressWarnings("FutureReturnValueIgnored")
private Channel acquireUploadChannel() throws InterruptedException {
Promise<Channel> channelReady = eventLoop.next().newPromise();
channelPool
.acquire()
.addListener(
(Future<Channel> channelAcquired) -> {
if (!channelAcquired.isSuccess()) {
channelReady.setFailure(channelAcquired.cause());
return;
}
try {
Channel ch = channelAcquired.getNow();
ChannelPipeline p = ch.pipeline();
if (!isChannelPipelineEmpty(p)) {
channelReady.setFailure(
new IllegalStateException("Channel pipeline is not empty."));
return;
}
p.addFirst(
"timeout-handler",
new IdleTimeoutHandler(timeoutSeconds, WriteTimeoutException.INSTANCE));
p.addLast(new HttpResponseDecoder());
// The 10KiB limit was chosen arbitrarily. We only expect HTTP servers to respond
// with an error message in the body, and that should always be less than 10KiB. If
// the response is larger than 10KiB, HttpUploadHandler will catch the
// TooLongFrameException that HttpObjectAggregator throws and convert it to an
// IOException.
p.addLast(new HttpObjectAggregator(10 * 1024));
p.addLast(new HttpRequestEncoder());
p.addLast(new ChunkedWriteHandler());
synchronized (credentialsLock) {
p.addLast(new HttpUploadHandler(creds, extraHttpHeaders));
}
if (!ch.eventLoop().inEventLoop()) {
// If addLast is called outside an event loop, then it doesn't complete until the
// event loop is run again. In that case, a message sent to the last handler gets
// delivered to the last non-pending handler, which will most likely end up
// throwing UnsupportedMessageTypeException. Therefore, we only complete the
// promise in the event loop.
ch.eventLoop().execute(() -> channelReady.setSuccess(ch));
} else {
channelReady.setSuccess(ch);
}
} catch (Throwable t) {
channelReady.setFailure(t);
}
});
try {
return channelReady.get();
} catch (ExecutionException e) {
PlatformDependent.throwException(e.getCause());
return null;
}
}