Example usage for org.apache.cassandra.service CassandraDaemon activate

List of usage examples for org.apache.cassandra.service CassandraDaemon activate

Introduction

In this page you can find the example usage for org.apache.cassandra.service CassandraDaemon activate.

Prototype

public void activate() 

Source Link

Document

A convenience method to initialize and start the daemon in one shot.

Usage

From source file:com.facebook.presto.cassandra.EmbeddedCassandra.java

License:Apache License

public static synchronized void start() throws Exception {
    if (initialized) {
        return;// w  w w.  j  a v  a 2s . c o  m
    }

    log.info("Starting cassandra...");

    System.setProperty("cassandra.config", "file:" + prepareCassandraYaml());
    System.setProperty("cassandra-foreground", "true");
    System.setProperty("cassandra.native.epoll.enabled", "false");

    CassandraDaemon cassandraDaemon = new CassandraDaemon();
    cassandraDaemon.activate();

    Cluster.Builder clusterBuilder = Cluster.builder().withProtocolVersion(V3).withClusterName("TestCluster")
            .addContactPointsWithPorts(ImmutableList.of(new InetSocketAddress(HOST, PORT)))
            .withMaxSchemaAgreementWaitSeconds(30);

    ReopeningCluster cluster = new ReopeningCluster(clusterBuilder::build);
    CassandraSession session = new NativeCassandraSession("EmbeddedCassandra",
            JsonCodec.listJsonCodec(ExtraColumnMetadata.class), cluster, new Duration(1, MINUTES));

    try {
        checkConnectivity(session);
    } catch (RuntimeException e) {
        cluster.close();
        cassandraDaemon.deactivate();
        throw e;
    }

    EmbeddedCassandra.session = session;
    initialized = true;
}

From source file:grakn.core.server.GraknStorage.java

License:Open Source License

public static void main(String[] args) {
    try {//www . j  a  v  a2  s.co m
        CassandraDaemon instance = new CassandraDaemon();
        instance.activate();
        persistPID();
    } catch (Exception e) {
        LOG.error("Cassandra Exception:", e);
        System.err.println(e.getMessage());
    }
}

From source file:info.archinnov.achilles.embedded.ServerStarter.java

License:Apache License

private void start(final CassandraConfig config) {

    if (isAlreadyRunning()) {
        log.debug("Cassandra is already running, not starting new one");
        return;//from  w ww  .ja  va2  s  .  com
    }

    final String triggersDir = createTriggersFolder();

    log.info(" Random embedded Cassandra RPC port/Thrift port = {}", config.getRPCPort());
    log.info(" Random embedded Cassandra Native port/CQL3 port = {}", config.getCqlPort());
    log.info(" Random embedded Cassandra Storage port = {}", config.getStoragePort());
    log.info(" Random embedded Cassandra Storage SSL port = {}", config.getStorageSSLPort());
    log.info(" Embedded Cassandra triggers directory = {}", triggersDir);

    log.info("Starting Cassandra...");
    config.write();

    System.setProperty("cassandra.triggers_dir", triggersDir);
    System.setProperty("cassandra.config", "file:" + config.getConfigFile().getAbsolutePath());
    System.setProperty("cassandra-foreground", "true");

    final CountDownLatch startupLatch = new CountDownLatch(1);
    executor = Executors.newSingleThreadExecutor();
    executor.execute(new Runnable() {
        @Override
        public void run() {
            CassandraDaemon cassandraDaemon = new CassandraDaemon();
            cassandraDaemon.activate();
            startupLatch.countDown();
        }
    });

    try {
        startupLatch.await(30, SECONDS);
    } catch (InterruptedException e) {
        log.error("Timeout starting Cassandra embedded", e);
        throw new IllegalStateException("Timeout starting Cassandra embedded", e);
    }
}

From source file:io.prestosql.plugin.cassandra.EmbeddedCassandra.java

License:Apache License

public static synchronized void start() throws Exception {
    if (initialized) {
        return;/*from   w w  w.  j  av  a2  s  . c o m*/
    }

    log.info("Starting cassandra...");

    System.setProperty("cassandra.config", "file:" + prepareCassandraYaml());
    System.setProperty("cassandra-foreground", "true");
    System.setProperty("cassandra.native.epoll.enabled", "false");

    CassandraDaemon cassandraDaemon = new CassandraDaemon();
    cassandraDaemon.activate();

    Cluster.Builder clusterBuilder = Cluster.builder().withProtocolVersion(V3).withClusterName("TestCluster")
            .addContactPointsWithPorts(ImmutableList.of(new InetSocketAddress(HOST, PORT)))
            .withMaxSchemaAgreementWaitSeconds(30);

    ReopeningCluster cluster = new ReopeningCluster(clusterBuilder::build);
    CassandraSession session = new NativeCassandraSession(JsonCodec.listJsonCodec(ExtraColumnMetadata.class),
            cluster, new Duration(1, MINUTES));

    try {
        checkConnectivity(session);
    } catch (RuntimeException e) {
        cluster.close();
        cassandraDaemon.deactivate();
        throw e;
    }

    EmbeddedCassandra.session = session;
    initialized = true;
}

From source file:org.springframework.cassandra.test.integration.EmbeddedCassandraServerHelper.java

License:Apache License

/**
 * Set embedded cassandra up and spawn it in a new thread.
 *//*from ww w . j  a  v a 2s . com*/
private static void startEmbeddedCassandra(File file, long timeout) throws Exception {

    checkConfigNameForRestart(file.getAbsolutePath());

    log.debug("Starting cassandra...");
    log.debug("Initialization needed");

    System.setProperty("cassandra.config", "file:" + file.getAbsolutePath());
    System.setProperty("cassandra-foreground", "true");
    System.setProperty("cassandra.native.epoll.enabled", "false"); // JNA doesn't cope with relocated netty

    cleanupAndRecreateDirectories();

    final CassandraDaemon cassandraDaemon = new CassandraDaemon();
    ExecutorService executor = Executors.newSingleThreadExecutor();
    Future<?> future = executor.submit(new Runnable() {
        @Override
        public void run() {
            cassandraDaemon.activate();
            cassandraRef.compareAndSet(null, cassandraDaemon);
        }
    });

    try {
        future.get(timeout, MILLISECONDS);
    } catch (ExecutionException e) {

        log.error("Cassandra daemon did not start after " + timeout + " ms. Consider increasing the timeout");
        throw new IllegalStateException("Cassandra daemon did not start within timeout", e);
    } catch (InterruptedException e) {

        log.error("Interrupted waiting for Cassandra daemon to start:", e);
        Thread.currentThread().interrupt();

        throw new IllegalStateException(e);
    } finally {
        executor.shutdown();
    }
}

From source file:org.springframework.data.cassandra.test.util.EmbeddedCassandraServerHelper.java

License:Apache License

/**
 * Set embedded cassandra up and spawn it in a new thread.
 *//*from   www.  jav a2  s  . co  m*/
private static void startEmbeddedCassandra(File file, long timeout) throws Exception {

    checkConfigNameForRestart(file.getAbsolutePath());

    log.debug("Starting cassandra...");
    log.debug("Initialization needed");

    System.setProperty("cassandra.config", "file:" + file.getAbsolutePath());
    System.setProperty("cassandra-foreground", "true");
    System.setProperty("cassandra.native.epoll.enabled", "false"); // JNA doesn't cope with relocated netty

    cleanupAndRecreateDirectories();

    CassandraDaemon cassandraDaemon = new CassandraDaemon();

    ExecutorService executor = Executors.newSingleThreadExecutor();

    Future<?> future = executor.submit(() -> {
        cassandraDaemon.activate();
        cassandraRef.compareAndSet(null, cassandraDaemon);
    });

    try {
        future.get(timeout, MILLISECONDS);
    } catch (ExecutionException cause) {

        log.error("Cassandra daemon did not start after " + timeout + " ms. Consider increasing the timeout");

        throw new IllegalStateException("Cassandra daemon did not start within timeout", cause);
    } catch (InterruptedException cause) {

        log.error("Interrupted waiting for Cassandra daemon to start:", cause);
        Thread.currentThread().interrupt();

        throw new IllegalStateException(cause);
    } finally {
        executor.shutdown();
    }
}

From source file:org.springframework.data.cql.EmbeddedCassandraServerHelper.java

License:Apache License

/**
 * Set embedded cassandra up and spawn it in a new thread.
 *//*from   ww  w . ja v  a 2  s. c  o  m*/
private static void startEmbeddedCassandra(File file, long timeout) throws Exception {

    checkConfigNameForRestart(file.getAbsolutePath());

    log.debug("Starting cassandra...");
    log.debug("Initialization needed");

    System.setProperty("cassandra.config", "file:" + file.getAbsolutePath());
    System.setProperty("cassandra-foreground", "true");
    System.setProperty("cassandra.native.epoll.enabled", "false"); // JNA doesn't cope with relocated netty

    cleanupAndRecreateDirectories();

    final CassandraDaemon cassandraDaemon = new CassandraDaemon();
    ExecutorService executor = Executors.newSingleThreadExecutor();
    Future<?> future = executor.submit(() -> {
        cassandraDaemon.activate();
        cassandraRef.compareAndSet(null, cassandraDaemon);
    });

    try {
        future.get(timeout, MILLISECONDS);
    } catch (ExecutionException e) {

        log.error("Cassandra daemon did not start after " + timeout + " ms. Consider increasing the timeout");
        throw new IllegalStateException("Cassandra daemon did not start within timeout", e);
    } catch (InterruptedException e) {

        log.error("Interrupted waiting for Cassandra daemon to start:", e);
        Thread.currentThread().interrupt();

        throw new IllegalStateException(e);
    } finally {
        executor.shutdown();
    }
}