james-server-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From nor...@apache.org
Subject svn commit: r1051470 [2/2] - in /james/server/trunk: container-spring/src/main/config/examples/ container-spring/src/main/config/james/context/ mailetcontainer-api/src/main/java/org/apache/james/mailetcontainer/api/ mailetcontainer-api/src/main/java/or...
Date Tue, 21 Dec 2010 12:05:58 GMT
Copied: james/server/trunk/mailetcontainer-library/src/main/java/org/apache/james/mailetcontainer/lib/jmx/MailetManagement.java
(from r1051383, james/server/trunk/mailetcontainer-library/src/main/java/org/apache/james/mailetcontainer/lib/MailetManagement.java)
URL: http://svn.apache.org/viewvc/james/server/trunk/mailetcontainer-library/src/main/java/org/apache/james/mailetcontainer/lib/jmx/MailetManagement.java?p2=james/server/trunk/mailetcontainer-library/src/main/java/org/apache/james/mailetcontainer/lib/jmx/MailetManagement.java&p1=james/server/trunk/mailetcontainer-library/src/main/java/org/apache/james/mailetcontainer/lib/MailetManagement.java&r1=1051383&r2=1051470&rev=1051470&view=diff
==============================================================================
--- james/server/trunk/mailetcontainer-library/src/main/java/org/apache/james/mailetcontainer/lib/MailetManagement.java
(original)
+++ james/server/trunk/mailetcontainer-library/src/main/java/org/apache/james/mailetcontainer/lib/jmx/MailetManagement.java
Tue Dec 21 12:05:57 2010
@@ -16,111 +16,56 @@
  * specific language governing permissions and limitations      *
  * under the License.                                           *
  ****************************************************************/
-package org.apache.james.mailetcontainer.lib;
+package org.apache.james.mailetcontainer.lib.jmx;
 
 import java.util.ArrayList;
 import java.util.Iterator;
 import java.util.List;
+import java.util.concurrent.atomic.AtomicLong;
 
-import javax.mail.MessagingException;
 import javax.management.NotCompliantMBeanException;
 import javax.management.StandardMBean;
 
-import org.apache.james.mailetcontainer.api.MailetManagementMBean;
-import org.apache.mailet.Mail;
-import org.apache.mailet.Mailet;
+import org.apache.james.mailetcontainer.api.jmx.MailetManagementMBean;
 import org.apache.mailet.MailetConfig;
 
-/**
- * Class which wraps a {@link Mailet} and expose statistics via JMX
- * 
- * 
- * 
- *
- */
-public final class MailetManagement extends StandardMBean implements Mailet, MailetManagementMBean{
-
-    private final Mailet mailet;
-    private long errorCount = 0;
-    private long successCount = 0;
-    private long fastestProcessing = -1;
-    private long slowestProcessing = -1;
+public final class MailetManagement extends StandardMBean implements MailetManagementMBean{
+
+    private AtomicLong errorCount = new AtomicLong(0);
+    private AtomicLong successCount = new AtomicLong(0);
+    private AtomicLong fastestProcessing = new AtomicLong(-1);
+    private AtomicLong slowestProcessing = new AtomicLong(-1);
+    private final MailetConfig config;
     
-    public MailetManagement(Mailet mailet) throws NotCompliantMBeanException {
+    public MailetManagement(MailetConfig config) throws NotCompliantMBeanException {
         super(MailetManagementMBean.class);
-        this.mailet = mailet;
+        this.config = config;
         
     }
-    
-    /*
-     * (non-Javadoc)
-     * @see org.apache.mailet.Mailet#destroy()
-     */
-    public void destroy() {
-        mailet.destroy();
-    }
-
-    /*
-     * (non-Javadoc)
-     * @see org.apache.mailet.Mailet#getMailetConfig()
-     */
-    public MailetConfig getMailetConfig() {
-        return mailet.getMailetConfig();
-    }
-    
-    /*
-     * (non-Javadoc)
-     * @see org.apache.mailet.Mailet#getMailetInfo()
-     */
-    public String getMailetInfo() {
-        return mailet.getMailetInfo();
-    }
-
-    /*
-     * (non-Javadoc)
-     * @see org.apache.mailet.Mailet#init(org.apache.mailet.MailetConfig)
-     */
-    public void init(MailetConfig config) throws MessagingException {
-        mailet.init(config);
-    }
-
-    /*
-     * (non-Javadoc)
-     * @see org.apache.mailet.Mailet#service(org.apache.mailet.Mail)
-     */
-    public void service(Mail mail) throws MessagingException {
-        long startProcessing = System.currentTimeMillis();
-        try {
-            mailet.service(mail);
-            long processTime = System.currentTimeMillis() - startProcessing;
-            if (processTime > slowestProcessing) {
-                slowestProcessing = processTime;
-            }
-            if (fastestProcessing == -1 || fastestProcessing > processTime) {
-                fastestProcessing = processTime;
-            }
-            successCount++;
-        } catch (MessagingException e) {
-            errorCount++;
-            throw e;
+ 
+   
+    public void update(long processTime, boolean success) {
+        long fastest = fastestProcessing.get();
+        
+        if ( fastest > processTime || fastest == -1) {
+            fastestProcessing.set(processTime);
         }
-    }
-    
-    /**
-     * Return the wrapped {@link Mailet}
-     * 
-     * @return mailet
-     */
-    public Mailet getMailet() {
-        return mailet;
-    }
-
+        
+        if (slowestProcessing.get() < processTime) {
+            slowestProcessing.set(processTime);
+        }
+        if (success) {
+            successCount.incrementAndGet();
+        } else {
+            errorCount.incrementAndGet();
+        }
+    } 
     /*
      * (non-Javadoc)
      * @see org.apache.james.mailetcontainer.MailetManagementMBean#getMailetName()
      */
     public String getMailetName() {
-        return mailet.getMailetConfig().getMailetName();
+        return config.getMailetName();
     }
 
     /*
@@ -129,11 +74,10 @@ public final class MailetManagement exte
     @SuppressWarnings("unchecked")
     public String[] getMailetParameters() {
         List<String> parameterList = new ArrayList<String>();
-        MailetConfig mailetConfig = getMailet().getMailetConfig();
-        Iterator<String> iterator = mailetConfig.getInitParameterNames();
+        Iterator<String> iterator = config.getInitParameterNames();
         while (iterator.hasNext()) {
             String name = (String) iterator.next();
-            String value = mailetConfig.getInitParameter(name);
+            String value = config.getInitParameter(name);
             parameterList.add(name + "=" + value);
         }
         String[] result = (String[]) parameterList.toArray(new String[] {});
@@ -145,7 +89,7 @@ public final class MailetManagement exte
      * @see org.apache.james.mailetcontainer.MailetManagementMBean#getErrorCount()
      */
     public long getErrorCount() {
-        return errorCount;
+        return errorCount.get();
     }
 
     /*
@@ -153,7 +97,7 @@ public final class MailetManagement exte
      * @see org.apache.james.mailetcontainer.MailetManagementMBean#getFastestProcessing()
      */
     public long getFastestProcessing() {
-        return fastestProcessing;
+        return fastestProcessing.get();
     }
 
     /*
@@ -169,7 +113,7 @@ public final class MailetManagement exte
      * @see org.apache.james.mailetcontainer.MailetManagementMBean#getSlowestProcessing()
      */
     public long getSlowestProcessing() {
-        return slowestProcessing;
+        return slowestProcessing.get();
     }
 
     /*
@@ -177,7 +121,7 @@ public final class MailetManagement exte
      * @see org.apache.james.mailetcontainer.MailetManagementMBean#getSuccessCount()
      */
     public long getSuccessCount() {
-        return successCount;
+        return successCount.get();
     }
 
 }

Copied: james/server/trunk/mailetcontainer-library/src/main/java/org/apache/james/mailetcontainer/lib/jmx/MatcherManagement.java
(from r1051383, james/server/trunk/mailetcontainer-library/src/main/java/org/apache/james/mailetcontainer/lib/MatcherManagement.java)
URL: http://svn.apache.org/viewvc/james/server/trunk/mailetcontainer-library/src/main/java/org/apache/james/mailetcontainer/lib/jmx/MatcherManagement.java?p2=james/server/trunk/mailetcontainer-library/src/main/java/org/apache/james/mailetcontainer/lib/jmx/MatcherManagement.java&p1=james/server/trunk/mailetcontainer-library/src/main/java/org/apache/james/mailetcontainer/lib/MatcherManagement.java&r1=1051383&r2=1051470&rev=1051470&view=diff
==============================================================================
--- james/server/trunk/mailetcontainer-library/src/main/java/org/apache/james/mailetcontainer/lib/MatcherManagement.java
(original)
+++ james/server/trunk/mailetcontainer-library/src/main/java/org/apache/james/mailetcontainer/lib/jmx/MatcherManagement.java
Tue Dec 21 12:05:57 2010
@@ -16,47 +16,56 @@
  * specific language governing permissions and limitations      *
  * under the License.                                           *
  ****************************************************************/
-package org.apache.james.mailetcontainer.lib;
+package org.apache.james.mailetcontainer.lib.jmx;
 
-import java.util.Collection;
+import java.util.concurrent.atomic.AtomicLong;
 
-import javax.mail.MessagingException;
 import javax.management.NotCompliantMBeanException;
 import javax.management.StandardMBean;
 
-import org.apache.james.mailetcontainer.api.MatcherManagementMBean;
-import org.apache.mailet.Mail;
-import org.apache.mailet.Matcher;
+import org.apache.james.mailetcontainer.api.jmx.MatcherManagementMBean;
 import org.apache.mailet.MatcherConfig;
 
-/**
- * JMX MBean which will collection statistics for the wrapped {@link Matcher}
- * 
- *
- */
-public final class MatcherManagement extends StandardMBean 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 final class MatcherManagement extends StandardMBean implements MatcherManagementMBean{
+    private MatcherConfig matcherConfig;
+    private AtomicLong errorCount = new AtomicLong(0);
+    private AtomicLong successCount = new AtomicLong(0);
+    private AtomicLong fastestProcessing = new AtomicLong(-1);
+    private AtomicLong slowestProcessing = new AtomicLong(-1);
+    private AtomicLong matchedCount = new AtomicLong(0);
+    private AtomicLong notMatchedCount = new AtomicLong(0);
     
-    public MatcherManagement(Matcher matcher) throws NotCompliantMBeanException {
+    public MatcherManagement(MatcherConfig matcherConfig) throws NotCompliantMBeanException
{
         super(MatcherManagementMBean.class);
-        this.matcher = matcher;
+        this.matcherConfig = matcherConfig;
 
     }
 
-    /**
-     * Return the wrapped {@link Matcher}
-     * 
-     * @return wrappedMatcher
-     */
-    public Matcher getMatcher() {
-        return matcher;
-    }
+
+    public void update(long processTime, boolean success, boolean matched) {
+        long fastest = fastestProcessing.get();
+        
+        if ( fastest > processTime || fastest == -1) {
+            fastestProcessing.set(processTime);
+        }
+        
+        if (slowestProcessing.get() < processTime) {
+            slowestProcessing.set(processTime);
+        }
+        if (success) {
+            successCount.incrementAndGet();
+        } else {
+            errorCount.incrementAndGet();
+        }
+        if (matched) {
+            matchedCount.incrementAndGet();
+        } else {
+            notMatchedCount.incrementAndGet();
+        }
+        
+    } 
+    
     
     
     /*
@@ -64,7 +73,7 @@ public final class MatcherManagement ext
      * @see org.apache.james.mailetcontainer.MatcherManagementMBean#getMatcherName()
      */
     public String getMatcherName() {
-        return matcher.getMatcherConfig().getMatcherName();
+        return matcherConfig.getMatcherName();
     }
     
     
@@ -73,7 +82,7 @@ public final class MatcherManagement ext
      * @see org.apache.james.mailetcontainer.MatcherManagementMBean#getMatcherCondition()
      */
     public String getMatcherCondition() {
-        return matcher.getMatcherConfig().getCondition();
+        return matcherConfig.getCondition();
     }
 
     /*
@@ -81,7 +90,7 @@ public final class MatcherManagement ext
      * @see org.apache.james.mailetcontainer.MailProcessingMBean#getErrorCount()
      */
     public long getErrorCount() {
-        return errorCount;
+        return errorCount.get();
     }
 
     /*
@@ -89,7 +98,7 @@ public final class MatcherManagement ext
      * @see org.apache.james.mailetcontainer.MailProcessingMBean#getFastestProcessing()
      */
     public long getFastestProcessing() {
-        return fastestProcessing;
+        return fastestProcessing.get();
     }
 
     /*
@@ -106,7 +115,7 @@ public final class MatcherManagement ext
      * @see org.apache.james.mailetcontainer.MailProcessingMBean#getSlowestProcessing()
      */
     public long getSlowestProcessing() {
-        return slowestProcessing;
+        return slowestProcessing.get();
     }
 
     /*
@@ -114,79 +123,16 @@ public final class MatcherManagement ext
      * @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();
+        return successCount.get();
     }
 
-    /*
-     * (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;
+        return matchedCount.get();
     }
 
     /*
@@ -194,7 +140,7 @@ public final class MatcherManagement ext
      * @see org.apache.james.mailetcontainer.MatcherManagementMBean#getNotMatchedRecipientCount()
      */
     public long getNotMatchedRecipientCount() {
-        return notMatched;
+        return notMatchedCount.get();
     }
 }
 



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