use of org.apache.flink.shaded.netty4.io.netty.channel.ChannelException in project netty by netty.
the class EpollChannelConfig method setEpollMode.
/**
* Set the {@link EpollMode} used. Default is
* {@link EpollMode#EDGE_TRIGGERED}. If you want to use {@link #isAutoRead()} {@code false} or
* {@link #getMaxMessagesPerRead()} and have an accurate behaviour you should use
* {@link EpollMode#LEVEL_TRIGGERED}.
*
* <strong>Be aware this config setting can only be adjusted before the channel was registered.</strong>
*/
public EpollChannelConfig setEpollMode(EpollMode mode) {
ObjectUtil.checkNotNull(mode, "mode");
try {
switch(mode) {
case EDGE_TRIGGERED:
checkChannelNotRegistered();
((AbstractEpollChannel) channel).setFlag(Native.EPOLLET);
break;
case LEVEL_TRIGGERED:
checkChannelNotRegistered();
((AbstractEpollChannel) channel).clearFlag(Native.EPOLLET);
break;
default:
throw new Error();
}
} catch (IOException e) {
throw new ChannelException(e);
}
return this;
}
use of org.apache.flink.shaded.netty4.io.netty.channel.ChannelException in project netty by netty.
the class EpollDatagramChannelConfig method setNetworkInterface.
@Override
public EpollDatagramChannelConfig setNetworkInterface(NetworkInterface networkInterface) {
try {
EpollDatagramChannel datagramChannel = (EpollDatagramChannel) channel;
datagramChannel.socket.setNetworkInterface(networkInterface);
return this;
} catch (IOException e) {
throw new ChannelException(e);
}
}
use of org.apache.flink.shaded.netty4.io.netty.channel.ChannelException in project netty by netty.
the class EpollSocketChannelConfigTest method testSetOptionWhenClosed.
// For this test to pass, we are relying on the sockets file descriptor not being reused after the socket is closed.
// This is inherently racy, so we allow getSoLinger to throw ChannelException a few of times, but eventually we do
// want to see a ClosedChannelException for the test to pass.
@RepeatedIfExceptionsTest(repeats = 4)
public void testSetOptionWhenClosed() {
ch.close().syncUninterruptibly();
ChannelException e = assertThrows(ChannelException.class, new Executable() {
@Override
public void execute() throws Throwable {
ch.config().setSoLinger(0);
}
});
assertThat(e).hasCauseInstanceOf(ClosedChannelException.class);
}
use of org.apache.flink.shaded.netty4.io.netty.channel.ChannelException in project rest.li by linkedin.
the class Http2ProtocolUpgradeHandler method processChannelActive.
public static void processChannelActive(ChannelHandlerContext ctx, Logger log, ChannelPromise upgradePromise) {
// For an upgrade request, clients should use an OPTIONS request for path “*” or a HEAD request for “/”.
// RFC: https://tools.ietf.org/html/rfc7540#section-3.2
// Implementation detail: https://http2.github.io/faq/#can-i-implement-http2-without-implementing-http11
final DefaultFullHttpRequest request = new DefaultFullHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.OPTIONS, "*");
final String hostname;
if (ctx.channel().remoteAddress() instanceof InetSocketAddress) {
// 1) The documentation of remoteAddress says that it should be down-casted to InetSocketAddress.
// 2) The getHostString doesn't attempt a reverse lookup
InetSocketAddress inetAddress = ((InetSocketAddress) ctx.channel().remoteAddress());
hostname = inetAddress.getHostString() + ":" + inetAddress.getPort();
} else {
// if it is not a InetSocketAddress, it is a DomainSocketAddress, a LocalAddress or a EmbeddedSocketAddress.
// In the R2 stack it should never happen
hostname = "localhost";
log.warn("The remoteAddress is not an InetSocketAddress, therefore it has been used '" + hostname + "'" + " for the HOST of the upgrade request", ctx.channel().remoteAddress());
}
// The host is required given rfc2616 14.23 also for the upgrade request.
// Without it, the host the upgrade request fails
// https://tools.ietf.org/html/rfc2616#section-14.23
request.headers().add(HttpHeaderNames.HOST, hostname);
ctx.writeAndFlush(request);
// Fail the upgrade promise when channel is closed
ctx.channel().closeFuture().addListener(future -> {
if (!upgradePromise.isDone()) {
upgradePromise.setFailure(new ChannelException("HTTP/2 upgrade did not complete before channel closed"));
}
});
ctx.fireChannelActive();
}
use of org.apache.flink.shaded.netty4.io.netty.channel.ChannelException in project Glowstone by GlowstoneMC.
the class GlowChannelInitializer method initChannel.
@Override
protected void initChannel(SocketChannel c) {
MessageHandler handler = new MessageHandler(connectionManager);
CodecsHandler codecs = new CodecsHandler(connectionManager.getProtocolProvider().handshake);
FramingHandler framing = new FramingHandler();
try {
c.config().setOption(ChannelOption.IP_TOS, 0x18);
} catch (ChannelException e) {
// Not supported on all OSs, like Windows XP and lesser
GlowServer.logger.warning("Your OS does not support type of service.");
}
c.pipeline().addLast("idle_timeout", new IdleStateHandler(READ_IDLE_TIMEOUT, WRITE_IDLE_TIMEOUT, 0)).addLast("legacy_ping", new LegacyPingHandler(connectionManager)).addLast("encryption", NoopHandler.INSTANCE).addLast("framing", framing).addLast("compression", NoopHandler.INSTANCE).addLast("codecs", codecs).addLast("handler", handler);
}
Aggregations