All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.dropwizard.cassandra.CassandraBundle Maven / Gradle / Ivy

Go to download

Provides easy integration for Dropwizard applications with Apache Cassandra using the DataStax 4.x client

There is a newer version: 4.0.0
Show newest version
package io.dropwizard.cassandra;

import brave.Tracing;
import com.datastax.driver.core.Session;
import io.dropwizard.Configuration;
import io.dropwizard.ConfiguredBundle;
import io.dropwizard.setup.Bootstrap;
import io.dropwizard.setup.Environment;

import javax.annotation.Nullable;

import static java.util.Objects.requireNonNull;

public abstract class CassandraBundle implements ConfiguredBundle, CassandraConfiguration {
    @Nullable
    private Session session;

    @Override
    public void initialize(final Bootstrap bootstrap) {
        // do nothing
    }

    @Override
    public void run(final T configuration, final Environment environment) throws Exception {
        final CassandraFactory cassandraFactory = requireNonNull(getCassandraFactory(configuration));

        final Tracing tracing = Tracing.current();

        this.session = cassandraFactory.build(environment.metrics(), environment.lifecycle(), environment.healthChecks(), tracing);
    }

    public abstract CassandraFactory getCassandraFactory(T configuration);

    public Session getSession() {
        return requireNonNull(session);
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy