james-server-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From btell...@apache.org
Subject [1/4] james-project git commit: JAMES-2012 Add the Cassandra TCP connection timeout
Date Wed, 03 May 2017 03:41:06 GMT
Repository: james-project
Updated Branches:
  refs/heads/master bab5ff434 -> 302a763db


JAMES-2012 Add the Cassandra TCP connection timeout


Project: http://git-wip-us.apache.org/repos/asf/james-project/repo
Commit: http://git-wip-us.apache.org/repos/asf/james-project/commit/f4b51ba2
Tree: http://git-wip-us.apache.org/repos/asf/james-project/tree/f4b51ba2
Diff: http://git-wip-us.apache.org/repos/asf/james-project/diff/f4b51ba2

Branch: refs/heads/master
Commit: f4b51ba26692d3f6b3de0f1b27696d6f22e51699
Parents: bab5ff4
Author: Antoine Duprat <aduprat@linagora.com>
Authored: Tue May 2 09:51:40 2017 +0200
Committer: benwa <btellier@linagora.com>
Committed: Wed May 3 10:40:03 2017 +0700

----------------------------------------------------------------------
 .../backends/cassandra/init/ClusterBuilder.java     | 14 +++++++++++---
 .../modules/mailbox/CassandraSessionModule.java     | 16 +++++++---------
 server/src/site/xdoc/config-cassandra.xml           |  7 ++++++-
 3 files changed, 24 insertions(+), 13 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/james-project/blob/f4b51ba2/backends-common/cassandra/src/main/java/org/apache/james/backends/cassandra/init/ClusterBuilder.java
----------------------------------------------------------------------
diff --git a/backends-common/cassandra/src/main/java/org/apache/james/backends/cassandra/init/ClusterBuilder.java
b/backends-common/cassandra/src/main/java/org/apache/james/backends/cassandra/init/ClusterBuilder.java
index 2a89280..e5760aa 100644
--- a/backends-common/cassandra/src/main/java/org/apache/james/backends/cassandra/init/ClusterBuilder.java
+++ b/backends-common/cassandra/src/main/java/org/apache/james/backends/cassandra/init/ClusterBuilder.java
@@ -51,6 +51,7 @@ public class ClusterBuilder {
 
     private Optional<QueryLoggerConfiguration> queryLogger;
     private Optional<Integer> readTimeoutMillis;
+    private Optional<Integer> connectTimeoutMillis;
 
     private ClusterBuilder() {
         username = Optional.empty();
@@ -65,6 +66,7 @@ public class ClusterBuilder {
 
         queryLogger = Optional.empty();
         readTimeoutMillis = Optional.empty();
+        connectTimeoutMillis = Optional.empty();
     }
 
     public ClusterBuilder username(String username) {
@@ -126,6 +128,11 @@ public class ClusterBuilder {
         return this;
     }
 
+    public ClusterBuilder connectTimeoutMillis(int connectTimeoutMillis) {
+        this.connectTimeoutMillis = Optional.of(connectTimeoutMillis);
+        return this;
+    }
+
     public Cluster build() {
         Preconditions.checkState(!(servers.isPresent() && host.isPresent()), "You
can't specify a list of servers and a host at the same time");
         Preconditions.checkState(!(servers.isPresent() && port.isPresent()), "You
can't specify a list of servers and a port at the same time");
@@ -146,9 +153,10 @@ public class ClusterBuilder {
                 new QueryOptions()
                     .setRefreshSchemaIntervalMillis(refreshSchemaIntervalMillis)));
 
-        readTimeoutMillis.map(timeout ->
-            clusterBuilder.withSocketOptions(
-                    new SocketOptions().setReadTimeoutMillis(timeout)));
+        SocketOptions socketOptions = new SocketOptions();
+        readTimeoutMillis.ifPresent(socketOptions::setReadTimeoutMillis);
+        connectTimeoutMillis.ifPresent(socketOptions::setConnectTimeoutMillis);
+        clusterBuilder.withSocketOptions(socketOptions);
 
         Cluster cluster = clusterBuilder.build();
 

http://git-wip-us.apache.org/repos/asf/james-project/blob/f4b51ba2/server/container/guice/cassandra-guice/src/main/java/org/apache/james/modules/mailbox/CassandraSessionModule.java
----------------------------------------------------------------------
diff --git a/server/container/guice/cassandra-guice/src/main/java/org/apache/james/modules/mailbox/CassandraSessionModule.java
b/server/container/guice/cassandra-guice/src/main/java/org/apache/james/modules/mailbox/CassandraSessionModule.java
index 7aaa6d9..497f418 100644
--- a/server/container/guice/cassandra-guice/src/main/java/org/apache/james/modules/mailbox/CassandraSessionModule.java
+++ b/server/container/guice/cassandra-guice/src/main/java/org/apache/james/modules/mailbox/CassandraSessionModule.java
@@ -66,6 +66,7 @@ public class CassandraSessionModule extends AbstractModule {
     private static final String CASSANDRA_NODES = "cassandra.nodes";
     private static final String LOCALHOST = "127.0.0.1";
     private static final int DEFAULT_READ_TIMEOUT_MILLIS = 5000;
+    private static final int DEFAULT_CONNECT_TIMEOUT_MILLIS = 5000;
 
 
     @Override
@@ -115,20 +116,17 @@ public class CassandraSessionModule extends AbstractModule {
         LOGGER.info("Trying to connect to Cassandra service");
 
         return context -> ClusterWithKeyspaceCreatedFactory
-            .config(getCluster(servers, queryLoggerConfiguration, configuration.getInt("cassandra.readTimeoutMillis",
DEFAULT_READ_TIMEOUT_MILLIS)), 
+            .config(ClusterBuilder.builder()
+                    .servers(servers)
+                    .queryLoggerConfiguration(queryLoggerConfiguration)
+                    .readTimeoutMillis(configuration.getInt("cassandra.readTimeoutMillis",
DEFAULT_READ_TIMEOUT_MILLIS))
+                    .connectTimeoutMillis(configuration.getInt("cassandra.connectTimeoutMillis",
DEFAULT_CONNECT_TIMEOUT_MILLIS))
+                    .build(),
                     configuration.getString("cassandra.keyspace", DEFAULT_KEYSPACE))
             .replicationFactor(configuration.getInt("cassandra.replication.factor", DEFAULT_REPLICATION_FACTOR))
             .clusterWithInitializedKeyspace();
     }
 
-    private Cluster getCluster(List<Host> servers, QueryLoggerConfiguration queryLoggerConfiguration,
int readTimeoutMillis) {
-        return ClusterBuilder.builder()
-            .servers(servers)
-            .queryLoggerConfiguration(queryLoggerConfiguration)
-            .readTimeoutMillis(readTimeoutMillis)
-            .build();
-    }
-
     private List<Host> listCassandraServers(PropertiesConfiguration configuration)
{
         String[] ipAndPorts = configuration.getStringArray(CASSANDRA_NODES);
 

http://git-wip-us.apache.org/repos/asf/james-project/blob/f4b51ba2/server/src/site/xdoc/config-cassandra.xml
----------------------------------------------------------------------
diff --git a/server/src/site/xdoc/config-cassandra.xml b/server/src/site/xdoc/config-cassandra.xml
index e6c3a7d..4b4145b 100644
--- a/server/src/site/xdoc/config-cassandra.xml
+++ b/server/src/site/xdoc/config-cassandra.xml
@@ -63,7 +63,12 @@
 
         <dt><strong>cassandra.readTimeoutMillis</strong></dt>
         <dd>Optional.
-          If specified defines the Cassandra <a href="http://docs.datastax.com/en/developer/java-driver/2.1/manual/socket_options/"">driver
read timeout</a></dd>
+          If specified defines the Cassandra <a href="http://docs.datastax.com/en/developer/java-driver/2.1/manual/socket_options/">driver
read timeout</a></dd>
+          
+        <dt><strong>cassandra.conectTimeoutMillis</strong></dt>
+        <dd>Optional.
+          If specified defines the Cassandra <a href="http://docs.datastax.com/en/developer/java-driver/2.1/manual/socket_options/">TCP
connect timeout</a></dd>
+          
       </dl>
 
 


---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org


Mime
View raw message