james-server-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From btell...@apache.org
Subject [04/13] james-project git commit: JAMES-2448 Don't use Camel exchanges properties
Date Thu, 05 Jul 2018 02:01:26 GMT
JAMES-2448 Don't use Camel exchanges properties

It comes with a performance penalty and actually makes code reading harder


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

Branch: refs/heads/master
Commit: 32d59cc34afb7408d3f131d532193be571d293e4
Parents: d261aef
Author: benwa <btellier@linagora.com>
Authored: Sun Jul 1 23:47:06 2018 +0700
Committer: benwa <btellier@linagora.com>
Committed: Thu Jul 5 08:56:22 2018 +0700

----------------------------------------------------------------------
 .../impl/camel/CamelMailetProcessor.java        | 29 ++++---------
 .../impl/camel/MatcherSplitter.java             | 43 ++++++++------------
 2 files changed, 26 insertions(+), 46 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/james-project/blob/32d59cc3/server/mailet/mailetcontainer-camel/src/main/java/org/apache/james/mailetcontainer/impl/camel/CamelMailetProcessor.java
----------------------------------------------------------------------
diff --git a/server/mailet/mailetcontainer-camel/src/main/java/org/apache/james/mailetcontainer/impl/camel/CamelMailetProcessor.java
b/server/mailet/mailetcontainer-camel/src/main/java/org/apache/james/mailetcontainer/impl/camel/CamelMailetProcessor.java
index b4808c8..2410374 100644
--- a/server/mailet/mailetcontainer-camel/src/main/java/org/apache/james/mailetcontainer/impl/camel/CamelMailetProcessor.java
+++ b/server/mailet/mailetcontainer-camel/src/main/java/org/apache/james/mailetcontainer/impl/camel/CamelMailetProcessor.java
@@ -133,18 +133,16 @@ public class CamelMailetProcessor extends AbstractStateMailetProcessor
implement
         }
 
         @Override
-        public void configure() throws Exception {
+        public void configure() {
             Processor disposeProcessor = new DisposeProcessor();
-            Processor removePropsProcessor = new RemovePropertiesProcessor();
             Processor completeProcessor = new CompleteProcessor();
             Processor stateChangedProcessor = new StateChangedProcessor();
 
             String state = getState();
 
-            RouteDefinition processorDef = from(getEndpoint()).routeId(state).setExchangePattern(ExchangePattern.InOnly)
-                    // store the logger in properties
-                    .setProperty(MatcherSplitter.LOGGER_PROPERTY, constant(LOGGER))
-                    .setProperty(MatcherSplitter.METRIC_FACTORY, constant(metricFactory));
+            RouteDefinition processorDef = from(getEndpoint())
+                .routeId(state)
+                .setExchangePattern(ExchangePattern.InOnly);
 
             for (MatcherMailetPair pair : pairs) {
                 Matcher matcher = pair.getMatcher();
@@ -155,14 +153,15 @@ public class CamelMailetProcessor extends AbstractStateMailetProcessor
implement
 
                 CamelProcessor mailetProccessor = new CamelProcessor(metricFactory, mailet,
CamelMailetProcessor.this);
                 // Store the matcher to use for splitter in properties
-                processorDef.setProperty(MatcherSplitter.MATCHER_PROPERTY, constant(matcher)).setProperty(MatcherSplitter.ON_MATCH_EXCEPTION_PROPERTY,
constant(onMatchException)).setProperty(MatcherSplitter.MAILETCONTAINER_PROPERTY, constant(CamelMailetProcessor.this))
+                MatcherSplitter matcherSplitter = new MatcherSplitter(metricFactory, CamelMailetProcessor.this,
matcher, onMatchException);
 
+                processorDef
                         // do splitting of the mail based on the stored matcher
-                        .split().method(MatcherSplitter.class).aggregationStrategy(aggr)
+                        .split().method(matcherSplitter).aggregationStrategy(aggr)
 
                         .choice().when(new MatcherMatch()).process(mailetProccessor).end()
 
-                        .choice().when(new MailStateEquals(Mail.GHOST)).process(disposeProcessor).stop().otherwise().process(removePropsProcessor).end()
+                        .choice().when(new MailStateEquals(Mail.GHOST)).process(disposeProcessor).stop().end()
 
                         .choice().when(new MailStateNotEquals(state)).process(stateChangedProcessor).process(completeProcessor).stop().end();
             }
@@ -186,19 +185,10 @@ public class CamelMailetProcessor extends AbstractStateMailetProcessor
implement
 
         }
 
-        private final class RemovePropertiesProcessor implements Processor {
-
-            @Override
-            public void process(Exchange exchange) throws Exception {
-                exchange.removeProperty(MatcherSplitter.ON_MATCH_EXCEPTION_PROPERTY);
-                exchange.removeProperty(MatcherSplitter.MATCHER_PROPERTY);
-            }
-        }
-
         private final class CompleteProcessor implements Processor {
 
             @Override
-            public void process(Exchange ex) throws Exception {
+            public void process(Exchange ex) {
                 LOGGER.debug("End of mailetprocessor for state {} reached", getState());
                 ex.setProperty(Exchange.ROUTE_STOP, true);
             }
@@ -210,7 +200,6 @@ public class CamelMailetProcessor extends AbstractStateMailetProcessor
implement
             public void process(Exchange arg0) throws Exception {
                 Mail mail = arg0.getIn().getBody(Mail.class);
                 toProcessor(mail);
-
             }
 
         }

http://git-wip-us.apache.org/repos/asf/james-project/blob/32d59cc3/server/mailet/mailetcontainer-camel/src/main/java/org/apache/james/mailetcontainer/impl/camel/MatcherSplitter.java
----------------------------------------------------------------------
diff --git a/server/mailet/mailetcontainer-camel/src/main/java/org/apache/james/mailetcontainer/impl/camel/MatcherSplitter.java
b/server/mailet/mailetcontainer-camel/src/main/java/org/apache/james/mailetcontainer/impl/camel/MatcherSplitter.java
index 876ce6a..016a0c9 100644
--- a/server/mailet/mailetcontainer-camel/src/main/java/org/apache/james/mailetcontainer/impl/camel/MatcherSplitter.java
+++ b/server/mailet/mailetcontainer-camel/src/main/java/org/apache/james/mailetcontainer/impl/camel/MatcherSplitter.java
@@ -24,11 +24,11 @@ import java.util.ArrayList;
 import java.util.Collection;
 import java.util.List;
 import java.util.Locale;
+import java.util.Optional;
 
 import javax.mail.MessagingException;
 
 import org.apache.camel.Body;
-import org.apache.camel.ExchangeProperty;
 import org.apache.camel.Handler;
 import org.apache.camel.InOnly;
 import org.apache.james.core.MailAddress;
@@ -56,36 +56,32 @@ public class MatcherSplitter {
     /** Headername which is used to indicate that the matcher matched */
     public static final String MATCHER_MATCHED_ATTRIBUTE = "matched";
 
-    /** Headername under which the matcher is stored */
-    public static final String MATCHER_PROPERTY = "matcher";
-
-    public static final String ON_MATCH_EXCEPTION_PROPERTY = "onMatchException";
-
-    public static final String LOGGER_PROPERTY = "logger";
-
-    public static final String MAILETCONTAINER_PROPERTY = "container";
-
-    public static final String METRIC_FACTORY = "metricFactory";
+    private final MetricFactory metricFactory;
+    private final CamelMailetProcessor container;
+    private final Matcher matcher;
+    private final String onMatchException;
+
+    public MatcherSplitter(MetricFactory metricFactory, CamelMailetProcessor container, Matcher
matcher, String onMatchException) {
+        this.metricFactory = metricFactory;
+        this.container = container;
+        this.matcher = matcher;
+        this.onMatchException = Optional.ofNullable(onMatchException)
+            .map(s -> s.trim().toLowerCase(Locale.US))
+            .orElse(Mail.ERROR);
+    }
 
     /**
      * Generate a List of MailMessage instances for the give @Body. This is done
      * by using the given Matcher to see if we need more then one instance of
      * the MailMessage
-     * 
-     * @param matcher
-     *            Matcher to use for splitting
+     *
      * @param mail
      *            Mail which is stored in the @Body of the MailMessage
      * @return mailMessageList
      * @throws MessagingException
      */
     @Handler
-    public List<Mail> split(@ExchangeProperty(MATCHER_PROPERTY) Matcher matcher,
-                            @ExchangeProperty(ON_MATCH_EXCEPTION_PROPERTY) String onMatchException,
-                            @ExchangeProperty(LOGGER_PROPERTY) Logger logger,
-                            @ExchangeProperty(MAILETCONTAINER_PROPERTY) CamelMailetProcessor
container,
-                            @ExchangeProperty(METRIC_FACTORY) MetricFactory metricFactory,
-                            @Body Mail mail) throws MessagingException {
+    public List<Mail> split(@Body Mail mail) throws MessagingException {
         Collection<MailAddress> matchedRcpts = null;
         Collection<MailAddress> origRcpts = new ArrayList<>(mail.getRecipients());
         long start = System.currentTimeMillis();
@@ -122,11 +118,6 @@ public class MatcherSplitter {
 
             } catch (Exception me) {
                 ex = me;
-                if (onMatchException == null) {
-                    onMatchException = Mail.ERROR;
-                } else {
-                    onMatchException = onMatchException.trim().toLowerCase(Locale.US);
-                }
                 if (onMatchException.equalsIgnoreCase("nomatch")) {
                     // In case the matcher returned null, create an empty
                     // Collection
@@ -137,7 +128,7 @@ public class MatcherSplitter {
                     matchedRcpts = mail.getRecipients();
                     // no need to verify addresses
                 } else {
-                    ProcessorUtil.handleException(me, mail, matcher.getMatcherConfig().getMatcherName(),
onMatchException, logger);
+                    ProcessorUtil.handleException(me, mail, matcher.getMatcherConfig().getMatcherName(),
onMatchException, LOGGER);
                 }
             }
 


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