Hi,

I tried to manage James via JMX and that's really great.
Tks again for this rich feature :)

The mbeanserver spring bean is injected in CamelMailProcessorList,... but is commented by default in spring-beans.xml
To start James, you need to uncomment the jmx section.

if we provide james with jmx, we should also think to have a secured (username/password) connection.
I googled a bit to find how to enable security, but didn't find it.

Tks,

Eric


On 13/10/2010 20:49, nor...@apache.org wrote:
Author: norman
Date: Wed Oct 13 18:49:36 2010
New Revision: 1022235

URL: http://svn.apache.org/viewvc?rev=1022235&view=rev
Log:
finish JMX stuff for mailet/matcher/mailetcontainer/mailprocessor (JAMES-1057)

Added:
     
james/server/trunk/mailetcontainer-impl/src/main/java/org/apache/james/mailetcontainer/MailetManagement.java
       - copied, changed from r1022183, 
james/server/trunk/mailetcontainer-impl/src/main/java/org/apache/james/mailetcontainer/MailetMBeanWrapper.java
     
james/server/trunk/mailetcontainer-impl/src/main/java/org/apache/james/mailetcontainer/ProcessorDetail.java
Removed:
     
james/server/trunk/mailetcontainer-impl/src/main/java/org/apache/james/mailetcontainer/MailetMBeanWrapper.java
Modified:
     
james/server/trunk/mailetcontainer-api/src/main/java/org/apache/james/mailetcontainer/MatcherManagementMBean.java
     
james/server/trunk/mailetcontainer-camel/src/main/java/org/apache/james/mailetcontainer/camel/CamelMailProcessorList.java
     
james/server/trunk/mailetcontainer-impl/src/main/java/org/apache/james/mailetcontainer/MatcherManagement.java
     james/server/trunk/spring-deployment/src/main/config/james/spring-beans.xml

Modified: 
james/server/trunk/mailetcontainer-api/src/main/java/org/apache/james/mailetcontainer/MatcherManagementMBean.java
URL: 
http://svn.apache.org/viewvc/james/server/trunk/mailetcontainer-api/src/main/java/org/apache/james/mailetcontainer/MatcherManagementMBean.java?rev=1022235&r1=1022234&r2=1022235&view=diff
==============================================================================
--- 
james/server/trunk/mailetcontainer-api/src/main/java/org/apache/james/mailetcontainer/MatcherManagementMBean.java
 (original)
+++ 
james/server/trunk/mailetcontainer-api/src/main/java/org/apache/james/mailetcontainer/MatcherManagementMBean.java
 Wed Oct 13 18:49:36 2010
@@ -22,7 +22,14 @@ package org.apache.james.mailetcontainer
  /**
   * management interface for one Matcher instance
   */
-public interface MatcherManagementMBean {
-    String getMatcherName();
-    String getMatcherCondition();
+public interface MatcherManagementMBean extends MailProcessingMBean{
+
+    public String getMatcherName();
+
+    public String getMatcherCondition();
+
+    public long getMatchedRecipientCount();
+
+    public long getNotMatchedRecipientCount();
+
  }

Modified: 
james/server/trunk/mailetcontainer-camel/src/main/java/org/apache/james/mailetcontainer/camel/CamelMailProcessorList.java
URL: 
http://svn.apache.org/viewvc/james/server/trunk/mailetcontainer-camel/src/main/java/org/apache/james/mailetcontainer/camel/CamelMailProcessorList.java?rev=1022235&r1=1022234&r2=1022235&view=diff
==============================================================================
--- 
james/server/trunk/mailetcontainer-camel/src/main/java/org/apache/james/mailetcontainer/camel/CamelMailProcessorList.java
 (original)
+++ 
james/server/trunk/mailetcontainer-camel/src/main/java/org/apache/james/mailetcontainer/camel/CamelMailProcessorList.java
 Wed Oct 13 18:49:36 2010
@@ -52,16 +52,15 @@ import org.apache.james.mailetcontainer.
  import org.apache.james.mailetcontainer.MailetConfigImpl;
  import org.apache.james.mailetcontainer.MailetContainer;
  import org.apache.james.mailetcontainer.MailetLoader;
-import org.apache.james.mailetcontainer.MailetMBeanWrapper;
+import org.apache.james.mailetcontainer.MailetManagement;
  import org.apache.james.mailetcontainer.MatcherLoader;
  import org.apache.james.mailetcontainer.MatcherManagement;
-import org.apache.james.mailetcontainer.ProcessorDetailMBean;
+import org.apache.james.mailetcontainer.ProcessorDetail;
  import org.apache.james.mailetcontainer.ProcessorManagementMBean;
  import org.apache.mailet.Mail;
  import org.apache.mailet.Mailet;
  import org.apache.mailet.MailetConfig;
  import org.apache.mailet.Matcher;
-import org.apache.mailet.MatcherConfig;
  import org.apache.mailet.base.GenericMailet;
  import org.apache.mailet.base.MatcherInverter;

@@ -78,8 +77,8 @@ public class CamelMailProcessorList impl
      private MailetLoader mailetLoader;
      private Log logger;

-    private final Map<String,List<MailetMBeanWrapper>>  mailets = new 
HashMap<String,List<MailetMBeanWrapper>>();
-    private final Map<String,List<Matcher>>  matchers = new 
HashMap<String,List<Matcher>>();
+    private final Map<String,List<MailetManagement>>  mailets = new 
HashMap<String,List<MailetManagement>>();
+    private final Map<String,List<MatcherManagement>>  matchers = new 
HashMap<String,List<MatcherManagement>>();
      private final Map<String,MailProcessor>  processors = new 
HashMap<String,MailProcessor>();
      private final UseLatestAggregationStrategy aggr = new 
UseLatestAggregationStrategy();

@@ -121,9 +120,9 @@ public class CamelMailProcessorList impl
      public void dispose() {
          boolean debugEnabled = logger.isDebugEnabled();

-        Iterator<List<MailetMBeanWrapper>>  it = mailets.values().iterator();
+        Iterator<List<MailetManagement>>  it = mailets.values().iterator();
          while (it.hasNext()) {
-            List<MailetMBeanWrapper>  mList = it.next();
+            List<MailetManagement>  mList = it.next();
              for (int i = 0; i<  mList.size(); i++) {
                  Mailet m = mList.get(i).getMailet();
                  if (debugEnabled) {
@@ -134,9 +133,9 @@ public class CamelMailProcessorList impl

          }

-        Iterator<List<Matcher>>  mit = matchers.values().iterator();
+        Iterator<List<MatcherManagement>>  mit = matchers.values().iterator();
          while (mit.hasNext()) {
-            List<Matcher>  mList = mit.next();
+            List<MatcherManagement>  mList = mit.next();
              for (int i = 0; i<  mList.size(); i++) {
                  Matcher m = mList.get(i);
                  if (debugEnabled) {
@@ -238,10 +237,11 @@ public class CamelMailProcessorList impl
       * @see 
org.apache.james.transport.MailProcessor#service(org.apache.mailet.Mail)
       */
      public void service(Mail mail) throws MessagingException {
-        try {
-            producerTemplate.sendBody(getEndpoint(mail.getState()), mail);
-        } catch (CamelExecutionException ex) {
-            throw new MessagingException("Unable to process mail " + 
mail.getName(),ex);
+        MailProcessor processor = getProcessor(mail.getState());
+        if (processor != null) {
+            processor.service(mail);
+        } else {
+            throw new MessagingException("No processor found for mail " + mail.getName() 
+ " with state " + mail.getState());
          }
      }

@@ -276,14 +276,12 @@ public class CamelMailProcessorList impl
      }


-    private final class ChildMailProcessor implements MailProcessor, 
MailetContainer, ProcessorDetailMBean {
-        private String processorName;
-        private long slowestProcessing = -1;
-        private long fastestProcessing = -1;
-        private long successCount = 0;
-        private long errorCount = 0;
+    private final class ChildProcessor implements MailProcessor, 
MailetContainer {
+

-        public ChildMailProcessor(String processorName) {
+        private String processorName;
+
+        public ChildProcessor(String processorName) {
              this.processorName = processorName;
          }

@@ -294,20 +292,9 @@ public class CamelMailProcessorList impl
           */
          public void service(Mail mail) throws MessagingException {
              try {
-                long startProcessing = System.currentTimeMillis();
-
                  producerTemplate.sendBody(getEndpoint(processorName), mail);
-
-                 long processTime = System.currentTimeMillis() - 
startProcessing;
-                 if (processTime>  slowestProcessing) {
-                        slowestProcessing = processTime;
-                 }
-                 if (fastestProcessing == -1 || fastestProcessing>  
processTime) {
-                     fastestProcessing = processTime;
-                 }
-                 successCount++;
+
               } catch (CamelExecutionException ex) {
-                errorCount++;
                   throw new MessagingException("Unable to process mail " + 
mail.getName(),ex);
               }
           }
@@ -325,70 +312,8 @@ public class CamelMailProcessorList impl
           * @see org.apache.james.transport.MailetContainer#getMatchers()
           */
          public List<Matcher>  getMatchers() {
-            return matchers.get(processorName);
-        }
-
-        /*
-         * (non-Javadoc)
-         *
-         * @see
-         * 
org.apache.james.mailetcontainer.ProcessorDetailMBean#getHandledMailCount
-         * ()
-         */
-        public long getHandledMailCount() {
-            return getSuccessCount() + getErrorCount();
-        }
-
-        /*
-         * (non-Javadoc)
-         *
-         * @see org.apache.james.mailetcontainer.ProcessorDetailMBean#getName()
-         */
-        public String getName() {
-            return processorName;
-        }
-
-        /*
-         * (non-Javadoc)
-         *
-         * @seeorg.apache.james.mailetcontainer.ProcessorDetailMBean#
-         * getFastestProcessing()
-         */
-        public long getFastestProcessing() {
-            return fastestProcessing;
+            return new ArrayList<Matcher>(matchers.get(processorName));
          }
-
-        /*
-         * (non-Javadoc)
-         *
-         * @seeorg.apache.james.mailetcontainer.ProcessorDetailMBean#
-         * getSlowestProcessing()
-         */
-        public long getSlowestProcessing() {
-            return slowestProcessing;
-        }
-
-        /*
-         * (non-Javadoc)
-         *
-         * @see
-         * 
org.apache.james.mailetcontainer.ProcessorDetailMBean#getErrorCount()
-         */
-        public long getErrorCount() {
-            return errorCount;
-        }
-
-        /*
-         * (non-Javadoc)
-         *
-         * @see
-         * 
org.apache.james.mailetcontainer.ProcessorDetailMBean#getSuccessCount
-         * ()
-         */
-        public long getSuccessCount() {
-            return successCount;
-        }
-
      }

        public CamelContext getCamelContext() {
@@ -414,28 +339,30 @@ public class CamelMailProcessorList impl

      private void createProcessorMBean(String baseObjectName, String 
processorName, MBeanServer mBeanServer) {
          String processorMBeanName = baseObjectName + "processor=" + 
processorName;
-        registerMBean(mBeanServer, processorMBeanName, (ProcessorDetailMBean) 
getProcessor(processorName));
+        registerMBean(mBeanServer, processorMBeanName, 
getProcessor(processorName));


          // add all mailets but the last, because that is a terminator (see 
LinearProcessor.closeProcessorLists())
-        List<MailetMBeanWrapper>  mailets =  this.mailets.get(processorName);
-        for (int i = 0; i<  mailets.size()-1; i++) {
-            MailetMBeanWrapper mailet = mailets.get(i);
+        List<Mailet>  mailets =  ((MailetContainer) 
getProcessor(processorName)).getMailets();
+        for (int i = 0; i<  mailets.size(); i++) {
+            MailetManagement mailet = (MailetManagement) mailets.get(i);

              String mailetMBeanName = processorMBeanName + ",subtype=mailet,index=" + 
(i+1) + ",mailetname=" + mailet.getMailetName();
              registerMBean(mBeanServer, mailetMBeanName, mailet);
          }

+

          // add all matchers but the last, because that is a terminator (see 
LinearProcessor.closeProcessorLists())
          List<Matcher>  matchers =  
((MailetContainer)getProcessor(processorName)).getMatchers();
-        for (int i = 0; i<  matchers.size()-1; i++) {
-            MatcherConfig matcherConfig = matchers.get(i).getMatcherConfig();
+        for (int i = 0; i<  matchers.size(); i++) {
+            MatcherManagement matcher = (MatcherManagement) matchers.get(i);
+
+            String matcherMBeanName = processorMBeanName + ",subtype=matcher,index=" + 
(i+1) + ",matchername=" + matcher.getMatcherName();

-            String matcherMBeanName = processorMBeanName + ",subtype=matcher,index=" + 
(i+1) + ",matchername=" + matcherConfig.getMatcherName();
-            MatcherManagement matcherMBean = new 
MatcherManagement(matcherConfig);
-            registerMBean(mBeanServer, matcherMBeanName, matcherMBean);
+            registerMBean(mBeanServer, matcherMBeanName, matcher);
          }
+

      }

@@ -451,7 +378,7 @@ public class CamelMailProcessorList impl
          try {
              mBeanServer.registerMBean(object, objectName);
          } catch (javax.management.JMException e) {
-               logger.info("Unable to register mbean", e);
+            logger.error("Unable to register mbean", e);
          }
      }

@@ -475,8 +402,8 @@ public class CamelMailProcessorList impl
                    String processorName = 
processorConf.getString("[...@name]");

        
-                   mailets.put(processorName, new 
ArrayList<MailetMBeanWrapper>());
-                   matchers.put(processorName, new ArrayList<Matcher>());
+                   mailets.put(processorName, new 
ArrayList<MailetManagement>());
+                   matchers.put(processorName, new 
ArrayList<MatcherManagement>());

                    RouteDefinition processorDef = 
from(getEndpoint(processorName)).inOnly()
                    // store the logger in properties
@@ -551,7 +478,8 @@ public class CamelMailProcessorList impl
                            throw new ConfigurationException("Unable to init 
mailet", ex);
                        }
                        if (mailet != null&&  matcher != null) {
-                           MailetMBeanWrapper wrappedMailet = new 
MailetMBeanWrapper(mailet);
+                           MailetManagement wrappedMailet = new 
MailetManagement(mailet);
+                           MatcherManagement wrappedMatcher = new 
MatcherManagement(matcher);
                            String onMatchException = null;
                            MailetConfig mailetConfig = 
wrappedMailet.getMailetConfig();
        
@@ -562,7 +490,7 @@ public class CamelMailProcessorList impl
                            MailetProcessor mailetProccessor = new 
MailetProcessor(wrappedMailet, logger);
                            // 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.MATCHER_PROPERTY, 
constant(wrappedMatcher)).setProperty(MatcherSplitter.ON_MATCH_EXCEPTION_PROPERTY,
 constant(onMatchException))
        
                                    // do splitting of the mail based on the 
stored matcher
                                    
.split().method(MatcherSplitter.class).aggregationStrategy(aggr).parallelProcessing()
@@ -575,7 +503,7 @@ public class CamelMailProcessorList impl

                            // store mailet and matcher
                            mailets.get(processorName).add(wrappedMailet);
-                           matchers.get(processorName).add(matcher);
+                           matchers.get(processorName).add(wrappedMatcher);
                        }
        

@@ -596,7 +524,7 @@ public class CamelMailProcessorList impl
                             // route it to the next processor
                            .otherwise().process(mailProcessor).stop();
        
-                   processors.put(processorName, new 
ChildMailProcessor(processorName));
+                   processors.put(processorName, new 
ProcessorDetail(processorName,new ChildProcessor(processorName)));
                }
        
            }

Copied: 
james/server/trunk/mailetcontainer-impl/src/main/java/org/apache/james/mailetcontainer/MailetManagement.java
 (from r1022183, 
james/server/trunk/mailetcontainer-impl/src/main/java/org/apache/james/mailetcontainer/MailetMBeanWrapper.java)
URL: 
http://svn.apache.org/viewvc/james/server/trunk/mailetcontainer-impl/src/main/java/org/apache/james/mailetcontainer/MailetManagement.java?p2=james/server/trunk/mailetcontainer-impl/src/main/java/org/apache/james/mailetcontainer/MailetManagement.java&p1=james/server/trunk/mailetcontainer-impl/src/main/java/org/apache/james/mailetcontainer/MailetMBeanWrapper.java&r1=1022183&r2=1022235&rev=1022235&view=diff
==============================================================================
--- 
james/server/trunk/mailetcontainer-impl/src/main/java/org/apache/james/mailetcontainer/MailetMBeanWrapper.java
 (original)
+++ 
james/server/trunk/mailetcontainer-impl/src/main/java/org/apache/james/mailetcontainer/MailetManagement.java
 Wed Oct 13 18:49:36 2010
@@ -35,7 +35,7 @@ import org.apache.mailet.MailetConfig;
   *
   *
   */
-public final class MailetMBeanWrapper implements Mailet, MailetManagementMBean{
+public final class MailetManagement implements Mailet, MailetManagementMBean{

      private final Mailet mailet;
      private long errorCount = 0;
@@ -43,7 +43,7 @@ public final class MailetMBeanWrapper im
      private long fastestProcessing = -1;
      private long slowestProcessing = -1;

-    public MailetMBeanWrapper(final Mailet mailet) {
+    public MailetManagement(Mailet mailet) {
          this.mailet = mailet;
      }


Modified: 
james/server/trunk/mailetcontainer-impl/src/main/java/org/apache/james/mailetcontainer/MatcherManagement.java
URL: 
http://svn.apache.org/viewvc/james/server/trunk/mailetcontainer-impl/src/main/java/org/apache/james/mailetcontainer/MatcherManagement.java?rev=1022235&r1=1022234&r2=1022235&view=diff
==============================================================================
--- 
james/server/trunk/mailetcontainer-impl/src/main/java/org/apache/james/mailetcontainer/MatcherManagement.java
 (original)
+++ 
james/server/trunk/mailetcontainer-impl/src/main/java/org/apache/james/mailetcontainer/MatcherManagement.java
 Wed Oct 13 18:49:36 2010
@@ -18,21 +18,162 @@
   ****************************************************************/
  package org.apache.james.mailetcontainer;

-import org.apache.mailet.MatcherConfig;
+import java.util.Collection;
+
+import javax.mail.MessagingException;

-public class MatcherManagement implements MatcherManagementMBean {
-    private MatcherConfig matcherConfig;
+import org.apache.mailet.Mail;
+import org.apache.mailet.Matcher;
+import org.apache.mailet.MatcherConfig;

-    public MatcherManagement(MatcherConfig matcherConfig) {
-        this.matcherConfig = matcherConfig;
+public final class MatcherManagement implements MatcherManagementMBean, 
Matcher{
+    private Matcher matcher;
+    private long slowestProcessing = -1;
+    private long fastestProcessing = -1;
+    private long successCount = 0;
+    private long errorCount = 0;
+    private long matched = 0;
+    private long notMatched = 0;
+    public MatcherManagement(Matcher matcher) {
+        this.matcher = matcher;
      }

+    /*
+     * (non-Javadoc)
+     * @see 
org.apache.james.mailetcontainer.MatcherManagementMBean#getMatcherName()
+     */
      public String getMatcherName() {
-        return matcherConfig.getMatcherName();
+        return matcher.getMatcherConfig().getMatcherName();
      }

+
+    /*
+     * (non-Javadoc)
+     * @see 
org.apache.james.mailetcontainer.MatcherManagementMBean#getMatcherCondition()
+     */
      public String getMatcherCondition() {
-        return matcherConfig.getCondition();
+        return matcher.getMatcherConfig().getCondition();
+    }
+
+    /*
+     * (non-Javadoc)
+     * @see 
org.apache.james.mailetcontainer.MailProcessingMBean#getErrorCount()
+     */
+    public long getErrorCount() {
+        return errorCount;
+    }
+
+    /*
+     * (non-Javadoc)
+     * @see 
org.apache.james.mailetcontainer.MailProcessingMBean#getFastestProcessing()
+     */
+    public long getFastestProcessing() {
+        return fastestProcessing;
+    }
+
+    /*
+     * (non-Javadoc)
+     * @see 
org.apache.james.mailetcontainer.MailProcessingMBean#getHandledMailCount()
+     */
+    public long getHandledMailCount() {
+        return getSuccessCount() + getErrorCount();
+
+    }
+
+    /*
+     * (non-Javadoc)
+     * @see 
org.apache.james.mailetcontainer.MailProcessingMBean#getSlowestProcessing()
+     */
+    public long getSlowestProcessing() {
+        return slowestProcessing;
+    }
+
+    /*
+     * (non-Javadoc)
+     * @see 
org.apache.james.mailetcontainer.MailProcessingMBean#getSuccessCount()
+     */
+    public long getSuccessCount() {
+        return successCount;
+    }
+
+    /*
+     * (non-Javadoc)
+     * @see org.apache.mailet.Matcher#destroy()
+     */
+    public void destroy() {
+        matcher.destroy();
+    }
+
+    /*
+     * (non-Javadoc)
+     * @see org.apache.mailet.Matcher#getMatcherConfig()
+     */
+    public MatcherConfig getMatcherConfig() {
+        return matcher.getMatcherConfig();
+    }
+
+    /*
+     * (non-Javadoc)
+     * @see org.apache.mailet.Matcher#getMatcherInfo()
+     */
+    public String getMatcherInfo() {
+        return matcher.getMatcherInfo();
+    }
+
+    /*
+     * (non-Javadoc)
+     * @see org.apache.mailet.Matcher#init(org.apache.mailet.MatcherConfig)
+     */
+    public void init(MatcherConfig config) throws MessagingException {
+        matcher.init(config);
+    }
+
+    @SuppressWarnings("unchecked")
+    public Collection match(Mail mail) throws MessagingException {
+        try {
+            long startProcessing = System.currentTimeMillis();
+             Collection origRcpts = mail.getRecipients();
+             Collection rcpts =  matcher.match(mail);
+
+             long processTime = System.currentTimeMillis() - startProcessing;
+             if (processTime>  slowestProcessing) {
+                 slowestProcessing = processTime;
+             }
+             if (fastestProcessing == -1 || fastestProcessing>  processTime) {
+                 fastestProcessing = processTime;
+             }
+             successCount++;
+
+             long match = 0;
+             if (rcpts != null) {
+                  match = rcpts.size();
+                  matched =+ match;
+             }
+
+             if (origRcpts != null) {
+                 notMatched =+ origRcpts.size() - match;
+             }
+             return rcpts;
+         } catch (MessagingException ex) {
+             errorCount++;
+             throw ex;
+         }
+    }
+
+    /*
+     * (non-Javadoc)
+     * @see 
org.apache.james.mailetcontainer.MatcherManagementMBean#getMatchedRecipientCount()
+     */
+    public long getMatchedRecipientCount() {
+        return matched;
+    }
+
+    /*
+     * (non-Javadoc)
+     * @see 
org.apache.james.mailetcontainer.MatcherManagementMBean#getNotMatchedRecipientCount()
+     */
+    public long getNotMatchedRecipientCount() {
+        return notMatched;
      }
  }


Added: 
james/server/trunk/mailetcontainer-impl/src/main/java/org/apache/james/mailetcontainer/ProcessorDetail.java
URL: 
http://svn.apache.org/viewvc/james/server/trunk/mailetcontainer-impl/src/main/java/org/apache/james/mailetcontainer/ProcessorDetail.java?rev=1022235&view=auto
==============================================================================
--- 
james/server/trunk/mailetcontainer-impl/src/main/java/org/apache/james/mailetcontainer/ProcessorDetail.java
 (added)
+++ 
james/server/trunk/mailetcontainer-impl/src/main/java/org/apache/james/mailetcontainer/ProcessorDetail.java
 Wed Oct 13 18:49:36 2010
@@ -0,0 +1,156 @@
+/****************************************************************
+ * 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.mailetcontainer;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import javax.mail.MessagingException;
+
+import org.apache.mailet.Mail;
+import org.apache.mailet.Mailet;
+import org.apache.mailet.Matcher;
+
+/**
+ * Wrapper which helps to expose JMX statistics for {...@link MailProcessor} 
and {...@link MailetContainer} implementations
+ *
+ *
+ */
+public class ProcessorDetail implements MailProcessor, MailetContainer, 
ProcessorDetailMBean{
+    private String processorName;
+    private long slowestProcessing = -1;
+    private long fastestProcessing = -1;
+    private long successCount = 0;
+    private long errorCount = 0;
+    private MailProcessor processor;
+
+    public ProcessorDetail(String processorName, MailProcessor processor) {
+        this.processorName = processorName;
+        this.processor = processor;
+    }
+
+
+    /*
+     * (non-Javadoc)
+     * @see 
org.apache.james.transport.MailProcessor#service(org.apache.mailet.Mail)
+     */
+    public void service(Mail mail) throws MessagingException {
+        try {
+            long startProcessing = System.currentTimeMillis();
+
+            processor.service(mail);
+
+             long processTime = System.currentTimeMillis() - startProcessing;
+             if (processTime>  slowestProcessing) {
+                 slowestProcessing = processTime;
+             }
+             if (fastestProcessing == -1 || fastestProcessing>  processTime) {
+                 fastestProcessing = processTime;
+             }
+             successCount++;
+         } catch (MessagingException ex) {
+             errorCount++;
+             throw ex;
+         }
+     }
+
+    /*
+     * (non-Javadoc)
+     * @see org.apache.james.transport.MailetContainer#getMailets()
+     */
+    public List<Mailet>  getMailets() {
+        if (processor instanceof MailetContainer) {
+            return ((MailetContainer) processor).getMailets();
+        }
+        return new ArrayList<Mailet>();
+    }
+
+    /*
+     * (non-Javadoc)
+     * @see org.apache.james.transport.MailetContainer#getMatchers()
+     */
+    public List<Matcher>  getMatchers() {
+        if (processor instanceof MailetContainer) {
+            return ((MailetContainer) processor).getMatchers();
+        }
+        return new ArrayList<Matcher>();
+    }
+
+    /*
+     * (non-Javadoc)
+     *
+     * @see
+     * 
org.apache.james.mailetcontainer.ProcessorDetailMBean#getHandledMailCount
+     * ()
+     */
+    public long getHandledMailCount() {
+        return getSuccessCount() + getErrorCount();
+    }
+
+    /*
+     * (non-Javadoc)
+     *
+     * @see org.apache.james.mailetcontainer.ProcessorDetailMBean#getName()
+     */
+    public String getName() {
+        return processorName;
+    }
+
+    /*
+     * (non-Javadoc)
+     *
+     * @seeorg.apache.james.mailetcontainer.ProcessorDetailMBean#
+     * getFastestProcessing()
+     */
+    public long getFastestProcessing() {
+        return fastestProcessing;
+    }
+
+    /*
+     * (non-Javadoc)
+     *
+     * @seeorg.apache.james.mailetcontainer.ProcessorDetailMBean#
+     * getSlowestProcessing()
+     */
+    public long getSlowestProcessing() {
+        return slowestProcessing;
+    }
+
+    /*
+     * (non-Javadoc)
+     *
+     * @see
+     * org.apache.james.mailetcontainer.ProcessorDetailMBean#getErrorCount()
+     */
+    public long getErrorCount() {
+        return errorCount;
+    }
+
+    /*
+     * (non-Javadoc)
+     *
+     * @see
+     * org.apache.james.mailetcontainer.ProcessorDetailMBean#getSuccessCount
+     * ()
+     */
+    public long getSuccessCount() {
+        return successCount;
+    }
+}

Modified: 
james/server/trunk/spring-deployment/src/main/config/james/spring-beans.xml
URL: 
http://svn.apache.org/viewvc/james/server/trunk/spring-deployment/src/main/config/james/spring-beans.xml?rev=1022235&r1=1022234&r2=1022235&view=diff
==============================================================================
--- james/server/trunk/spring-deployment/src/main/config/james/spring-beans.xml 
(original)
+++ james/server/trunk/spring-deployment/src/main/config/james/spring-beans.xml 
Wed Oct 13 18:49:36 2010
@@ -41,14 +41,15 @@
            <entry key="org.apache.james:type=server,name=pop3server" 
value-ref="pop3server"/>
            <entry key="org.apache.james:type=server,name=imapserver" 
value-ref="imapserver"/>
            <entry key="org.apache.james:type=server,name=remotemanager" 
value-ref="remotemanager"/>
-<entry key="org.apache.james:type=components,name=domainlist" 
value-ref="domainlist"/>
-<entry key="org.apache.james:type=components,name=dnsservice" 
value-ref="dnsservice"/>
+<entry key="org.apache.james:type=component,name=domainlist" 
value-ref="domainlist"/>
+<entry key="org.apache.james:type=component,name=dnsservice" 
value-ref="dnsservice"/>
+<entry key="org.apache.james:type=component,name=processor" 
value-ref="mailProcessor"/>

          </map>
        </property>
        <property name="assembler">
            <bean 
class="org.springframework.jmx.export.assembler.InterfaceBasedMBeanInfoAssembler">
-<property name="managedInterfaces" 
value="org.apache.james.smtpserver.SMTPServerMBean,org.apache.james.socket.ServerMBean,org.apache.james.api.domainlist.DomainListMBean,org.apache.james.api.domainlist.ManageableDomainListMBean,org.apache.james.dnsservice.api.DNSServiceMBean"/>
+<property name="managedInterfaces" 
value="org.apache.james.smtpserver.SMTPServerMBean,org.apache.james.socket.ServerMBean,org.apache.james.api.domainlist.DomainListMBean,org.apache.james.api.domainlist.ManageableDomainListMBean,org.apache.james.dnsservice.api.DNSServiceMBean,org.apache.james.mailetcontainer.ProcessorManagementMBean"/>
            </bean>
        </property>
      </bean>



---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscr...@james.apache.org
For additional commands, e-mail: server-dev-h...@james.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscr...@james.apache.org
For additional commands, e-mail: server-dev-h...@james.apache.org

Reply via email to