Example usage for io.netty.channel EventLoopGroup shutdownGracefully

List of usage examples for io.netty.channel EventLoopGroup shutdownGracefully

Introduction

In this page you can find the example usage for io.netty.channel EventLoopGroup shutdownGracefully.

Prototype

Future<?> shutdownGracefully(long quietPeriod, long timeout, TimeUnit unit);

Source Link

Document

Signals this executor that the caller wants the executor to be shut down.

Usage

From source file:cassandra.CassandraExecutor20.java

License:Apache License

public CassandraExecutor20(int binaryPort) {
    NettyOptions closeQuickly = new NettyOptions() {
        public void onClusterClose(EventLoopGroup eventLoopGroup) {
            //Shutdown immediately, since we close cluster when finished, we know nothing new coming through.
            eventLoopGroup.shutdownGracefully(0, 1000, TimeUnit.MILLISECONDS).syncUninterruptibly();
        }//from w ww  . j av a 2  s. c  o  m
    };
    cluster = Cluster.builder().addContactPoint(Config.NATIVE_HOST).withPort(binaryPort)
            .withNettyOptions(closeQuickly).build();
    session = cluster.connect(Config.KEYSPACE);
}

From source file:cassandra.CassandraExecutor21.java

License:Apache License

public CassandraExecutor21(int binaryPort) {
    NettyOptions closeQuickly = new NettyOptions() {
        public void onClusterClose(EventLoopGroup eventLoopGroup) {
            //Shutdown immediately, since we close cluster when finished, we know nothing new coming through.
            eventLoopGroup.shutdownGracefully(0, 1000, TimeUnit.MILLISECONDS).syncUninterruptibly();
        }// w  w  w.ja  v  a  2  s.  co  m
    };
    cluster = Cluster.builder().addContactPoint(Config.NATIVE_HOST).withPort(binaryPort)
            .withNettyOptions(closeQuickly).withTimestampGenerator(ServerSideTimestampGenerator.INSTANCE)
            .build();
    session = cluster.connect(KEYSPACE);
}

From source file:cassandra.CassandraExecutor30.java

License:Apache License

public CassandraExecutor30(int binaryPort) {
    NettyOptions closeQuickly = new NettyOptions() {
        public void onClusterClose(EventLoopGroup eventLoopGroup) {
            //Shutdown immediately, since we close cluster when finished, we know nothing new coming through.
            eventLoopGroup.shutdownGracefully(0, 1000, TimeUnit.MILLISECONDS).syncUninterruptibly();
        }//  w  w w .j  av  a2  s . com
    };
    cluster = Cluster.builder().addContactPoint(Config.NATIVE_HOST).withPort(binaryPort)
            .withQueryOptions(new QueryOptions().setConsistencyLevel(ConsistencyLevel.ONE))
            .withNettyOptions(closeQuickly).withTimestampGenerator(ServerSideTimestampGenerator.INSTANCE)
            .build();
    session = cluster.connect(Config.KEYSPACE);
}

From source file:com.mycompany.springboot.cassandra2.repository.LogTextRepositoryTest.java

@Before
public void setUp() {
    log.info("SETTING UP THE TEST KEYSPACE");
    Cluster cluster = Cluster.builder().addContactPoint("localhost").withPort(9042)
            .withNettyOptions(new NettyOptions() {
                @Override/*from w w  w  .j av a2s  .c  o m*/
                public void onClusterClose(EventLoopGroup eventLoopGroup) {
                    eventLoopGroup.shutdownGracefully(0, 0, TimeUnit.MILLISECONDS).syncUninterruptibly();
                }
            }).build();

    Session session = cluster.newSession();

    try {

        session.execute(String.format(
                "CREATE KEYSPACE IF NOT EXISTS %s \n"
                        + "WITH REPLICATION = { 'class' : 'SimpleStrategy', 'replication_factor' : 1 };",
                "test_junit"));
    } catch (Exception e) {
        log.error("KEYSPACE CREATION FAILED");
    } finally {
        session.close();
        cluster.close();
    }
}

From source file:com.mycompany.springboot.cassandra2.repository.LogTextRepositoryTest.java

@After
public void cleanUp() {
    log.info("DESTROYING THE TEST KEYSPACE");
    Cluster cluster = Cluster.builder().addContactPoint("localhost").withPort(9042)
            .withNettyOptions(new NettyOptions() {
                @Override//from   ww w . j  a va 2  s  .  c  o m
                public void onClusterClose(EventLoopGroup eventLoopGroup) {
                    eventLoopGroup.shutdownGracefully(0, 0, TimeUnit.MILLISECONDS).syncUninterruptibly();
                }
            }).build();

    Session session = cluster.newSession();

    try {

        session.execute("DROP KEYSPACE  test_junit ;");
    } catch (Exception e) {
        log.error("KEYSPACE DELETION FAILED", e);
    } finally {
        session.close();
        cluster.close();
    }
}

From source file:com.mycompany.springboot.cassandra2.RequiresCassandraKeyspace.java

License:Apache License

@Override
protected void before() throws Throwable {

    try (Socket socket = new Socket()) {
        socket.setTcpNoDelay(true);//from  w w  w  . j a v  a  2 s.  c  om
        socket.setSoLinger(true, 0);
        socket.connect(new InetSocketAddress(host, port), timeout);

    } catch (Exception e) {
        throw new AssumptionViolatedException(
                String.format("Seems as Cassandra is not running at %s:%s.", host, port), e);
    }

    Cluster cluster = Cluster.builder().addContactPoint(host).withPort(port)
            .withNettyOptions(new NettyOptions() {
                @Override
                public void onClusterClose(EventLoopGroup eventLoopGroup) {
                    eventLoopGroup.shutdownGracefully(0, 0, TimeUnit.MILLISECONDS).syncUninterruptibly();
                }
            }).build();

    Session session = cluster.newSession();

    try {

        if (requiresVersion != null) {

            Version cassandraReleaseVersion = CassandraVersion.getReleaseVersion(session);

            if (cassandraReleaseVersion.isLessThan(requiresVersion)) {
                throw new AssumptionViolatedException(
                        String.format("Cassandra at %s:%s runs in Version %s but we require at least %s", host,
                                port, cassandraReleaseVersion, requiresVersion));
            }
        }

        session.execute(String.format(
                "CREATE KEYSPACE IF NOT EXISTS %s \n"
                        + "WITH REPLICATION = { 'class' : 'SimpleStrategy', 'replication_factor' : 1 };",
                keyspaceName));
    } finally {
        session.close();
        cluster.close();
    }
}