io.dropwizard.cassandra.CassandraBundle Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of dropwizard-cassandra Show documentation
Show all versions of dropwizard-cassandra Show documentation
Provides easy integration for Dropwizard applications with Apache Cassandra using the DataStax 4.x client
package io.dropwizard.cassandra;
import brave.Tracing;
import com.datastax.oss.driver.api.core.CqlSession;
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 CqlSession 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 CqlSession getSession() {
return requireNonNull(session);
}
}