james-server-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From btell...@apache.org
Subject [15/17] james-project git commit: JAMES-2414 Guice should used the MixedEventDelivery
Date Tue, 12 Jun 2018 00:03:34 GMT
JAMES-2414 Guice should used the MixedEventDelivery

Allows per listener async/sync executions


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

Branch: refs/heads/master
Commit: 4fae4fdcb05796a2949bc86f9345dc73d5f6d46e
Parents: 150e529
Author: benwa <btellier@linagora.com>
Authored: Thu Jun 7 16:31:41 2018 +0700
Committer: benwa <btellier@linagora.com>
Committed: Tue Jun 12 07:01:45 2018 +0700

----------------------------------------------------------------------
 .../modules/mailbox/DefaultEventModule.java     | 29 ++++++++++++++++++--
 1 file changed, 26 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/james-project/blob/4fae4fdc/server/container/guice/mailbox/src/main/java/org/apache/james/modules/mailbox/DefaultEventModule.java
----------------------------------------------------------------------
diff --git a/server/container/guice/mailbox/src/main/java/org/apache/james/modules/mailbox/DefaultEventModule.java
b/server/container/guice/mailbox/src/main/java/org/apache/james/modules/mailbox/DefaultEventModule.java
index 9cf2f97..b788ed9 100644
--- a/server/container/guice/mailbox/src/main/java/org/apache/james/modules/mailbox/DefaultEventModule.java
+++ b/server/container/guice/mailbox/src/main/java/org/apache/james/modules/mailbox/DefaultEventModule.java
@@ -20,17 +20,20 @@
 package org.apache.james.modules.mailbox;
 
 import java.util.List;
+import java.util.Optional;
 
 import javax.inject.Inject;
 
 import org.apache.commons.configuration.ConfigurationException;
 import org.apache.james.lifecycle.api.Configurable;
 import org.apache.james.mailbox.MailboxListener;
+import org.apache.james.mailbox.store.event.AsynchronousEventDelivery;
 import org.apache.james.mailbox.store.event.DefaultDelegatingMailboxListener;
 import org.apache.james.mailbox.store.event.DelegatingMailboxListener;
 import org.apache.james.mailbox.store.event.EventDelivery;
 import org.apache.james.mailbox.store.event.MailboxAnnotationListener;
 import org.apache.james.mailbox.store.event.MailboxListenerRegistry;
+import org.apache.james.mailbox.store.event.MixedEventDelivery;
 import org.apache.james.mailbox.store.event.SynchronousEventDelivery;
 import org.apache.james.mailbox.store.quota.ListeningCurrentQuotaUpdater;
 import org.apache.james.server.core.configuration.ConfigurationProvider;
@@ -38,20 +41,20 @@ import org.apache.james.utils.ConfigurationPerformer;
 
 import com.google.common.collect.ImmutableList;
 import com.google.inject.AbstractModule;
+import com.google.inject.Provides;
 import com.google.inject.Scopes;
 import com.google.inject.Singleton;
 import com.google.inject.multibindings.Multibinder;
 
 public class DefaultEventModule extends AbstractModule {
 
+    private static final int DEFAULT_POOL_SIZE = 8;
+
     @Override
     protected void configure() {
         bind(DefaultDelegatingMailboxListener.class).in(Scopes.SINGLETON);
         bind(DelegatingMailboxListener.class).to(DefaultDelegatingMailboxListener.class);
 
-        bind(SynchronousEventDelivery.class).in(Scopes.SINGLETON);
-        bind(EventDelivery.class).to(SynchronousEventDelivery.class);
-
         Multibinder.newSetBinder(binder(), ConfigurationPerformer.class).addBinding().to(ListenerRegistrationPerformer.class);
 
         bind(ListeningCurrentQuotaUpdater.class).in(Scopes.SINGLETON);
@@ -64,6 +67,26 @@ public class DefaultEventModule extends AbstractModule {
         Multibinder.newSetBinder(binder(), MailboxListener.class);
     }
 
+    @Provides
+    @Singleton
+    EventDelivery provideEventDelivery(ConfigurationProvider configurationProvider) {
+        int poolSize = retrievePoolSize(configurationProvider);
+
+        return new MixedEventDelivery(
+            new AsynchronousEventDelivery(poolSize),
+            new SynchronousEventDelivery());
+    }
+
+    private int retrievePoolSize(ConfigurationProvider configurationProvider) {
+        try {
+            return Optional.ofNullable(configurationProvider.getConfiguration("listeners")
+                .getInteger("poolSize", null))
+                .orElse(DEFAULT_POOL_SIZE);
+        } catch (ConfigurationException e) {
+            return DEFAULT_POOL_SIZE;
+        }
+    }
+
     @Singleton
     public static class ListenerRegistrationPerformer implements ConfigurationPerformer {
         private final ConfigurationProvider configurationProvider;


---------------------------------------------------------------------
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