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 2018/07/20 11:19:37 UTC
[05/10] james-project git commit: JAMES-2470 Introduce a clean stage
in Guice
JAMES-2470 Introduce a clean stage in Guice
Project: http://git-wip-us.apache.org/repos/asf/james-project/repo
Commit: http://git-wip-us.apache.org/repos/asf/james-project/commit/c1ae8261
Tree: http://git-wip-us.apache.org/repos/asf/james-project/tree/c1ae8261
Diff: http://git-wip-us.apache.org/repos/asf/james-project/diff/c1ae8261
Branch: refs/heads/master
Commit: c1ae826101d96d1b4f170d6a3a535cd661e59cee
Parents: 1afb716
Author: benwa <bt...@linagora.com>
Authored: Thu Jul 19 17:22:08 2018 +0700
Committer: benwa <bt...@linagora.com>
Committed: Fri Jul 20 18:18:14 2018 +0700
----------------------------------------------------------------------
.../org/apache/james/CleanupTasksPerformer.java | 48 ++++++++++++++++++++
.../java/org/apache/james/GuiceJamesServer.java | 4 ++
.../apache/james/modules/CleanupTaskModule.java | 32 +++++++++++++
.../james/modules/CommonServicesModule.java | 1 +
4 files changed, 85 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/james-project/blob/c1ae8261/server/container/guice/guice-common/src/main/java/org/apache/james/CleanupTasksPerformer.java
----------------------------------------------------------------------
diff --git a/server/container/guice/guice-common/src/main/java/org/apache/james/CleanupTasksPerformer.java b/server/container/guice/guice-common/src/main/java/org/apache/james/CleanupTasksPerformer.java
new file mode 100644
index 0000000..cb7d21b
--- /dev/null
+++ b/server/container/guice/guice-common/src/main/java/org/apache/james/CleanupTasksPerformer.java
@@ -0,0 +1,48 @@
+/****************************************************************
+ * 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;
+
+import java.util.Set;
+
+import javax.inject.Inject;
+
+import org.apache.james.task.Task;
+import org.apache.james.task.TaskManager;
+
+public class CleanupTasksPerformer {
+
+ public interface CleanupTask extends Task {
+
+ }
+
+ private final TaskManager taskManager;
+ private final Set<CleanupTask> cleanupTasks;
+
+ @Inject
+ public CleanupTasksPerformer(TaskManager taskManager, Set<CleanupTask> cleanupTasks) {
+ this.taskManager = taskManager;
+ this.cleanupTasks = cleanupTasks;
+ }
+
+ public void clean() {
+ cleanupTasks.forEach(Task::run);
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/james-project/blob/c1ae8261/server/container/guice/guice-common/src/main/java/org/apache/james/GuiceJamesServer.java
----------------------------------------------------------------------
diff --git a/server/container/guice/guice-common/src/main/java/org/apache/james/GuiceJamesServer.java b/server/container/guice/guice-common/src/main/java/org/apache/james/GuiceJamesServer.java
index 6b774c5..b43996c 100644
--- a/server/container/guice/guice-common/src/main/java/org/apache/james/GuiceJamesServer.java
+++ b/server/container/guice/guice-common/src/main/java/org/apache/james/GuiceJamesServer.java
@@ -20,6 +20,7 @@ package org.apache.james;
import java.util.Arrays;
import java.util.List;
+import java.util.Optional;
import javax.annotation.PreDestroy;
@@ -44,6 +45,7 @@ public class GuiceJamesServer {
protected final Module module;
private Stager<PreDestroy> preDestroy;
private GuiceProbeProvider guiceProbeProvider;
+ private CleanupTasksPerformer cleanupTasksPerformer;
private boolean isStarted = false;
public GuiceJamesServer(Configuration configuration) {
@@ -73,10 +75,12 @@ public class GuiceJamesServer {
preDestroy = injector.getInstance(Key.get(new TypeLiteral<Stager<PreDestroy>>() {}));
injector.getInstance(ConfigurationsPerformer.class).initModules();
guiceProbeProvider = injector.getInstance(GuiceProbeProvider.class);
+ cleanupTasksPerformer = injector.getInstance(CleanupTasksPerformer.class);
isStarted = true;
}
public void stop() {
+ Optional.ofNullable(cleanupTasksPerformer).ifPresent(CleanupTasksPerformer::clean);
if (preDestroy != null) {
preDestroy.stage();
isStarted = false;
http://git-wip-us.apache.org/repos/asf/james-project/blob/c1ae8261/server/container/guice/guice-common/src/main/java/org/apache/james/modules/CleanupTaskModule.java
----------------------------------------------------------------------
diff --git a/server/container/guice/guice-common/src/main/java/org/apache/james/modules/CleanupTaskModule.java b/server/container/guice/guice-common/src/main/java/org/apache/james/modules/CleanupTaskModule.java
new file mode 100644
index 0000000..01b8304
--- /dev/null
+++ b/server/container/guice/guice-common/src/main/java/org/apache/james/modules/CleanupTaskModule.java
@@ -0,0 +1,32 @@
+/****************************************************************
+ * 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;
+
+import org.apache.james.CleanupTasksPerformer;
+
+import com.google.inject.AbstractModule;
+import com.google.inject.multibindings.Multibinder;
+
+public class CleanupTaskModule extends AbstractModule {
+ @Override
+ protected void configure() {
+ Multibinder.newSetBinder(binder(), CleanupTasksPerformer.CleanupTask.class);
+ }
+}
http://git-wip-us.apache.org/repos/asf/james-project/blob/c1ae8261/server/container/guice/guice-common/src/main/java/org/apache/james/modules/CommonServicesModule.java
----------------------------------------------------------------------
diff --git a/server/container/guice/guice-common/src/main/java/org/apache/james/modules/CommonServicesModule.java b/server/container/guice/guice-common/src/main/java/org/apache/james/modules/CommonServicesModule.java
index 986a65a..c2ec854 100644
--- a/server/container/guice/guice-common/src/main/java/org/apache/james/modules/CommonServicesModule.java
+++ b/server/container/guice/guice-common/src/main/java/org/apache/james/modules/CommonServicesModule.java
@@ -60,6 +60,7 @@ public class CommonServicesModule extends AbstractModule {
install(new AsyncTasksExecutorModule());
install(new DropWizardMetricsModule());
install(new TaskManagerModule());
+ install(new CleanupTaskModule());
bind(FileSystem.class).toInstance(fileSystem);
---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org