<groupId>org.opendaylight.netconf</groupId>
<artifactId>transport-api</artifactId>
</dependency>
-
- <dependency>
- <groupId>io.netty</groupId>
- <artifactId>netty-transport-native-epoll</artifactId>
- <classifier>linux-x86_64</classifier>
- <scope>test</scope>
- </dependency>
</dependencies>
<build>
@NonNullByDefault
public final class NettyTransportSupport {
private static final Logger LOG = LoggerFactory.getLogger(NettyTransportSupport.class);
- private static final AbstractNettyImpl IMPL = Epoll.isAvailable() ? new EpollNettyImpl() : new NioNettyImpl();
+ private static final AbstractNettyImpl IMPL = Epoll.isAvailable() ? new EpollNettyImpl() : NioNettyImpl.INSTANCE;
static {
LOG.info("Netty transport backed by {}", IMPL);
SUPPORT = support;
}
- private final boolean supportsKeepalives;
+ static final NioNettyImpl INSTANCE;
- NioNettyImpl() {
- final var ch = new NioSocketChannel();
+ static {
+ final var grp = new NioEventLoopGroup();
try {
- supportsKeepalives = SUPPORT.configureKeepalives(ch.config());
- } finally {
- ch.close();
+ try {
+ final var ch = new NioSocketChannel();
+ grp.register(ch).sync();
+
+ final boolean supportsKeepalives;
+ try {
+ supportsKeepalives = SUPPORT.configureKeepalives(ch.config());
+ } finally {
+ ch.close().sync();
+ }
+ INSTANCE = new NioNettyImpl(supportsKeepalives);
+ } finally {
+ grp.shutdownGracefully().sync();
+ }
+ } catch (InterruptedException e) {
+ Thread.currentThread().interrupt();
+ throw new ExceptionInInitializerError(e);
}
}
+ private final boolean supportsKeepalives;
+
+ private NioNettyImpl(final boolean supportsKeepalives) {
+ this.supportsKeepalives = supportsKeepalives;
+ }
+
@Override
Class<NioSocketChannel> channelClass() {
return NioSocketChannel.class;