Skip to content

Commit

Permalink
JAMES-1950 Log duration of SMTP commands
Browse files Browse the repository at this point in the history
  • Loading branch information
chibenwa authored and aduprat committed Mar 3, 2017
1 parent 90ec55b commit 4f0c583
Show file tree
Hide file tree
Showing 37 changed files with 442 additions and 162 deletions.
Expand Up @@ -16,11 +16,7 @@
* specific language governing permissions and limitations *
* under the License. *
****************************************************************/
package org.apache.james.imap.processor;

import org.apache.james.metrics.api.Metric;
import org.apache.james.metrics.api.MetricFactory;
import org.apache.james.metrics.api.TimeMetric;
package org.apache.james.metrics.api;

public class NoopMetricFactory implements MetricFactory {

Expand Down Expand Up @@ -53,8 +49,9 @@ public String name() {
return "";
}


@Override
public long elapsed() {
public long stopAndPublish() {
return 0;
}
}
Expand Down
Expand Up @@ -46,6 +46,7 @@
import org.apache.james.mailbox.model.MailboxPath;
import org.apache.james.mailbox.model.MessageRange;
import org.apache.james.mailbox.store.MailboxMetaData;
import org.apache.james.metrics.api.NoopMetricFactory;
import org.junit.Before;
import org.junit.Test;
import org.slf4j.Logger;
Expand Down
Expand Up @@ -44,6 +44,7 @@
import org.apache.james.mailbox.model.SimpleMailboxACL;
import org.apache.james.mailbox.model.SimpleMailboxACL.Rfc4314Rights;
import org.apache.james.mailbox.model.SimpleMailboxACL.SimpleMailboxACLEntryKey;
import org.apache.james.metrics.api.NoopMetricFactory;
import org.jmock.Expectations;
import org.jmock.Mockery;
import org.jmock.integration.junit4.JMock;
Expand Down
Expand Up @@ -42,6 +42,7 @@
import org.apache.james.mailbox.model.MailboxPath;
import org.apache.james.mailbox.model.SimpleMailboxACL;
import org.apache.james.mailbox.model.SimpleMailboxACL.Rfc4314Rights;
import org.apache.james.metrics.api.NoopMetricFactory;
import org.jmock.Expectations;
import org.jmock.Mockery;
import org.jmock.integration.junit4.JMock;
Expand Down
Expand Up @@ -53,6 +53,7 @@
import org.apache.james.mailbox.model.MailboxAnnotation;
import org.apache.james.mailbox.model.MailboxAnnotationKey;
import org.apache.james.mailbox.model.MailboxPath;
import org.apache.james.metrics.api.NoopMetricFactory;
import org.junit.Before;
import org.junit.Test;
import org.mockito.ArgumentCaptor;
Expand Down
Expand Up @@ -40,6 +40,7 @@
import org.apache.james.mailbox.quota.QuotaRootResolver;
import org.apache.james.mailbox.store.quota.QuotaImpl;
import org.apache.james.mailbox.store.quota.QuotaRootImpl;
import org.apache.james.metrics.api.NoopMetricFactory;
import org.jmock.Expectations;
import org.jmock.Mockery;
import org.jmock.integration.junit4.JMock;
Expand Down
Expand Up @@ -41,6 +41,7 @@
import org.apache.james.mailbox.quota.QuotaRootResolver;
import org.apache.james.mailbox.store.quota.QuotaImpl;
import org.apache.james.mailbox.store.quota.QuotaRootImpl;
import org.apache.james.metrics.api.NoopMetricFactory;
import org.jmock.Expectations;
import org.jmock.Mockery;
import org.jmock.integration.junit4.JUnit4Mockery;
Expand Down
Expand Up @@ -37,6 +37,7 @@
import org.apache.james.mailbox.MailboxSession;
import org.apache.james.mailbox.SubscriptionManager;
import org.apache.james.mailbox.model.MailboxMetaData;
import org.apache.james.metrics.api.NoopMetricFactory;
import org.jmock.Expectations;
import org.jmock.Mockery;
import org.jmock.integration.junit4.JMock;
Expand Down
Expand Up @@ -29,6 +29,7 @@
import org.apache.james.mailbox.model.MailboxConstants;
import org.apache.james.mailbox.model.MailboxMetaData;
import org.apache.james.mailbox.model.MailboxPath;
import org.apache.james.metrics.api.NoopMetricFactory;
import org.jmock.Expectations;
import org.jmock.Mockery;
import org.jmock.integration.junit4.JMock;
Expand Down
Expand Up @@ -45,6 +45,7 @@
import org.apache.james.mailbox.model.SimpleMailboxACL;
import org.apache.james.mailbox.model.SimpleMailboxACL.Rfc4314Rights;
import org.apache.james.mailbox.model.SimpleMailboxACL.SimpleMailboxACLEntryKey;
import org.apache.james.metrics.api.NoopMetricFactory;
import org.jmock.Expectations;
import org.jmock.Mockery;
import org.jmock.integration.junit4.JMock;
Expand Down
Expand Up @@ -49,6 +49,7 @@
import org.apache.james.mailbox.model.MailboxPath;
import org.apache.james.mailbox.model.MessageRange;
import org.apache.james.mailbox.store.MailboxMetaData;
import org.apache.james.metrics.api.NoopMetricFactory;
import org.junit.Before;
import org.junit.Test;
import org.slf4j.Logger;
Expand Down
Expand Up @@ -38,6 +38,7 @@
import org.apache.james.mailbox.MailboxManager;
import org.apache.james.mailbox.MailboxSession;
import org.apache.james.mailbox.model.MailboxConstants;
import org.apache.james.metrics.api.NoopMetricFactory;
import org.jmock.Expectations;
import org.jmock.Mockery;
import org.jmock.integration.junit4.JMock;
Expand Down
Expand Up @@ -56,6 +56,7 @@
import org.apache.james.mailbox.model.SearchQuery.AddressType;
import org.apache.james.mailbox.model.SearchQuery.Criterion;
import org.apache.james.mailbox.model.SearchQuery.DateResolution;
import org.apache.james.metrics.api.NoopMetricFactory;
import org.jmock.Expectations;
import org.jmock.Mockery;
import org.jmock.integration.junit4.JMock;
Expand Down
Expand Up @@ -45,6 +45,7 @@
import org.apache.james.mailbox.model.SimpleMailboxACL;
import org.apache.james.mailbox.model.SimpleMailboxACL.Rfc4314Rights;
import org.apache.james.mailbox.model.SimpleMailboxACL.SimpleMailboxACLEntryKey;
import org.apache.james.metrics.api.NoopMetricFactory;
import org.jmock.Expectations;
import org.jmock.Mockery;
import org.jmock.integration.junit4.JMock;
Expand Down
Expand Up @@ -50,6 +50,7 @@
import org.apache.james.mailbox.model.MailboxAnnotation;
import org.apache.james.mailbox.model.MailboxAnnotationKey;
import org.apache.james.mailbox.model.MailboxPath;
import org.apache.james.metrics.api.NoopMetricFactory;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
Expand Down
Expand Up @@ -30,6 +30,7 @@
import org.apache.james.mailbox.MailboxManager;
import org.apache.james.mailbox.MailboxSession;
import org.apache.james.mailbox.mock.MockMailboxSession;
import org.apache.james.metrics.api.NoopMetricFactory;
import org.jmock.Expectations;
import org.jmock.Mockery;
import org.jmock.integration.junit4.JMock;
Expand Down
4 changes: 4 additions & 0 deletions protocols/lmtp/pom.xml
Expand Up @@ -52,6 +52,10 @@
<artifactId>commons-net</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>javax.inject</groupId>
<artifactId>javax.inject</artifactId>
</dependency>
<dependency>
<groupId>org.apache.james.protocols</groupId>
<artifactId>protocols-netty</artifactId>
Expand Down
Expand Up @@ -21,6 +21,7 @@
import java.util.ArrayList;
import java.util.List;

import org.apache.james.metrics.api.NoopMetricFactory;
import org.apache.james.protocols.api.handler.CommandDispatcher;
import org.apache.james.protocols.api.handler.CommandHandlerResultLogger;
import org.apache.james.protocols.api.handler.ProtocolHandler;
Expand Down Expand Up @@ -53,37 +54,37 @@
public class LMTPProtocolHandlerChain extends SMTPProtocolHandlerChain{

public LMTPProtocolHandlerChain() {
super();
super(new NoopMetricFactory());
}

public LMTPProtocolHandlerChain(boolean addDefault) {
super(addDefault);
super(new NoopMetricFactory(), addDefault);
}

public LMTPProtocolHandlerChain(Hook... hooks) throws WiringException {
super(hooks);
super(new NoopMetricFactory(), hooks);
}

@Override
protected List<ProtocolHandler> initDefaultHandlers() {
List<ProtocolHandler> defaultHandlers = new ArrayList<ProtocolHandler>();
defaultHandlers.add(new CommandDispatcher<SMTPSession>());
defaultHandlers.add(new ExpnCmdHandler());
defaultHandlers.add(new LhloCmdHandler());
defaultHandlers.add(new LhloCmdHandler(new NoopMetricFactory()));
defaultHandlers.add(new HelpCmdHandler());
defaultHandlers.add(new MailCmdHandler());
defaultHandlers.add(new MailCmdHandler(new NoopMetricFactory()));
defaultHandlers.add(new NoopCmdHandler());
defaultHandlers.add(new QuitCmdHandler());
defaultHandlers.add(new RcptCmdHandler());
defaultHandlers.add(new QuitCmdHandler(new NoopMetricFactory()));
defaultHandlers.add(new RcptCmdHandler(new NoopMetricFactory()));
defaultHandlers.add(new RsetCmdHandler());
defaultHandlers.add(new VrfyCmdHandler());
defaultHandlers.add(new DataCmdHandler());
defaultHandlers.add(new DataCmdHandler(new NoopMetricFactory()));
defaultHandlers.add(new MailSizeEsmtpExtension());
defaultHandlers.add(new WelcomeMessageHandler());
defaultHandlers.add(new ReceivedDataLineFilter());
defaultHandlers.add(new DataLineMessageHookHandler());
defaultHandlers.add(new StartTlsCmdHandler());
defaultHandlers.add(new UnknownCmdHandler());
defaultHandlers.add(new UnknownCmdHandler(new NoopMetricFactory()));
defaultHandlers.add(new CommandHandlerResultLogger());

return defaultHandlers;
Expand Down
Expand Up @@ -23,6 +23,9 @@
import java.util.Collection;
import java.util.Collections;

import javax.inject.Inject;

import org.apache.james.metrics.api.MetricFactory;
import org.apache.james.protocols.smtp.core.esmtp.EhloCmdHandler;

/**
Expand All @@ -31,7 +34,12 @@
public class LhloCmdHandler extends EhloCmdHandler {

private static final Collection<String> COMMANDS = Collections.unmodifiableCollection(Arrays.asList("LHLO"));


@Inject
public LhloCmdHandler(MetricFactory metricFactory) {
super(metricFactory);
}

@Override
public Collection<String> getImplCommands() {
return COMMANDS;
Expand Down
131 changes: 131 additions & 0 deletions protocols/smtp/dependency-reduced-pom.xml
@@ -0,0 +1,131 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<parent>
<artifactId>protocols</artifactId>
<groupId>org.apache.james</groupId>
<version>3.0.0-beta6-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<groupId>org.apache.james.protocols</groupId>
<artifactId>protocols-smtp</artifactId>
<packaging>bundle</packaging>
<name>Apache James :: Protocols :: SMTP</name>
<build>
<plugins>
<plugin>
<artifactId>maven-shade-plugin</artifactId>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<artifactSet>
<includes>
<include>commons-codec:commons-codec</include>
</includes>
</artifactSet>
<filters>
<filter>
<artifact>commons-codec:commons-codec</artifact>
<excludes>
<exclude>org/apache/commons/codec/*</exclude>
</excludes>
<includes>
<include>org/apache/commons/codec/binary/*</include>
</includes>
</filter>
</filters>
<relocations>
<relocation>
<pattern>org.apache.commons.codec.binary</pattern>
<shadedPattern>org.apache.james.protocols.smtp.util</shadedPattern>
</relocation>
</relocations>
<transformers>
<transformer />
</transformers>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>org.apache.james</groupId>
<artifactId>james-server-util</artifactId>
<version>3.0.0-beta6-SNAPSHOT</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.apache.james.protocols</groupId>
<artifactId>protocols-api</artifactId>
<version>3.0.0-beta6-SNAPSHOT</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.apache.james.protocols</groupId>
<artifactId>protocols-api</artifactId>
<version>3.0.0-beta6-SNAPSHOT</version>
<type>test-jar</type>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.james.protocols</groupId>
<artifactId>protocols-netty</artifactId>
<version>3.0.0-beta6-SNAPSHOT</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>18.0</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>commons-net</groupId>
<artifactId>commons-net</artifactId>
<version>3.2</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.netty</groupId>
<artifactId>netty</artifactId>
<version>3.10.6.Final</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.10</version>
<scope>test</scope>
<exclusions>
<exclusion>
<artifactId>hamcrest-core</artifactId>
<groupId>org.hamcrest</groupId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>javax.mail</groupId>
<artifactId>mail</artifactId>
<version>1.4.4</version>
<scope>test</scope>
<exclusions>
<exclusion>
<artifactId>activation</artifactId>
<groupId>javax.activation</groupId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.assertj</groupId>
<artifactId>assertj-core</artifactId>
<version>1.7.1</version>
<scope>test</scope>
</dependency>
</dependencies>
</project>

8 changes: 8 additions & 0 deletions protocols/smtp/pom.xml
Expand Up @@ -52,6 +52,10 @@
<groupId>org.apache.james.protocols</groupId>
<artifactId>protocols-netty</artifactId>
</dependency>
<dependency>
<groupId>org.apache.james</groupId>
<artifactId>metrics-api</artifactId>
</dependency>
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
Expand All @@ -70,6 +74,10 @@
<groupId>io.netty</groupId>
<artifactId>netty</artifactId>
</dependency>
<dependency>
<groupId>javax.inject</groupId>
<artifactId>javax.inject</artifactId>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
Expand Down

0 comments on commit 4f0c583

Please sign in to comment.