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

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

commit 3d8d5e1a9eeb69d4f10f34145739efcf1095b8d7
Author: Gautier DI FOLCO <gdifo...@linagora.com>
AuthorDate: Mon Aug 26 12:09:26 2019 +0200

    JAMES-2873 Inject Hostname in DistributedTaskManager
---
 .../apache/james/DistributedTaskManagerModule.java |  3 +-
 .../james/modules/server/HostnameModule.java       | 21 +---------
 .../META-INF/org/apache/james/spring-server.xml    |  5 ++-
 .../apache/james/task/eventsourcing/Events.scala   | 48 ++++++++++++++--------
 4 files changed, 38 insertions(+), 39 deletions(-)

diff --git 
a/server/container/guice/cassandra-rabbitmq-guice/src/main/java/org/apache/james/DistributedTaskManagerModule.java
 
b/server/container/guice/cassandra-rabbitmq-guice/src/main/java/org/apache/james/DistributedTaskManagerModule.java
index 6f1a294..f5cb955 100644
--- 
a/server/container/guice/cassandra-rabbitmq-guice/src/main/java/org/apache/james/DistributedTaskManagerModule.java
+++ 
b/server/container/guice/cassandra-rabbitmq-guice/src/main/java/org/apache/james/DistributedTaskManagerModule.java
@@ -20,6 +20,7 @@
 
 package org.apache.james;
 
+import org.apache.james.modules.server.HostnameModule;
 import org.apache.james.task.MemoryWorkQueue;
 import org.apache.james.task.SerialTaskManagerWorker;
 import org.apache.james.task.TaskManager;
@@ -34,7 +35,6 @@ import com.google.inject.AbstractModule;
 import com.google.inject.Scopes;
 
 public class DistributedTaskManagerModule extends AbstractModule {
-
     public static final WorkQueueSupplier workQueueSupplier = 
eventSourcingSystem -> {
         WorkerStatusListener listener = new 
WorkerStatusListener(eventSourcingSystem);
         TaskManagerWorker worker = new SerialTaskManagerWorker(listener);
@@ -43,6 +43,7 @@ public class DistributedTaskManagerModule extends 
AbstractModule {
 
     @Override
     protected void configure() {
+        install(new HostnameModule());
         bind(TaskExecutionDetailsProjection.class).in(Scopes.SINGLETON);
         bind(TaskManager.class).in(Scopes.SINGLETON);
         bind(WorkQueueSupplier.class).in(Scopes.SINGLETON);
diff --git 
a/server/container/guice/guice-common/src/main/java/org/apache/james/modules/server/HostnameModule.java
 
b/server/container/guice/guice-common/src/main/java/org/apache/james/modules/server/HostnameModule.java
index 6607a74..de590a1 100644
--- 
a/server/container/guice/guice-common/src/main/java/org/apache/james/modules/server/HostnameModule.java
+++ 
b/server/container/guice/guice-common/src/main/java/org/apache/james/modules/server/HostnameModule.java
@@ -20,32 +20,13 @@
 
 package org.apache.james.modules.server;
 
-import java.net.InetAddress;
-import java.net.UnknownHostException;
-
 import org.apache.james.task.eventsourcing.Hostname;
 
 import com.google.inject.AbstractModule;
-import com.google.inject.Scopes;
 
 public class HostnameModule extends AbstractModule {
-    private static class UnconfigurableHostnameException extends 
RuntimeException {
-        UnconfigurableHostnameException(String message, Exception 
originException) {
-            super(message, originException);
-        }
-    }
-
     @Override
     protected void configure() {
-        bind(Hostname.class).in(Scopes.SINGLETON);
-        bind(Hostname.class).toInstance(getHostname());
-    }
-
-    private Hostname getHostname() {
-        try {
-            return new Hostname(InetAddress.getLocalHost().getHostName());
-        } catch (UnknownHostException e) {
-            throw new UnconfigurableHostnameException("Hostname can not be 
retrieved, unable to initialize the distributed task manager", e);
-        }
+        bind(Hostname.class).toInstance(Hostname.fromLocalHostname());
     }
 }
diff --git 
a/server/container/spring/src/main/resources/META-INF/org/apache/james/spring-server.xml
 
b/server/container/spring/src/main/resources/META-INF/org/apache/james/spring-server.xml
index 9456080..49b7a48 100644
--- 
a/server/container/spring/src/main/resources/META-INF/org/apache/james/spring-server.xml
+++ 
b/server/container/spring/src/main/resources/META-INF/org/apache/james/spring-server.xml
@@ -285,7 +285,10 @@
     <bean id="sievemanagerbean" 
class="org.apache.james.sieverepository.lib.SieveRepositoryManagement"/>
 
 
-    <bean id="taskManager" class="org.apache.james.task.MemoryTaskManager"/>
+    <bean id="hostname" class="org.apache.james.task.eventsourcing.Hostname" 
factory-method="fromLocalHostname" />
+    <bean id="taskManager" class="org.apache.james.task.MemoryTaskManager">
+        <constructor-arg index="0" ref="hostname"/>
+    </bean>
     <!--
         <bean id="james23importermanagement" 
class="org.apache.james.container.spring.tool.James23ImporterManagement" />
     -->
diff --git 
a/server/task/src/main/scala/org/apache/james/task/eventsourcing/Events.scala 
b/server/task/src/main/scala/org/apache/james/task/eventsourcing/Events.scala
index fa0607e..6d9c7ba 100644
--- 
a/server/task/src/main/scala/org/apache/james/task/eventsourcing/Events.scala
+++ 
b/server/task/src/main/scala/org/apache/james/task/eventsourcing/Events.scala
@@ -1,23 +1,25 @@
 /** **************************************************************
-  * 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.                                           *
-  * ***************************************************************/
+ * 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.task.eventsourcing
 
+import java.net.{InetAddress, UnknownHostException}
+
 import org.apache.james.eventsourcing.{Event, EventId}
 import org.apache.james.task.Task
 import org.apache.james.task.Task.Result
@@ -30,6 +32,18 @@ case class Hostname(private val value: String) {
   def asString: String = value
 }
 
+object Hostname {
+  def fromLocalHostname = try new 
Hostname(InetAddress.getLocalHost.getHostName)
+  catch {
+    case e: UnknownHostException =>
+      throw new UnconfigurableHostnameException("Hostname can not be 
retrieved", e)
+  }
+}
+
+private class UnconfigurableHostnameException(val message: String, val 
originException: Exception) extends RuntimeException(message, originException) {
+}
+
+
 case class Created(aggregateId: TaskAggregateId, override val eventId: 
EventId, task: Task, hostname: Hostname) extends TaskEvent(aggregateId, eventId)
 
 case class Started(aggregateId: TaskAggregateId, override val eventId: 
EventId, hostname: Hostname) extends TaskEvent(aggregateId, eventId)


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

Reply via email to