Skip to content
This repository was archived by the owner on Feb 5, 2020. It is now read-only.

Add configurability for timeouts to C* #46

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 34 additions & 1 deletion webapp/src/main/java/edu/si/trellis/CassandraContext.java
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,36 @@ public ConsistencyLevel rdfWriteConsistency() {
return rdfWriteConsistency;
}

@Inject
@Config(value = { "cassandra.connectionTimeout", "CASSANDRA_CONNECTION_TIMEOUT" }, defaultValue = "5000")
private int connectTimeoutMillis;

@Inject
@Config(value = { "cassandra.readTimeout", "CASSANDRA_READ_TIMEOUT" }, defaultValue = "12000")
private int readTimeoutMillis;

/**
* The timeout for making a connection to Cassandra, in ms. *
*
* @see SocketOptions#setReadTimeoutMillis(int)
*/
@Produces
@ConnectionTimeout
private int connectTimeoutMillis() {
return connectTimeoutMillis;
}

/**
* The timeout for reading from a connection to Cassandra, in ms.
*
* @see SocketOptions#setConnectTimeoutMillis(int)
*/
@Produces
@ReadTimeout
private int readTimeoutMillis() {
return readTimeoutMillis;
}

private Cluster cluster;

private Session session;
Expand All @@ -129,10 +159,13 @@ public ConsistencyLevel rdfWriteConsistency() {
@PostConstruct
public void connect() {
log.info("Using Cassandra node address: {} and port: {}", contactAddress, contactPort);
log.info("Using connection timeout: {} and read timeout: { in ms.}", connectTimeoutMillis, readTimeoutMillis);
log.debug("Looking for connection...");
SocketOptions socketOptions = new SocketOptions().setConnectTimeoutMillis(connectTimeoutMillis)
.setReadTimeoutMillis(readTimeoutMillis);
this.cluster = Cluster.builder().withTimestampGenerator(new AtomicMonotonicTimestampGenerator())
.withoutJMXReporting().withoutMetrics().addContactPoint(contactAddress)
.withPort(parseInt(contactPort)).build();
.withPort(parseInt(contactPort)).withSocketOptions(socketOptions).build();
if (log.isDebugEnabled()) cluster.register(QueryLogger.builder().build());
cluster.getConfiguration().getCodecRegistry().register(STANDARD_CODECS);
Timer connector = new Timer("Cassandra Connection Maker", true);
Expand Down
16 changes: 16 additions & 0 deletions webapp/src/main/java/edu/si/trellis/ConnectionTimeout.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package edu.si.trellis;

import static java.lang.annotation.RetentionPolicy.RUNTIME;

import java.lang.annotation.Documented;
import java.lang.annotation.Retention;

import javax.inject.Qualifier;

/**
* The timeout for making a connection to Cassandra, in ms.
*/
@Documented
@Retention(RUNTIME)
@Qualifier
public @interface ConnectionTimeout {}
18 changes: 18 additions & 0 deletions webapp/src/main/java/edu/si/trellis/ReadTimeout.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package edu.si.trellis;

import static java.lang.annotation.RetentionPolicy.RUNTIME;

import java.lang.annotation.Documented;
import java.lang.annotation.Retention;

import javax.inject.Qualifier;

/**
* The timeout for reading from a connection to Cassandra, in ms.
*/
@Documented
@Retention(RUNTIME)
@Qualifier
public @interface ReadTimeout {

}