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/06/13 02:49:17 UTC
[8/8] james-project git commit: MAILBOX-341 EventDeliver should
report MailboxListener execution timings
MAILBOX-341 EventDeliver should report MailboxListener execution timings
Project: http://git-wip-us.apache.org/repos/asf/james-project/repo
Commit: http://git-wip-us.apache.org/repos/asf/james-project/commit/175f1f29
Tree: http://git-wip-us.apache.org/repos/asf/james-project/tree/175f1f29
Diff: http://git-wip-us.apache.org/repos/asf/james-project/diff/175f1f29
Branch: refs/heads/master
Commit: 175f1f29c95220392ae1027c1c826353355c2e61
Parents: 72bc076
Author: benwa <bt...@linagora.com>
Authored: Tue Jun 12 10:32:11 2018 +0700
Committer: benwa <bt...@linagora.com>
Committed: Wed Jun 13 09:48:48 2018 +0700
----------------------------------------------------------------------
.../main/resources/META-INF/spring/event-system.xml | 5 ++++-
.../test/resources/META-INF/spring/event-alias.xml | 2 ++
.../store/event/AsynchronousEventDelivery.java | 4 ++--
.../store/event/DefaultDelegatingMailboxListener.java | 6 +++++-
.../mailbox/store/event/SynchronousEventDelivery.java | 14 ++++++++++++++
.../BroadcastDelegatingMailboxListener.java | 6 +++++-
.../RegisteredDelegatingMailboxListener.java | 6 +++++-
.../store/event/AsynchronousEventDeliveryTest.java | 4 +++-
.../mailbox/store/event/MixedEventDeliveryTest.java | 11 +++++++----
.../store/event/SynchronousEventDeliveryTest.java | 3 ++-
.../james/modules/mailbox/DefaultEventModule.java | 8 +++++---
11 files changed, 54 insertions(+), 15 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/james-project/blob/175f1f29/mailbox/spring/src/main/resources/META-INF/spring/event-system.xml
----------------------------------------------------------------------
diff --git a/mailbox/spring/src/main/resources/META-INF/spring/event-system.xml b/mailbox/spring/src/main/resources/META-INF/spring/event-system.xml
index e64f0b7..4e04252 100644
--- a/mailbox/spring/src/main/resources/META-INF/spring/event-system.xml
+++ b/mailbox/spring/src/main/resources/META-INF/spring/event-system.xml
@@ -71,12 +71,15 @@
<constructor-arg index="0" ref="mailbox-id-deserializer"/>
</bean>
- <bean id="synchronous-event-delivery" class="org.apache.james.mailbox.store.event.SynchronousEventDelivery" lazy-init="true"/>
+ <bean id="synchronous-event-delivery" class="org.apache.james.mailbox.store.event.SynchronousEventDelivery" lazy-init="true">
+ <constructor-arg index="0" ref="metricFactory"/>
+ </bean>
<bean id="event-registry" class="org.apache.james.mailbox.store.event.MailboxListenerRegistry"/>
<bean id="asynchronous-event-delivery" class="org.apache.james.mailbox.store.event.AsynchronousEventDelivery" lazy-init="true">
<constructor-arg index="0" ref="${event.delivery.thread.count}"/>
+ <constructor-arg index="1" ref="synchronous-event-delivery"/>
</bean>
<bean id="mixed-event-delivery" class="org.apache.james.mailbox.store.event.MixedEventDelivery" lazy-init="true">
http://git-wip-us.apache.org/repos/asf/james-project/blob/175f1f29/mailbox/spring/src/test/resources/META-INF/spring/event-alias.xml
----------------------------------------------------------------------
diff --git a/mailbox/spring/src/test/resources/META-INF/spring/event-alias.xml b/mailbox/spring/src/test/resources/META-INF/spring/event-alias.xml
index fb3cace..7406b84 100644
--- a/mailbox/spring/src/test/resources/META-INF/spring/event-alias.xml
+++ b/mailbox/spring/src/test/resources/META-INF/spring/event-alias.xml
@@ -29,4 +29,6 @@
<constructor-arg index="0" ref="delegating-listener"/>
</bean>
+ <bean id="metricFactory" class="org.apache.james.metrics.api.NoopMetricFactory"/>
+
</beans>
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/james-project/blob/175f1f29/mailbox/store/src/main/java/org/apache/james/mailbox/store/event/AsynchronousEventDelivery.java
----------------------------------------------------------------------
diff --git a/mailbox/store/src/main/java/org/apache/james/mailbox/store/event/AsynchronousEventDelivery.java b/mailbox/store/src/main/java/org/apache/james/mailbox/store/event/AsynchronousEventDelivery.java
index 98a43ab..9ca9824 100644
--- a/mailbox/store/src/main/java/org/apache/james/mailbox/store/event/AsynchronousEventDelivery.java
+++ b/mailbox/store/src/main/java/org/apache/james/mailbox/store/event/AsynchronousEventDelivery.java
@@ -32,9 +32,9 @@ public class AsynchronousEventDelivery implements EventDelivery {
private final ExecutorService threadPoolExecutor;
private final SynchronousEventDelivery synchronousEventDelivery;
- public AsynchronousEventDelivery(int threadPoolSize) {
+ public AsynchronousEventDelivery(int threadPoolSize, SynchronousEventDelivery synchronousEventDelivery) {
this.threadPoolExecutor = Executors.newFixedThreadPool(threadPoolSize);
- this.synchronousEventDelivery = new SynchronousEventDelivery();
+ this.synchronousEventDelivery = synchronousEventDelivery;
}
@Override
http://git-wip-us.apache.org/repos/asf/james-project/blob/175f1f29/mailbox/store/src/main/java/org/apache/james/mailbox/store/event/DefaultDelegatingMailboxListener.java
----------------------------------------------------------------------
diff --git a/mailbox/store/src/main/java/org/apache/james/mailbox/store/event/DefaultDelegatingMailboxListener.java b/mailbox/store/src/main/java/org/apache/james/mailbox/store/event/DefaultDelegatingMailboxListener.java
index 43a236c..a380304 100644
--- a/mailbox/store/src/main/java/org/apache/james/mailbox/store/event/DefaultDelegatingMailboxListener.java
+++ b/mailbox/store/src/main/java/org/apache/james/mailbox/store/event/DefaultDelegatingMailboxListener.java
@@ -28,6 +28,9 @@ import org.apache.james.mailbox.MailboxListener;
import org.apache.james.mailbox.MailboxSession;
import org.apache.james.mailbox.exception.MailboxException;
import org.apache.james.mailbox.model.MailboxPath;
+import org.apache.james.metrics.api.NoopMetricFactory;
+
+import com.google.common.annotations.VisibleForTesting;
/**
* Receive a {@link org.apache.james.mailbox.MailboxListener.MailboxEvent} and delegate it to an other
@@ -45,8 +48,9 @@ public class DefaultDelegatingMailboxListener implements DelegatingMailboxListen
return ListenerType.EACH_NODE;
}
+ @VisibleForTesting
public DefaultDelegatingMailboxListener() {
- this(new SynchronousEventDelivery(),
+ this(new SynchronousEventDelivery(new NoopMetricFactory()),
new MailboxListenerRegistry());
}
http://git-wip-us.apache.org/repos/asf/james-project/blob/175f1f29/mailbox/store/src/main/java/org/apache/james/mailbox/store/event/SynchronousEventDelivery.java
----------------------------------------------------------------------
diff --git a/mailbox/store/src/main/java/org/apache/james/mailbox/store/event/SynchronousEventDelivery.java b/mailbox/store/src/main/java/org/apache/james/mailbox/store/event/SynchronousEventDelivery.java
index 97112de..df52819 100644
--- a/mailbox/store/src/main/java/org/apache/james/mailbox/store/event/SynchronousEventDelivery.java
+++ b/mailbox/store/src/main/java/org/apache/james/mailbox/store/event/SynchronousEventDelivery.java
@@ -19,8 +19,12 @@
package org.apache.james.mailbox.store.event;
+import javax.inject.Inject;
+
import org.apache.james.mailbox.Event;
import org.apache.james.mailbox.MailboxListener;
+import org.apache.james.metrics.api.MetricFactory;
+import org.apache.james.metrics.api.TimeMetric;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -28,14 +32,24 @@ public class SynchronousEventDelivery implements EventDelivery {
private static final Logger LOGGER = LoggerFactory.getLogger(SynchronousEventDelivery.class);
+ private final MetricFactory metricFactory;
+
+ @Inject
+ public SynchronousEventDelivery(MetricFactory metricFactory) {
+ this.metricFactory = metricFactory;
+ }
+
@Override
public void deliver(MailboxListener mailboxListener, Event event) {
+ TimeMetric timer = metricFactory.timer("mailbox-listener-" + mailboxListener.getClass().getSimpleName());
try {
mailboxListener.event(event);
} catch (Throwable throwable) {
LOGGER.error("Error while processing listener {} for {}",
mailboxListener.getClass().getCanonicalName(), event.getClass().getCanonicalName(),
throwable);
+ } finally {
+ timer.stopAndPublish();
}
}
}
http://git-wip-us.apache.org/repos/asf/james-project/blob/175f1f29/mailbox/store/src/main/java/org/apache/james/mailbox/store/event/distributed/BroadcastDelegatingMailboxListener.java
----------------------------------------------------------------------
diff --git a/mailbox/store/src/main/java/org/apache/james/mailbox/store/event/distributed/BroadcastDelegatingMailboxListener.java b/mailbox/store/src/main/java/org/apache/james/mailbox/store/event/distributed/BroadcastDelegatingMailboxListener.java
index 74fd142..2171e80 100644
--- a/mailbox/store/src/main/java/org/apache/james/mailbox/store/event/distributed/BroadcastDelegatingMailboxListener.java
+++ b/mailbox/store/src/main/java/org/apache/james/mailbox/store/event/distributed/BroadcastDelegatingMailboxListener.java
@@ -33,9 +33,12 @@ import org.apache.james.mailbox.store.event.SynchronousEventDelivery;
import org.apache.james.mailbox.store.publisher.MessageConsumer;
import org.apache.james.mailbox.store.publisher.Publisher;
import org.apache.james.mailbox.store.publisher.Topic;
+import org.apache.james.metrics.api.NoopMetricFactory;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+import com.google.common.annotations.VisibleForTesting;
+
public class BroadcastDelegatingMailboxListener implements DistributedDelegatingMailboxListener {
private static final Logger LOGGER = LoggerFactory.getLogger(BroadcastDelegatingMailboxListener.class);
@@ -60,11 +63,12 @@ public class BroadcastDelegatingMailboxListener implements DistributedDelegating
messageConsumer.init(this.globalTopic);
}
+ @VisibleForTesting
public BroadcastDelegatingMailboxListener(Publisher publisher,
MessageConsumer messageConsumer,
EventSerializer eventSerializer,
String globalTopic) throws Exception {
- this(publisher, messageConsumer, eventSerializer, new SynchronousEventDelivery(), globalTopic);
+ this(publisher, messageConsumer, eventSerializer, new SynchronousEventDelivery(new NoopMetricFactory()), globalTopic);
}
@Override
http://git-wip-us.apache.org/repos/asf/james-project/blob/175f1f29/mailbox/store/src/main/java/org/apache/james/mailbox/store/event/distributed/RegisteredDelegatingMailboxListener.java
----------------------------------------------------------------------
diff --git a/mailbox/store/src/main/java/org/apache/james/mailbox/store/event/distributed/RegisteredDelegatingMailboxListener.java b/mailbox/store/src/main/java/org/apache/james/mailbox/store/event/distributed/RegisteredDelegatingMailboxListener.java
index 383da95..8165536 100644
--- a/mailbox/store/src/main/java/org/apache/james/mailbox/store/event/distributed/RegisteredDelegatingMailboxListener.java
+++ b/mailbox/store/src/main/java/org/apache/james/mailbox/store/event/distributed/RegisteredDelegatingMailboxListener.java
@@ -34,9 +34,12 @@ import org.apache.james.mailbox.store.event.SynchronousEventDelivery;
import org.apache.james.mailbox.store.publisher.MessageConsumer;
import org.apache.james.mailbox.store.publisher.Publisher;
import org.apache.james.mailbox.store.publisher.Topic;
+import org.apache.james.metrics.api.NoopMetricFactory;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+import com.google.common.annotations.VisibleForTesting;
+
public class RegisteredDelegatingMailboxListener implements DistributedDelegatingMailboxListener {
private static final Logger LOGGER = LoggerFactory.getLogger(RegisteredDelegatingMailboxListener.class);
@@ -61,11 +64,12 @@ public class RegisteredDelegatingMailboxListener implements DistributedDelegatin
messageConsumer.init(mailboxPathRegister.getLocalTopic());
}
+ @VisibleForTesting
public RegisteredDelegatingMailboxListener(EventSerializer eventSerializer,
Publisher publisher,
MessageConsumer messageConsumer,
MailboxPathRegister mailboxPathRegister) throws Exception {
- this(eventSerializer, publisher, messageConsumer, mailboxPathRegister, new SynchronousEventDelivery());
+ this(eventSerializer, publisher, messageConsumer, mailboxPathRegister, new SynchronousEventDelivery(new NoopMetricFactory()));
}
@Override
http://git-wip-us.apache.org/repos/asf/james-project/blob/175f1f29/mailbox/store/src/test/java/org/apache/james/mailbox/store/event/AsynchronousEventDeliveryTest.java
----------------------------------------------------------------------
diff --git a/mailbox/store/src/test/java/org/apache/james/mailbox/store/event/AsynchronousEventDeliveryTest.java b/mailbox/store/src/test/java/org/apache/james/mailbox/store/event/AsynchronousEventDeliveryTest.java
index a072bbf..1fbe4d7 100644
--- a/mailbox/store/src/test/java/org/apache/james/mailbox/store/event/AsynchronousEventDeliveryTest.java
+++ b/mailbox/store/src/test/java/org/apache/james/mailbox/store/event/AsynchronousEventDeliveryTest.java
@@ -28,6 +28,7 @@ import java.util.concurrent.TimeUnit;
import org.apache.james.mailbox.MailboxListener;
import org.apache.james.mailbox.mock.MockMailboxSession;
+import org.apache.james.metrics.api.NoopMetricFactory;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
@@ -41,7 +42,8 @@ public class AsynchronousEventDeliveryTest {
@Before
public void setUp() {
mailboxListener = mock(MailboxListener.class);
- asynchronousEventDelivery = new AsynchronousEventDelivery(2);
+ asynchronousEventDelivery = new AsynchronousEventDelivery(2,
+ new SynchronousEventDelivery(new NoopMetricFactory()));
}
@After
http://git-wip-us.apache.org/repos/asf/james-project/blob/175f1f29/mailbox/store/src/test/java/org/apache/james/mailbox/store/event/MixedEventDeliveryTest.java
----------------------------------------------------------------------
diff --git a/mailbox/store/src/test/java/org/apache/james/mailbox/store/event/MixedEventDeliveryTest.java b/mailbox/store/src/test/java/org/apache/james/mailbox/store/event/MixedEventDeliveryTest.java
index 08dacee..5a6dc92 100644
--- a/mailbox/store/src/test/java/org/apache/james/mailbox/store/event/MixedEventDeliveryTest.java
+++ b/mailbox/store/src/test/java/org/apache/james/mailbox/store/event/MixedEventDeliveryTest.java
@@ -29,6 +29,7 @@ import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;
import org.apache.james.mailbox.MailboxListener;
+import org.apache.james.metrics.api.NoopMetricFactory;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
@@ -44,7 +45,9 @@ public class MixedEventDeliveryTest {
@Before
public void setUp() {
listener = mock(MailboxListener.class);
- mixedEventDelivery = new MixedEventDelivery(new AsynchronousEventDelivery(2), new SynchronousEventDelivery());
+ SynchronousEventDelivery synchronousEventDelivery = new SynchronousEventDelivery(new NoopMetricFactory());
+ AsynchronousEventDelivery asynchronousEventDelivery = new AsynchronousEventDelivery(2, synchronousEventDelivery);
+ mixedEventDelivery = new MixedEventDelivery(asynchronousEventDelivery, synchronousEventDelivery);
}
@After
@@ -53,7 +56,7 @@ public class MixedEventDeliveryTest {
}
@Test
- public void deliverShouldWorkOnSynchronousListeners() throws Exception {
+ public void deliverShouldWorkOnSynchronousListeners() {
when(listener.getExecutionMode()).thenReturn(MailboxListener.ExecutionMode.SYNCHRONOUS);
MailboxListener.MailboxEvent event = new MailboxListener.MailboxEvent(null, null) {};
mixedEventDelivery.deliver(listener, event);
@@ -61,7 +64,7 @@ public class MixedEventDeliveryTest {
}
@Test
- public void deliverShouldEventuallyDeliverOnAsynchronousListeners() throws Exception {
+ public void deliverShouldEventuallyDeliverOnAsynchronousListeners() {
MailboxListener.MailboxEvent event = new MailboxListener.MailboxEvent(null, null) {};
when(listener.getExecutionMode()).thenReturn(MailboxListener.ExecutionMode.ASYNCHRONOUS);
mixedEventDelivery.deliver(listener, event);
@@ -69,7 +72,7 @@ public class MixedEventDeliveryTest {
}
@Test(timeout = ONE_MINUTE)
- public void deliverShouldNotBlockOnAsynchronousListeners() throws Exception {
+ public void deliverShouldNotBlockOnAsynchronousListeners() {
MailboxListener.MailboxEvent event = new MailboxListener.MailboxEvent(null, null) {};
when(listener.getExecutionMode()).thenReturn(MailboxListener.ExecutionMode.ASYNCHRONOUS);
final CountDownLatch latch = new CountDownLatch(1);
http://git-wip-us.apache.org/repos/asf/james-project/blob/175f1f29/mailbox/store/src/test/java/org/apache/james/mailbox/store/event/SynchronousEventDeliveryTest.java
----------------------------------------------------------------------
diff --git a/mailbox/store/src/test/java/org/apache/james/mailbox/store/event/SynchronousEventDeliveryTest.java b/mailbox/store/src/test/java/org/apache/james/mailbox/store/event/SynchronousEventDeliveryTest.java
index 5b5137a..85bc13f 100644
--- a/mailbox/store/src/test/java/org/apache/james/mailbox/store/event/SynchronousEventDeliveryTest.java
+++ b/mailbox/store/src/test/java/org/apache/james/mailbox/store/event/SynchronousEventDeliveryTest.java
@@ -25,6 +25,7 @@ import static org.mockito.Mockito.verify;
import org.apache.james.mailbox.MailboxListener;
import org.apache.james.mailbox.mock.MockMailboxSession;
+import org.apache.james.metrics.api.NoopMetricFactory;
import org.junit.Before;
import org.junit.Test;
@@ -36,7 +37,7 @@ public class SynchronousEventDeliveryTest {
@Before
public void setUp() {
mailboxListener = mock(MailboxListener.class);
- synchronousEventDelivery = new SynchronousEventDelivery();
+ synchronousEventDelivery = new SynchronousEventDelivery(new NoopMetricFactory());
}
@Test
http://git-wip-us.apache.org/repos/asf/james-project/blob/175f1f29/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 b788ed9..835eccc 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
@@ -36,6 +36,7 @@ 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.metrics.api.MetricFactory;
import org.apache.james.server.core.configuration.ConfigurationProvider;
import org.apache.james.utils.ConfigurationPerformer;
@@ -69,12 +70,13 @@ public class DefaultEventModule extends AbstractModule {
@Provides
@Singleton
- EventDelivery provideEventDelivery(ConfigurationProvider configurationProvider) {
+ EventDelivery provideEventDelivery(ConfigurationProvider configurationProvider, MetricFactory metricFactory) {
int poolSize = retrievePoolSize(configurationProvider);
+ SynchronousEventDelivery synchronousEventDelivery = new SynchronousEventDelivery(metricFactory);
return new MixedEventDelivery(
- new AsynchronousEventDelivery(poolSize),
- new SynchronousEventDelivery());
+ new AsynchronousEventDelivery(poolSize, synchronousEventDelivery),
+ synchronousEventDelivery);
}
private int retrievePoolSize(ConfigurationProvider configurationProvider) {
---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org