Example usage for io.netty.util Version identify

List of usage examples for io.netty.util Version identify

Introduction

In this page you can find the example usage for io.netty.util Version identify.

Prototype

public static Map<String, Version> identify() 

Source Link

Document

Retrieves the version information of Netty artifacts using the current Thread#getContextClassLoader() context class loader .

Usage

From source file:co.elastic.tealess.cli.EnvironmentCommand.java

License:Apache License

private void showNettyDetails() {
    if (OpenSsl.isAvailable()) {
        System.out.printf("Netty OpenSSL support is available.\n");
    } else {//w  w  w .  j  a v a  2s.  co m
        Throwable e = OpenSsl.unavailabilityCause();
        System.out.printf("Netty's OpenSSL layer could not be loaded: %s\n", e.getMessage());
    }

    System.out.println("Netty details:");
    Map<String, Version> nettyComponents = Version.identify();
    Version.identify().forEach((k, v) -> {
        if (k.contains("tcnative")) {
            System.out.printf("  %s\n", v);
        }
    });

}

From source file:com.lambdaworks.redis.reliability.AtLeastOnceTest.java

License:Apache License

@Test
public void commandNotFailedChannelClosesWhileFlush() throws Exception {

    assumeTrue(Version.identify().get("netty-transport").artifactVersion().startsWith("4.0.2"));

    RedisCommands<String, String> connection = client.connect().sync();
    RedisCommands<String, String> verificationConnection = client.connect().sync();
    RedisChannelWriter<String, String> channelWriter = getRedisChannelHandler(connection).getChannelWriter();

    connection.set(key, "1");
    assertThat(verificationConnection.get(key)).isEqualTo("1");

    final CountDownLatch block = new CountDownLatch(1);

    ConnectionWatchdog connectionWatchdog = Connections
            .getConnectionWatchdog(connection.getStatefulConnection());

    AsyncCommand<String, String, Object> command = getBlockOnEncodeCommand(block);

    channelWriter.write(command);/*w  ww  . j  a  v  a 2s  .c om*/

    connectionWatchdog.setReconnectSuspended(true);

    Channel channel = getChannel(getRedisChannelHandler(connection));
    channel.unsafe().disconnect(channel.newPromise());

    assertThat(channel.isOpen()).isFalse();
    assertThat(command.isCancelled()).isFalse();
    assertThat(command.isDone()).isFalse();
    block.countDown();
    assertThat(command.await(2, TimeUnit.SECONDS)).isFalse();
    assertThat(command.isCancelled()).isFalse();
    assertThat(command.isDone()).isFalse();

    assertThat(verificationConnection.get(key)).isEqualTo("1");

    assertThat(getQueue(getRedisChannelHandler(connection))).isEmpty();
    assertThat(getCommandBuffer(getRedisChannelHandler(connection))).isNotEmpty().contains(command);

    connection.close();
}

From source file:com.lambdaworks.redis.reliability.AtLeastOnceTest.java

License:Apache License

@Test
public void commandRetriedChannelClosesWhileFlush() throws Exception {

    assumeTrue(Version.identify().get("netty-transport").artifactVersion().startsWith("4.0.2"));

    RedisCommands<String, String> connection = client.connect().sync();
    RedisCommands<String, String> verificationConnection = client.connect().sync();
    RedisChannelWriter<String, String> channelWriter = getRedisChannelHandler(connection).getChannelWriter();

    connection.set(key, "1");
    assertThat(verificationConnection.get(key)).isEqualTo("1");

    final CountDownLatch block = new CountDownLatch(1);

    ConnectionWatchdog connectionWatchdog = Connections
            .getConnectionWatchdog(connection.getStatefulConnection());

    AsyncCommand<String, String, Object> command = getBlockOnEncodeCommand(block);

    channelWriter.write(command);/*from w  ww .j a  va2  s .  c  om*/

    connectionWatchdog.setReconnectSuspended(true);

    Channel channel = getChannel(getRedisChannelHandler(connection));
    channel.unsafe().disconnect(channel.newPromise());

    assertThat(channel.isOpen()).isFalse();
    assertThat(command.isCancelled()).isFalse();
    assertThat(command.isDone()).isFalse();
    block.countDown();
    assertThat(command.await(2, TimeUnit.SECONDS)).isFalse();

    connectionWatchdog.setReconnectSuspended(false);
    connectionWatchdog.scheduleReconnect();

    assertThat(command.await(2, TimeUnit.SECONDS)).isTrue();
    assertThat(command.isCancelled()).isFalse();
    assertThat(command.isDone()).isTrue();

    assertThat(verificationConnection.get(key)).isEqualTo("2");

    assertThat(getQueue(getRedisChannelHandler(connection))).isEmpty();
    assertThat(getCommandBuffer(getRedisChannelHandler(connection))).isEmpty();

    connection.close();
    verificationConnection.close();
}

From source file:com.lambdaworks.redis.reliability.AtMostOnceTest.java

License:Apache License

@Test
public void commandNotExecutedChannelClosesWhileFlush() throws Exception {

    assumeTrue(Version.identify().get("netty-transport").artifactVersion().startsWith("4.0.2"));

    RedisCommands<String, String> connection = client.connect().sync();
    RedisCommands<String, String> verificationConnection = client.connect().sync();
    RedisChannelWriter<String, String> channelWriter = getRedisChannelHandler(connection).getChannelWriter();

    connection.set(key, "1");
    assertThat(verificationConnection.get(key)).isEqualTo("1");

    final CountDownLatch block = new CountDownLatch(1);

    AsyncCommand<String, String, Object> command = new AsyncCommand<String, String, Object>(
            new Command<>(CommandType.INCR, new IntegerOutput(CODEC), new CommandArgs<>(CODEC).addKey(key))) {

        @Override//  w  ww.  j a v  a2s . c o m
        public void encode(ByteBuf buf) {
            try {
                block.await();
            } catch (InterruptedException e) {
            }
            super.encode(buf);
        }
    };

    channelWriter.write(command);

    Channel channel = getChannel(getRedisChannelHandler(connection));
    channel.unsafe().disconnect(channel.newPromise());

    assertThat(channel.isOpen()).isFalse();
    assertThat(command.isCancelled()).isFalse();
    assertThat(command.isDone()).isFalse();
    block.countDown();
    assertThat(command.await(2, TimeUnit.SECONDS)).isTrue();
    assertThat(command.isCancelled()).isFalse();
    assertThat(command.isDone()).isTrue();

    assertThat(verificationConnection.get(key)).isEqualTo("1");

    assertThat(getQueue(getRedisChannelHandler(connection))).isEmpty();
    assertThat(getCommandBuffer(getRedisChannelHandler(connection))).isEmpty();

    connection.close();
}

From source file:io.lettuce.core.reliability.AtLeastOnceTest.java

License:Apache License

@Test
public void commandNotFailedChannelClosesWhileFlush() throws Exception {

    assumeTrue(Version.identify().get("netty-transport").artifactVersion().startsWith("4.0.2"));

    StatefulRedisConnection<String, String> connection = client.connect();
    RedisCommands<String, String> verificationConnection = client.connect().sync();
    RedisChannelWriter channelWriter = ConnectionTestUtil.getChannelWriter(connection);

    RedisCommands<String, String> sync = connection.sync();
    sync.set(key, "1");
    assertThat(verificationConnection.get(key)).isEqualTo("1");

    final CountDownLatch block = new CountDownLatch(1);

    ConnectionWatchdog connectionWatchdog = ConnectionTestUtil.getConnectionWatchdog(connection);

    AsyncCommand<String, String, Object> command = getBlockOnEncodeCommand(block);

    channelWriter.write(command);/*from   ww  w.  j ava 2  s .com*/

    connectionWatchdog.setReconnectSuspended(true);

    Channel channel = ConnectionTestUtil.getChannel(connection);
    channel.unsafe().disconnect(channel.newPromise());

    assertThat(channel.isOpen()).isFalse();
    assertThat(command.isCancelled()).isFalse();
    assertThat(command.isDone()).isFalse();
    block.countDown();
    assertThat(command.await(2, TimeUnit.SECONDS)).isFalse();
    assertThat(command.isCancelled()).isFalse();
    assertThat(command.isDone()).isFalse();

    assertThat(verificationConnection.get(key)).isEqualTo("1");

    assertThat(ConnectionTestUtil.getStack(connection)).isEmpty();
    assertThat(ConnectionTestUtil.getCommandBuffer(connection)).isNotEmpty().contains(command);

    connection.close();
}

From source file:io.lettuce.core.reliability.AtLeastOnceTest.java

License:Apache License

@Test
public void commandRetriedChannelClosesWhileFlush() throws Exception {

    assumeTrue(Version.identify().get("netty-transport").artifactVersion().startsWith("4.0.2"));

    StatefulRedisConnection<String, String> connection = client.connect();
    RedisCommands<String, String> sync = connection.sync();
    RedisCommands<String, String> verificationConnection = client.connect().sync();
    RedisChannelWriter channelWriter = ConnectionTestUtil.getChannelWriter(connection);

    sync.set(key, "1");
    assertThat(verificationConnection.get(key)).isEqualTo("1");

    final CountDownLatch block = new CountDownLatch(1);

    ConnectionWatchdog connectionWatchdog = ConnectionTestUtil
            .getConnectionWatchdog(sync.getStatefulConnection());

    AsyncCommand<String, String, Object> command = getBlockOnEncodeCommand(block);

    channelWriter.write(command);// w w  w. ja v a 2s. co  m

    connectionWatchdog.setReconnectSuspended(true);

    Channel channel = ConnectionTestUtil.getChannel(sync.getStatefulConnection());
    channel.unsafe().disconnect(channel.newPromise());

    assertThat(channel.isOpen()).isFalse();
    assertThat(command.isCancelled()).isFalse();
    assertThat(command.isDone()).isFalse();
    block.countDown();
    assertThat(command.await(2, TimeUnit.SECONDS)).isFalse();

    connectionWatchdog.setReconnectSuspended(false);
    connectionWatchdog.scheduleReconnect();

    assertThat(command.await(2, TimeUnit.SECONDS)).isTrue();
    assertThat(command.isCancelled()).isFalse();
    assertThat(command.isDone()).isTrue();

    assertThat(verificationConnection.get(key)).isEqualTo("2");

    assertThat(ConnectionTestUtil.getStack(sync.getStatefulConnection())).isEmpty();
    assertThat(ConnectionTestUtil.getCommandBuffer(sync.getStatefulConnection())).isEmpty();

    sync.getStatefulConnection().close();
    verificationConnection.getStatefulConnection().close();
}

From source file:io.lettuce.core.reliability.AtMostOnceTest.java

License:Apache License

@Test
public void commandNotExecutedChannelClosesWhileFlush() {

    assumeTrue(Version.identify().get("netty-transport").artifactVersion().startsWith("4.0.2"));

    StatefulRedisConnection<String, String> connection = client.connect();
    RedisCommands<String, String> sync = connection.sync();
    RedisCommands<String, String> verificationConnection = client.connect().sync();
    RedisChannelWriter channelWriter = ConnectionTestUtil.getChannelWriter(connection);

    sync.set(key, "1");
    assertThat(verificationConnection.get(key)).isEqualTo("1");

    final CountDownLatch block = new CountDownLatch(1);

    AsyncCommand<String, String, Object> command = new AsyncCommand<String, String, Object>(
            new Command<>(CommandType.INCR, new IntegerOutput(CODEC), new CommandArgs<>(CODEC).addKey(key))) {

        @Override//  w w w .  j a  va2  s . c o m
        public void encode(ByteBuf buf) {
            try {
                block.await();
            } catch (InterruptedException e) {
            }
            super.encode(buf);
        }
    };

    channelWriter.write(command);

    Channel channel = ConnectionTestUtil.getChannel(connection);
    channel.unsafe().disconnect(channel.newPromise());

    assertThat(channel.isOpen()).isFalse();
    assertThat(command.isCancelled()).isFalse();
    assertThat(command.isDone()).isFalse();
    block.countDown();
    assertThat(command.await(2, TimeUnit.SECONDS)).isTrue();
    assertThat(command.isCancelled()).isFalse();
    assertThat(command.isDone()).isTrue();

    assertThat(verificationConnection.get(key)).isEqualTo("1");

    assertThat(getStack(connection)).isEmpty();
    assertThat(getCommandBuffer(connection)).isEmpty();

    connection.close();
}

From source file:org.apache.cassandra.transport.Server.java

License:Apache License

private void run() {
    // Configure the server.
    eventExecutorGroup = new RequestThreadPoolExecutor();

    boolean hasEpoll = enableEpoll ? Epoll.isAvailable() : false;
    if (hasEpoll) {
        workerGroup = new EpollEventLoopGroup();
        logger.info("Netty using native Epoll event loop");
    } else {/* w  w w  . j  a va  2 s  .c o m*/
        workerGroup = new NioEventLoopGroup();
        logger.info("Netty using Java NIO event loop");
    }

    ServerBootstrap bootstrap = new ServerBootstrap().group(workerGroup)
            .channel(hasEpoll ? EpollServerSocketChannel.class : NioServerSocketChannel.class)
            .childOption(ChannelOption.TCP_NODELAY, true).childOption(ChannelOption.SO_LINGER, 0)
            .childOption(ChannelOption.SO_KEEPALIVE, DatabaseDescriptor.getRpcKeepAlive())
            .childOption(ChannelOption.ALLOCATOR, CBUtil.allocator)
            .childOption(ChannelOption.WRITE_BUFFER_HIGH_WATER_MARK, 32 * 1024)
            .childOption(ChannelOption.WRITE_BUFFER_LOW_WATER_MARK, 8 * 1024);

    final EncryptionOptions.ClientEncryptionOptions clientEnc = DatabaseDescriptor.getClientEncryptionOptions();
    if (clientEnc.enabled) {
        logger.info("Enabling encrypted CQL connections between client and server");
        bootstrap.childHandler(new SecureInitializer(this, clientEnc));
    } else {
        bootstrap.childHandler(new Initializer(this));
    }

    // Bind and start to accept incoming connections.
    logger.info("Using Netty Version: {}", Version.identify().entrySet());
    logger.info("Starting listening for CQL clients on {}...", socket);

    ChannelFuture bindFuture = bootstrap.bind(socket);
    if (!bindFuture.awaitUninterruptibly().isSuccess())
        throw new IllegalStateException(String.format("Failed to bind port %d on %s.", socket.getPort(),
                socket.getAddress().getHostAddress()));

    connectionTracker.allChannels.add(bindFuture.channel());
    isRunning.set(true);

    StorageService.instance.setRpcReady(true);
}