You are viewing a plain text version of this content. The canonical link for it is here.
Posted to server-dev@james.apache.org by bt...@apache.org on 2019/05/30 07:22:29 UTC

[james-project] 18/19: JAMES-2763 Split ES Client module in ES mailbox module

This is an automated email from the ASF dual-hosted git repository.

btellier pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/james-project.git

commit 28d8aab1f20c4db5b4dbb170be02052b6c5341e1
Author: Tran Tien Duc <dt...@linagora.com>
AuthorDate: Tue May 28 15:46:12 2019 +0700

    JAMES-2763 Split ES Client module in ES mailbox module
---
 .../org/apache/james/CassandraJamesServerMain.java |  2 +
 .../modules/mailbox/ElasticSearchClientModule.java | 67 ++++++++++++++++++++++
 .../mailbox/ElasticSearchMailboxModule.java        | 28 ---------
 3 files changed, 69 insertions(+), 28 deletions(-)

diff --git a/server/container/guice/cassandra-guice/src/main/java/org/apache/james/CassandraJamesServerMain.java b/server/container/guice/cassandra-guice/src/main/java/org/apache/james/CassandraJamesServerMain.java
index ee05ad2..d7f5ddd 100644
--- a/server/container/guice/cassandra-guice/src/main/java/org/apache/james/CassandraJamesServerMain.java
+++ b/server/container/guice/cassandra-guice/src/main/java/org/apache/james/CassandraJamesServerMain.java
@@ -35,6 +35,7 @@ import org.apache.james.modules.mailbox.CassandraMailboxModule;
 import org.apache.james.modules.mailbox.CassandraObjectStoreModule;
 import org.apache.james.modules.mailbox.CassandraQuotaMailingModule;
 import org.apache.james.modules.mailbox.CassandraSessionModule;
+import org.apache.james.modules.mailbox.ElasticSearchClientModule;
 import org.apache.james.modules.mailbox.ElasticSearchMailboxModule;
 import org.apache.james.modules.mailbox.TikaMailboxModule;
 import org.apache.james.modules.metrics.CassandraMetricsModule;
@@ -119,6 +120,7 @@ public class CassandraJamesServerMain {
     public static final Module CASSANDRA_MAILBOX_MODULE = Modules.combine(
         new CassandraMailboxModule(),
         new DeletedMessageVaultModule(),
+        new ElasticSearchClientModule(),
         new ElasticSearchMailboxModule(),
         new ElasticSearchMetricReporterModule(),
         new MailboxModule(),
diff --git a/server/container/guice/cassandra-guice/src/main/java/org/apache/james/modules/mailbox/ElasticSearchClientModule.java b/server/container/guice/cassandra-guice/src/main/java/org/apache/james/modules/mailbox/ElasticSearchClientModule.java
new file mode 100644
index 0000000..96350a1
--- /dev/null
+++ b/server/container/guice/cassandra-guice/src/main/java/org/apache/james/modules/mailbox/ElasticSearchClientModule.java
@@ -0,0 +1,67 @@
+/****************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one   *
+ * or more contributor license agreements.  See the NOTICE file *
+ * distributed with this work for additional information        *
+ * regarding copyright ownership.  The ASF licenses this file   *
+ * to you under the Apache License, Version 2.0 (the            *
+ * "License"); you may not use this file except in compliance   *
+ * with the License.  You may obtain a copy of the License at   *
+ *                                                              *
+ *   http://www.apache.org/licenses/LICENSE-2.0                 *
+ *                                                              *
+ * Unless required by applicable law or agreed to in writing,   *
+ * software distributed under the License is distributed on an  *
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY       *
+ * KIND, either express or implied.  See the License for the    *
+ * specific language governing permissions and limitations      *
+ * under the License.                                           *
+ ****************************************************************/
+
+package org.apache.james.modules.mailbox;
+
+import java.io.IOException;
+import java.time.Duration;
+import java.time.LocalDateTime;
+
+import javax.inject.Singleton;
+
+import org.apache.commons.lang3.time.DurationFormatUtils;
+import org.apache.james.backends.es.ClientProviderImpl;
+import org.apache.james.backends.es.ElasticSearchConfiguration;
+import org.elasticsearch.client.RestHighLevelClient;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import com.google.inject.AbstractModule;
+import com.google.inject.Provides;
+
+import reactor.core.publisher.Mono;
+import reactor.core.scheduler.Schedulers;
+
+public class ElasticSearchClientModule extends AbstractModule {
+
+    private static final Logger LOGGER = LoggerFactory.getLogger(ElasticSearchClientModule.class);
+
+    @Override
+    protected void configure() {
+    }
+
+    @Provides
+    @Singleton
+    protected RestHighLevelClient provideClient(ElasticSearchConfiguration configuration) {
+        Duration waitDelay = Duration.ofMillis(configuration.getMinDelay());
+        return Mono.fromCallable(() -> connectToCluster(configuration))
+            .doOnError(e -> LOGGER.warn("Error establishing ElasticSearch connection. Next retry scheduled in {}",
+                DurationFormatUtils.formatDurationWords(waitDelay.toMillis(), true, true), e))
+            .retryBackoff(configuration.getMaxRetries(), waitDelay, waitDelay)
+            .publishOn(Schedulers.elastic())
+            .block();
+    }
+
+    private RestHighLevelClient connectToCluster(ElasticSearchConfiguration configuration) throws IOException {
+        LOGGER.info("Trying to connect to ElasticSearch service at {}", LocalDateTime.now());
+
+        return ClientProviderImpl.fromHosts(configuration.getHosts(), configuration.getClusterName())
+            .get();
+    }
+}
diff --git a/server/container/guice/cassandra-guice/src/main/java/org/apache/james/modules/mailbox/ElasticSearchMailboxModule.java b/server/container/guice/cassandra-guice/src/main/java/org/apache/james/modules/mailbox/ElasticSearchMailboxModule.java
index 46e1803..907ae76 100644
--- a/server/container/guice/cassandra-guice/src/main/java/org/apache/james/modules/mailbox/ElasticSearchMailboxModule.java
+++ b/server/container/guice/cassandra-guice/src/main/java/org/apache/james/modules/mailbox/ElasticSearchMailboxModule.java
@@ -23,8 +23,6 @@ import static org.apache.james.mailbox.elasticsearch.search.ElasticSearchSearche
 
 import java.io.FileNotFoundException;
 import java.io.IOException;
-import java.time.Duration;
-import java.time.LocalDateTime;
 import java.util.List;
 
 import javax.inject.Inject;
@@ -33,8 +31,6 @@ import javax.inject.Singleton;
 
 import org.apache.commons.configuration.Configuration;
 import org.apache.commons.configuration.ConfigurationException;
-import org.apache.commons.lang3.time.DurationFormatUtils;
-import org.apache.james.backends.es.ClientProviderImpl;
 import org.apache.james.backends.es.ElasticSearchConfiguration;
 import org.apache.james.backends.es.ElasticSearchIndexer;
 import org.apache.james.lifecycle.api.StartUpCheck;
@@ -63,9 +59,6 @@ import com.google.inject.Provides;
 import com.google.inject.Scopes;
 import com.google.inject.multibindings.Multibinder;
 
-import reactor.core.publisher.Mono;
-import reactor.core.scheduler.Schedulers;
-
 public class ElasticSearchMailboxModule extends AbstractModule {
 
     static class MailboxIndexCreator implements Startable {
@@ -194,27 +187,6 @@ public class ElasticSearchMailboxModule extends AbstractModule {
 
     @Provides
     @Singleton
-    protected RestHighLevelClient provideClient(ElasticSearchConfiguration configuration) {
-
-        Duration waitDelay = Duration.ofMillis(configuration.getMinDelay());
-        return Mono.fromCallable(() -> connectToCluster(configuration))
-            .doOnError(e -> LOGGER.warn("Error establishing ElasticSearch connection. Next retry scheduled in {}",
-                DurationFormatUtils.formatDurationWords(waitDelay.toMillis(), true, true),
-                e))
-            .retryBackoff(configuration.getMaxRetries(), waitDelay, waitDelay)
-            .publishOn(Schedulers.elastic())
-            .block();
-    }
-
-    private RestHighLevelClient connectToCluster(ElasticSearchConfiguration configuration) throws IOException {
-        LOGGER.info("Trying to connect to ElasticSearch service at {}", LocalDateTime.now());
-
-        return ClientProviderImpl.fromHosts(configuration.getHosts(), configuration.getClusterName())
-            .get();
-    }
-
-    @Provides
-    @Singleton
     public IndexAttachments provideIndexAttachments(ElasticSearchMailboxConfiguration configuration) {
         return configuration.getIndexAttachment();
     }


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