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 no...@apache.org on 2010/12/21 13:05:58 UTC

svn commit: r1051470 [1/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...

Author: norman
Date: Tue Dec 21 12:05:57 2010
New Revision: 1051470

URL: http://svn.apache.org/viewvc?rev=1051470&view=rev
Log:
Add listener support for Mailetcontainer and MailProcessorList and reuse it for JMX support. See JAMES-1059 and JAMES-1057

Added:
    james/server/trunk/mailetcontainer-api/src/main/java/org/apache/james/mailetcontainer/api/MailProcessorListListener.java
    james/server/trunk/mailetcontainer-api/src/main/java/org/apache/james/mailetcontainer/api/MailetContainerListener.java
    james/server/trunk/mailetcontainer-api/src/main/java/org/apache/james/mailetcontainer/api/jmx/
    james/server/trunk/mailetcontainer-api/src/main/java/org/apache/james/mailetcontainer/api/jmx/MailProcessingMBean.java
      - copied, changed from r1051383, james/server/trunk/mailetcontainer-api/src/main/java/org/apache/james/mailetcontainer/api/MailProcessingMBean.java
    james/server/trunk/mailetcontainer-api/src/main/java/org/apache/james/mailetcontainer/api/jmx/MailProcessorManagementMBean.java
      - copied, changed from r1051383, james/server/trunk/mailetcontainer-api/src/main/java/org/apache/james/mailetcontainer/api/ProcessorDetailMBean.java
    james/server/trunk/mailetcontainer-api/src/main/java/org/apache/james/mailetcontainer/api/jmx/MailSpoolerMBean.java
      - copied, changed from r1051383, james/server/trunk/mailetcontainer-api/src/main/java/org/apache/james/mailetcontainer/api/MailSpoolerMBean.java
    james/server/trunk/mailetcontainer-api/src/main/java/org/apache/james/mailetcontainer/api/jmx/MailetManagementMBean.java
      - copied, changed from r1051383, james/server/trunk/mailetcontainer-api/src/main/java/org/apache/james/mailetcontainer/api/MailetManagementMBean.java
    james/server/trunk/mailetcontainer-api/src/main/java/org/apache/james/mailetcontainer/api/jmx/MatcherManagementMBean.java
      - copied, changed from r1051383, james/server/trunk/mailetcontainer-api/src/main/java/org/apache/james/mailetcontainer/api/MatcherManagementMBean.java
    james/server/trunk/mailetcontainer-api/src/main/java/org/apache/james/mailetcontainer/api/jmx/ProcessorManagementMBean.java
      - copied, changed from r1051383, james/server/trunk/mailetcontainer-api/src/main/java/org/apache/james/mailetcontainer/api/ProcessorManagementMBean.java
    james/server/trunk/mailetcontainer-library/src/main/java/org/apache/james/mailetcontainer/lib/jmx/
    james/server/trunk/mailetcontainer-library/src/main/java/org/apache/james/mailetcontainer/lib/jmx/JMXMailProcessorListListener.java
    james/server/trunk/mailetcontainer-library/src/main/java/org/apache/james/mailetcontainer/lib/jmx/JMXMailetContainerListener.java
    james/server/trunk/mailetcontainer-library/src/main/java/org/apache/james/mailetcontainer/lib/jmx/MailProcessorManagement.java
      - copied, changed from r1051383, james/server/trunk/mailetcontainer-library/src/main/java/org/apache/james/mailetcontainer/lib/ProcessorDetail.java
    james/server/trunk/mailetcontainer-library/src/main/java/org/apache/james/mailetcontainer/lib/jmx/MailetManagement.java
      - copied, changed from r1051383, james/server/trunk/mailetcontainer-library/src/main/java/org/apache/james/mailetcontainer/lib/MailetManagement.java
    james/server/trunk/mailetcontainer-library/src/main/java/org/apache/james/mailetcontainer/lib/jmx/MatcherManagement.java
      - copied, changed from r1051383, james/server/trunk/mailetcontainer-library/src/main/java/org/apache/james/mailetcontainer/lib/MatcherManagement.java
Removed:
    james/server/trunk/mailetcontainer-api/src/main/java/org/apache/james/mailetcontainer/api/MailProcessingMBean.java
    james/server/trunk/mailetcontainer-api/src/main/java/org/apache/james/mailetcontainer/api/MailSpoolerMBean.java
    james/server/trunk/mailetcontainer-api/src/main/java/org/apache/james/mailetcontainer/api/MailetManagementMBean.java
    james/server/trunk/mailetcontainer-api/src/main/java/org/apache/james/mailetcontainer/api/MatcherManagementMBean.java
    james/server/trunk/mailetcontainer-api/src/main/java/org/apache/james/mailetcontainer/api/ProcessorDetailMBean.java
    james/server/trunk/mailetcontainer-api/src/main/java/org/apache/james/mailetcontainer/api/ProcessorManagementMBean.java
    james/server/trunk/mailetcontainer-library/src/main/java/org/apache/james/mailetcontainer/lib/MailetManagement.java
    james/server/trunk/mailetcontainer-library/src/main/java/org/apache/james/mailetcontainer/lib/MatcherManagement.java
    james/server/trunk/mailetcontainer-library/src/main/java/org/apache/james/mailetcontainer/lib/ProcessorDetail.java
    james/server/trunk/mailetcontainer-library/src/main/java/org/apache/james/mailetcontainer/lib/ProcessorManagement.java
Modified:
    james/server/trunk/container-spring/src/main/config/examples/mailetcontainer.xml
    james/server/trunk/container-spring/src/main/config/james/context/james-server-context.xml
    james/server/trunk/mailetcontainer-api/src/main/java/org/apache/james/mailetcontainer/api/MailProcessor.java
    james/server/trunk/mailetcontainer-api/src/main/java/org/apache/james/mailetcontainer/api/MailProcessorList.java
    james/server/trunk/mailetcontainer-api/src/main/java/org/apache/james/mailetcontainer/api/MailetContainer.java
    james/server/trunk/mailetcontainer-camel/src/main/java/org/apache/james/mailetcontainer/camel/CamelMailProcessorList.java
    james/server/trunk/mailetcontainer-camel/src/main/java/org/apache/james/mailetcontainer/camel/MailetProcessor.java
    james/server/trunk/mailetcontainer-camel/src/main/java/org/apache/james/mailetcontainer/camel/MatcherSplitter.java
    james/server/trunk/mailetcontainer-library/src/main/java/org/apache/james/mailetcontainer/lib/JamesMailSpooler.java

Modified: james/server/trunk/container-spring/src/main/config/examples/mailetcontainer.xml
URL: http://svn.apache.org/viewvc/james/server/trunk/container-spring/src/main/config/examples/mailetcontainer.xml?rev=1051470&r1=1051469&r2=1051470&view=diff
==============================================================================
--- james/server/trunk/container-spring/src/main/config/examples/mailetcontainer.xml (original)
+++ james/server/trunk/container-spring/src/main/config/examples/mailetcontainer.xml Tue Dec 21 12:05:57 2010
@@ -24,6 +24,9 @@
 
       <!-- Number of spool threads -->
       <threads> 20 </threads>
+      
+      <!-- expose JMX MBeans -->
+      <enableJmx>true</enableJmx>
 
       
       <!-- The root processor is a required processor - James routes all mail on the spool -->

Modified: james/server/trunk/container-spring/src/main/config/james/context/james-server-context.xml
URL: http://svn.apache.org/viewvc/james/server/trunk/container-spring/src/main/config/james/context/james-server-context.xml?rev=1051470&r1=1051469&r2=1051470&view=diff
==============================================================================
--- james/server/trunk/container-spring/src/main/config/james/context/james-server-context.xml (original)
+++ james/server/trunk/container-spring/src/main/config/james/context/james-server-context.xml Tue Dec 21 12:05:57 2010
@@ -390,7 +390,6 @@
           <entry key="org.apache.james:type=server,name=remotemanager" value-ref="remotemanager"/>
           <entry key="org.apache.james:type=component,name=domainlist" value-ref="domainlistmanagement"/>
           <entry key="org.apache.james:type=component,name=dnsservice" value-ref="dnsservice"/>
-          <entry key="org.apache.james:type=component,name=processor" value-ref="processormanagement"/>
           <entry key="org.apache.james:type=component,name=virtualusertable" value-ref="virtualusertablemanagement"/>
           <entry key="org.apache.james:type=component,name=usermanagement" value-ref="usermanagement"/>
           <entry key="org.apache.james:type=component,name=fetchmail" value-ref="fetchmail"/>
@@ -401,11 +400,10 @@
       </property>
       <property name="assembler">
           <bean class="org.springframework.jmx.export.assembler.InterfaceBasedMBeanInfoAssembler">
-            <property name="managedInterfaces" value="org.apache.james.smtpserver.netty.SMTPServerMBean,org.apache.james.remotemanager.netty.RemoteManagerMBean,org.apache.james.pop3server.netty.POP3ServerMBean,org.apache.james.imapserver.netty.IMAPServerMBean,org.apache.james.fetchmail.FetchSchedulerMBean,org.apache.james.domainlist.api.DomainListManagementMBean,org.apache.james.dnsservice.api.DNSServiceMBean,org.apache.james.mailetcontainer.api.ProcessorManagementMBean,org.apache.james.vut.api.VirtualUserTableManagementMBean,org.apache.james.user.api.UserManagementMBean,org.apache.james.adapter.mailbox.MailboxManagerManagementMBean,org.apache.james.mailbox.copier.MailboxCopierManagementMBean,org.apache.james.mailetcontainer.api.MailSpoolerMBean"/>
+            <property name="managedInterfaces" value="org.apache.james.smtpserver.netty.SMTPServerMBean,org.apache.james.remotemanager.netty.RemoteManagerMBean,org.apache.james.pop3server.netty.POP3ServerMBean,org.apache.james.imapserver.netty.IMAPServerMBean,org.apache.james.fetchmail.FetchSchedulerMBean,org.apache.james.domainlist.api.DomainListManagementMBean,org.apache.james.dnsservice.api.DNSServiceMBean,org.apache.james.vut.api.VirtualUserTableManagementMBean,org.apache.james.user.api.UserManagementMBean,org.apache.james.adapter.mailbox.MailboxManagerManagementMBean,org.apache.james.mailbox.copier.MailboxCopierManagementMBean,org.apache.james.mailetcontainer.api.jmx.MailSpoolerMBean"/>
           </bean>
       </property>
     </bean>
-    <bean id="processormanagement" class="org.apache.james.mailetcontainer.lib.ProcessorManagement"/>
     <bean id="usermanagement" class="org.apache.james.user.lib.UserManagement" />
     <bean id="virtualusertablemanagement" class="org.apache.james.vut.lib.VirtualUserTableManagement" />
     <bean id="domainlistmanagement" class="org.apache.james.domainlist.lib.DomainListManagement" />

Modified: james/server/trunk/mailetcontainer-api/src/main/java/org/apache/james/mailetcontainer/api/MailProcessor.java
URL: http://svn.apache.org/viewvc/james/server/trunk/mailetcontainer-api/src/main/java/org/apache/james/mailetcontainer/api/MailProcessor.java?rev=1051470&r1=1051469&r2=1051470&view=diff
==============================================================================
--- james/server/trunk/mailetcontainer-api/src/main/java/org/apache/james/mailetcontainer/api/MailProcessor.java (original)
+++ james/server/trunk/mailetcontainer-api/src/main/java/org/apache/james/mailetcontainer/api/MailProcessor.java Tue Dec 21 12:05:57 2010
@@ -53,5 +53,6 @@ public interface MailProcessor {
      *      an exception that interferes with the mailet's normal operation
      */
     void service(Mail mail) throws javax.mail.MessagingException;
+    
 }
 

Modified: james/server/trunk/mailetcontainer-api/src/main/java/org/apache/james/mailetcontainer/api/MailProcessorList.java
URL: http://svn.apache.org/viewvc/james/server/trunk/mailetcontainer-api/src/main/java/org/apache/james/mailetcontainer/api/MailProcessorList.java?rev=1051470&r1=1051469&r2=1051470&view=diff
==============================================================================
--- james/server/trunk/mailetcontainer-api/src/main/java/org/apache/james/mailetcontainer/api/MailProcessorList.java (original)
+++ james/server/trunk/mailetcontainer-api/src/main/java/org/apache/james/mailetcontainer/api/MailProcessorList.java Tue Dec 21 12:05:57 2010
@@ -18,6 +18,8 @@
  ****************************************************************/
 package org.apache.james.mailetcontainer.api;
 
+import java.util.List;
+
 
 /**
  * {@link MailProcessor} which delegate the work to child {@link MailProcessor}
@@ -28,11 +30,32 @@ public interface MailProcessorList exten
     /**
      * @return names of all configured processor
      */
-    String[] getProcessorNames();
+    public String[] getProcessorNames();
 
     /**
      * @return access the child processor
      */
-    MailProcessor getProcessor(String name);
+    public MailProcessor getProcessor(String name);
 
+    /**
+     * Add a {@link MailProcessorListListener} which will get triggered after a child {@link MailProcessor} finish
+     * processing
+     * 
+     * @param listener
+     */
+    public void addListener(MailProcessorListListener listener);
+    
+    /**
+     * Remove a {@link MailProcessorListListener}
+     * 
+     * @param listener
+     */
+    public void removeListener(MailProcessorListListener listener);
+    
+    /**
+     * Return a unmodifiable {@link List} of {@link MailProcessorListListener} which are registered 
+     * 
+     * @return listeners
+     */
+    public List<MailProcessorListListener> getListeners();
 }

Added: james/server/trunk/mailetcontainer-api/src/main/java/org/apache/james/mailetcontainer/api/MailProcessorListListener.java
URL: http://svn.apache.org/viewvc/james/server/trunk/mailetcontainer-api/src/main/java/org/apache/james/mailetcontainer/api/MailProcessorListListener.java?rev=1051470&view=auto
==============================================================================
--- james/server/trunk/mailetcontainer-api/src/main/java/org/apache/james/mailetcontainer/api/MailProcessorListListener.java (added)
+++ james/server/trunk/mailetcontainer-api/src/main/java/org/apache/james/mailetcontainer/api/MailProcessorListListener.java Tue Dec 21 12:05:57 2010
@@ -0,0 +1,39 @@
+/****************************************************************
+ * 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.api;
+
+import javax.mail.MessagingException;
+
+/**
+ * A Listener which will get called after {@link MailProcessor#service(org.apache.mailet.Mail)} was called
+ *
+ */
+public interface MailProcessorListListener {
+
+    /**
+     * Get called after the processing via a {@link MailProcessor} was complete
+     * 
+     * @param processor
+     * @param mailName
+     * @param processTime in ms
+     * @param e or null if no exception was thrown
+     */
+    public void afterProcessor(MailProcessor processor, String mailName, long processTime, MessagingException e);
+
+}

Modified: james/server/trunk/mailetcontainer-api/src/main/java/org/apache/james/mailetcontainer/api/MailetContainer.java
URL: http://svn.apache.org/viewvc/james/server/trunk/mailetcontainer-api/src/main/java/org/apache/james/mailetcontainer/api/MailetContainer.java?rev=1051470&r1=1051469&r2=1051470&view=diff
==============================================================================
--- james/server/trunk/mailetcontainer-api/src/main/java/org/apache/james/mailetcontainer/api/MailetContainer.java (original)
+++ james/server/trunk/mailetcontainer-api/src/main/java/org/apache/james/mailetcontainer/api/MailetContainer.java Tue Dec 21 12:05:57 2010
@@ -35,13 +35,34 @@ public interface MailetContainer extends
      * retrieve mailet configuration data for introspection
      * @return List<MailetConfig>
      */
-    List<Mailet> getMailets();
+    public List<Mailet> getMailets();
 
     /**
      * retrieve matcher configuration data for introspection
      * @return List<MatcherConfig>
      */
-    List<Matcher> getMatchers();
+    public List<Matcher> getMatchers();
+    
+    /**
+     * Add a {@link MailetContainerListener} which will get triggered after a matcher / mailet was called
+     * 
+     * @param listener
+     */
+    public void addListener(MailetContainerListener listener);
+    
+    /**
+     * Remove a {@link MailetContainerListener}
+     * 
+     * @param listener
+     */
+    public void removeListener(MailetContainerListener listener);
+    
+    /**
+     * Return a unmodifiable {@link List} of {@link MailetContainerListener} which are registered 
+     * 
+     * @return listeners
+     */
+    public List<MailetContainerListener> getListeners();
 
 }
 

Added: james/server/trunk/mailetcontainer-api/src/main/java/org/apache/james/mailetcontainer/api/MailetContainerListener.java
URL: http://svn.apache.org/viewvc/james/server/trunk/mailetcontainer-api/src/main/java/org/apache/james/mailetcontainer/api/MailetContainerListener.java?rev=1051470&view=auto
==============================================================================
--- james/server/trunk/mailetcontainer-api/src/main/java/org/apache/james/mailetcontainer/api/MailetContainerListener.java (added)
+++ james/server/trunk/mailetcontainer-api/src/main/java/org/apache/james/mailetcontainer/api/MailetContainerListener.java Tue Dec 21 12:05:57 2010
@@ -0,0 +1,61 @@
+/****************************************************************
+ * 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.api;
+
+import java.util.Collection;
+
+import javax.mail.MessagingException;
+
+import org.apache.mailet.MailAddress;
+import org.apache.mailet.Mailet;
+import org.apache.mailet.Matcher;
+
+/**
+ * A Listener which will get notified after {@link Mailet#service(org.apache.mailet.Mail)} and {@link Matcher#match(org.apache.mailet.Mail)} methods are called from
+ * the container
+ *  
+ *
+ */
+public interface MailetContainerListener {
+
+    /**
+     * Get called after each {@link Mailet} call was complete 
+     * 
+     * @param m
+     * @param mailName
+     * @param state
+     * @param processTime in ms
+     * @param e or null if no {@link MessagingException} was thrown
+     */
+    public void afterMailet( Mailet m, String mailName, String state, long processTime, MessagingException e);
+    
+    /**
+     * Get called after each {@link Matcher} call was complete 
+
+     * @param m
+     * @param mailName
+     * @param recipients
+     * @param matches 
+     * @param processTime in ms
+     * @param e or null if no {@link MessagingException} was thrown
+     * 
+     */
+    public void afterMatcher( Matcher m,  String mailName, Collection<MailAddress> recipients, Collection<MailAddress> matches, long processTime, MessagingException e);
+    
+}

Copied: james/server/trunk/mailetcontainer-api/src/main/java/org/apache/james/mailetcontainer/api/jmx/MailProcessingMBean.java (from r1051383, james/server/trunk/mailetcontainer-api/src/main/java/org/apache/james/mailetcontainer/api/MailProcessingMBean.java)
URL: http://svn.apache.org/viewvc/james/server/trunk/mailetcontainer-api/src/main/java/org/apache/james/mailetcontainer/api/jmx/MailProcessingMBean.java?p2=james/server/trunk/mailetcontainer-api/src/main/java/org/apache/james/mailetcontainer/api/jmx/MailProcessingMBean.java&p1=james/server/trunk/mailetcontainer-api/src/main/java/org/apache/james/mailetcontainer/api/MailProcessingMBean.java&r1=1051383&r2=1051470&rev=1051470&view=diff
==============================================================================
--- james/server/trunk/mailetcontainer-api/src/main/java/org/apache/james/mailetcontainer/api/MailProcessingMBean.java (original)
+++ james/server/trunk/mailetcontainer-api/src/main/java/org/apache/james/mailetcontainer/api/jmx/MailProcessingMBean.java Tue Dec 21 12:05:57 2010
@@ -17,7 +17,7 @@
  * under the License.                                           *
  ****************************************************************/
 
-package org.apache.james.mailetcontainer.api;
+package org.apache.james.mailetcontainer.api.jmx;
 
 public interface MailProcessingMBean {
 

Copied: james/server/trunk/mailetcontainer-api/src/main/java/org/apache/james/mailetcontainer/api/jmx/MailProcessorManagementMBean.java (from r1051383, james/server/trunk/mailetcontainer-api/src/main/java/org/apache/james/mailetcontainer/api/ProcessorDetailMBean.java)
URL: http://svn.apache.org/viewvc/james/server/trunk/mailetcontainer-api/src/main/java/org/apache/james/mailetcontainer/api/jmx/MailProcessorManagementMBean.java?p2=james/server/trunk/mailetcontainer-api/src/main/java/org/apache/james/mailetcontainer/api/jmx/MailProcessorManagementMBean.java&p1=james/server/trunk/mailetcontainer-api/src/main/java/org/apache/james/mailetcontainer/api/ProcessorDetailMBean.java&r1=1051383&r2=1051470&rev=1051470&view=diff
==============================================================================
--- james/server/trunk/mailetcontainer-api/src/main/java/org/apache/james/mailetcontainer/api/ProcessorDetailMBean.java (original)
+++ james/server/trunk/mailetcontainer-api/src/main/java/org/apache/james/mailetcontainer/api/jmx/MailProcessorManagementMBean.java Tue Dec 21 12:05:57 2010
@@ -16,13 +16,14 @@
  * specific language governing permissions and limitations      *
  * under the License.                                           *
  ****************************************************************/
-package org.apache.james.mailetcontainer.api;
+package org.apache.james.mailetcontainer.api.jmx;
+
 
 
 /**
  * MBean for one processor instance
  */
-public interface ProcessorDetailMBean extends MailProcessingMBean{
+public interface MailProcessorManagementMBean extends MailProcessingMBean{
 
     public String getName();
     

Copied: james/server/trunk/mailetcontainer-api/src/main/java/org/apache/james/mailetcontainer/api/jmx/MailSpoolerMBean.java (from r1051383, james/server/trunk/mailetcontainer-api/src/main/java/org/apache/james/mailetcontainer/api/MailSpoolerMBean.java)
URL: http://svn.apache.org/viewvc/james/server/trunk/mailetcontainer-api/src/main/java/org/apache/james/mailetcontainer/api/jmx/MailSpoolerMBean.java?p2=james/server/trunk/mailetcontainer-api/src/main/java/org/apache/james/mailetcontainer/api/jmx/MailSpoolerMBean.java&p1=james/server/trunk/mailetcontainer-api/src/main/java/org/apache/james/mailetcontainer/api/MailSpoolerMBean.java&r1=1051383&r2=1051470&rev=1051470&view=diff
==============================================================================
--- james/server/trunk/mailetcontainer-api/src/main/java/org/apache/james/mailetcontainer/api/MailSpoolerMBean.java (original)
+++ james/server/trunk/mailetcontainer-api/src/main/java/org/apache/james/mailetcontainer/api/jmx/MailSpoolerMBean.java Tue Dec 21 12:05:57 2010
@@ -16,7 +16,7 @@
  * specific language governing permissions and limitations      *
  * under the License.                                           *
  ****************************************************************/
-package org.apache.james.mailetcontainer.api;
+package org.apache.james.mailetcontainer.api.jmx;
 
 /**
  * JMX MBean for MailSpooler 

Copied: james/server/trunk/mailetcontainer-api/src/main/java/org/apache/james/mailetcontainer/api/jmx/MailetManagementMBean.java (from r1051383, james/server/trunk/mailetcontainer-api/src/main/java/org/apache/james/mailetcontainer/api/MailetManagementMBean.java)
URL: http://svn.apache.org/viewvc/james/server/trunk/mailetcontainer-api/src/main/java/org/apache/james/mailetcontainer/api/jmx/MailetManagementMBean.java?p2=james/server/trunk/mailetcontainer-api/src/main/java/org/apache/james/mailetcontainer/api/jmx/MailetManagementMBean.java&p1=james/server/trunk/mailetcontainer-api/src/main/java/org/apache/james/mailetcontainer/api/MailetManagementMBean.java&r1=1051383&r2=1051470&rev=1051470&view=diff
==============================================================================
--- james/server/trunk/mailetcontainer-api/src/main/java/org/apache/james/mailetcontainer/api/MailetManagementMBean.java (original)
+++ james/server/trunk/mailetcontainer-api/src/main/java/org/apache/james/mailetcontainer/api/jmx/MailetManagementMBean.java Tue Dec 21 12:05:57 2010
@@ -17,7 +17,7 @@
  * under the License.                                           *
  ****************************************************************/
 
-package org.apache.james.mailetcontainer.api;
+package org.apache.james.mailetcontainer.api.jmx;
 
 /**
  * management interface for one Mailet instance

Copied: james/server/trunk/mailetcontainer-api/src/main/java/org/apache/james/mailetcontainer/api/jmx/MatcherManagementMBean.java (from r1051383, james/server/trunk/mailetcontainer-api/src/main/java/org/apache/james/mailetcontainer/api/MatcherManagementMBean.java)
URL: http://svn.apache.org/viewvc/james/server/trunk/mailetcontainer-api/src/main/java/org/apache/james/mailetcontainer/api/jmx/MatcherManagementMBean.java?p2=james/server/trunk/mailetcontainer-api/src/main/java/org/apache/james/mailetcontainer/api/jmx/MatcherManagementMBean.java&p1=james/server/trunk/mailetcontainer-api/src/main/java/org/apache/james/mailetcontainer/api/MatcherManagementMBean.java&r1=1051383&r2=1051470&rev=1051470&view=diff
==============================================================================
--- james/server/trunk/mailetcontainer-api/src/main/java/org/apache/james/mailetcontainer/api/MatcherManagementMBean.java (original)
+++ james/server/trunk/mailetcontainer-api/src/main/java/org/apache/james/mailetcontainer/api/jmx/MatcherManagementMBean.java Tue Dec 21 12:05:57 2010
@@ -17,7 +17,7 @@
  * under the License.                                           *
  ****************************************************************/
 
-package org.apache.james.mailetcontainer.api;
+package org.apache.james.mailetcontainer.api.jmx;
 
 /**
  * management interface for one Matcher instance

Copied: james/server/trunk/mailetcontainer-api/src/main/java/org/apache/james/mailetcontainer/api/jmx/ProcessorManagementMBean.java (from r1051383, james/server/trunk/mailetcontainer-api/src/main/java/org/apache/james/mailetcontainer/api/ProcessorManagementMBean.java)
URL: http://svn.apache.org/viewvc/james/server/trunk/mailetcontainer-api/src/main/java/org/apache/james/mailetcontainer/api/jmx/ProcessorManagementMBean.java?p2=james/server/trunk/mailetcontainer-api/src/main/java/org/apache/james/mailetcontainer/api/jmx/ProcessorManagementMBean.java&p1=james/server/trunk/mailetcontainer-api/src/main/java/org/apache/james/mailetcontainer/api/ProcessorManagementMBean.java&r1=1051383&r2=1051470&rev=1051470&view=diff
==============================================================================
--- james/server/trunk/mailetcontainer-api/src/main/java/org/apache/james/mailetcontainer/api/ProcessorManagementMBean.java (original)
+++ james/server/trunk/mailetcontainer-api/src/main/java/org/apache/james/mailetcontainer/api/jmx/ProcessorManagementMBean.java Tue Dec 21 12:05:57 2010
@@ -17,7 +17,7 @@
  * under the License.                                           *
  ****************************************************************/
 
-package org.apache.james.mailetcontainer.api;
+package org.apache.james.mailetcontainer.api.jmx;
 
 /**
  * Expose processor management functionality through JMX.

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=1051470&r1=1051469&r2=1051470&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 Tue Dec 21 12:05:57 2010
@@ -20,6 +20,7 @@
 package org.apache.james.mailetcontainer.camel;
 
 import java.util.ArrayList;
+import java.util.Collections;
 import java.util.HashMap;
 import java.util.Iterator;
 import java.util.List;
@@ -29,6 +30,8 @@ import javax.annotation.PostConstruct;
 import javax.annotation.PreDestroy;
 import javax.annotation.Resource;
 import javax.mail.MessagingException;
+import javax.management.JMException;
+import javax.management.MalformedObjectNameException;
 import javax.management.NotCompliantMBeanException;
 
 import org.apache.camel.CamelContext;
@@ -44,18 +47,20 @@ import org.apache.commons.configuration.
 import org.apache.commons.configuration.HierarchicalConfiguration;
 import org.apache.commons.logging.Log;
 import org.apache.james.lifecycle.api.Configurable;
+import org.apache.james.lifecycle.api.Disposable;
 import org.apache.james.lifecycle.api.LogEnabled;
 import org.apache.james.mailetcontainer.api.MailProcessor;
 import org.apache.james.mailetcontainer.api.MailProcessorList;
+import org.apache.james.mailetcontainer.api.MailProcessorListListener;
+import org.apache.james.mailetcontainer.api.MailetContainerListener;
 import org.apache.james.mailetcontainer.api.MailetContainer;
 import org.apache.james.mailetcontainer.api.MailetLoader;
 import org.apache.james.mailetcontainer.api.MatcherLoader;
-import org.apache.james.mailetcontainer.api.ProcessorManagementMBean;
+import org.apache.james.mailetcontainer.api.jmx.ProcessorManagementMBean;
 import org.apache.james.mailetcontainer.lib.MailetConfigImpl;
-import org.apache.james.mailetcontainer.lib.MailetManagement;
 import org.apache.james.mailetcontainer.lib.MatcherConfigImpl;
-import org.apache.james.mailetcontainer.lib.MatcherManagement;
-import org.apache.james.mailetcontainer.lib.ProcessorDetail;
+import org.apache.james.mailetcontainer.lib.jmx.JMXMailProcessorListListener;
+import org.apache.james.mailetcontainer.lib.jmx.JMXMailetContainerListener;
 import org.apache.james.mailetcontainer.lib.matchers.CompositeMatcher;
 import org.apache.mailet.Mail;
 import org.apache.mailet.Mailet;
@@ -82,13 +87,13 @@ public class CamelMailProcessorList impl
     private MailetLoader mailetLoader;
     private Log logger;
 
-    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,List<Mailet>> mailets = new HashMap<String,List<Mailet>>();
+    private final Map<String,List<Matcher>> matchers = new HashMap<String,List<Matcher>>();
     
     private final Map<String,MailProcessor> processors = new HashMap<String,MailProcessor>();
     private final UseLatestAggregationStrategy aggr = new UseLatestAggregationStrategy();
     private MailetContext mailetContext;
-       
+    
     @Resource(name = "matcherloader")
     public void setMatcherLoader(MatcherLoader matcherLoader) {
         this.matcherLoader = matcherLoader;
@@ -105,13 +110,44 @@ public class CamelMailProcessorList impl
     }
 
     private ProducerTemplate producerTemplate;
-	private CamelContext camelContext;
+    private CamelContext camelContext;
+    
+    private List<MailProcessorListListener> listeners = Collections.synchronizedList(new ArrayList<MailProcessorListListener>());
+    private JMXMailProcessorListListener jmxListener;
+    private boolean enableJmx;
+    
+    /*
+     * (non-Javadoc)
+     * @see org.apache.james.mailetcontainer.api.MailProcessorList#addListener(org.apache.james.mailetcontainer.api.MailProcessorListListener)
+     */
+    public void addListener(MailProcessorListListener listener) {
+        listeners.add(listener);
+    }
+    
+    /*
+     * (non-Javadoc)
+     * @see org.apache.james.mailetcontainer.api.MailProcessorList#getListeners()
+     */
+    public List<MailProcessorListListener> getListeners() {
+        return listeners;
+    }
+    
+    /*
+     * (non-Javadoc)
+     * @see org.apache.james.mailetcontainer.api.MailProcessorList#removeListener(org.apache.james.mailetcontainer.api.MailProcessorListListener)
+     */
+    public void removeListener(MailProcessorListListener listener) {
+        listeners.remove(listener);
+    }
     
-
-
 	@PostConstruct
     public void init() throws Exception {
         getCamelContext().addRoutes(new SpoolRouteBuilder());
+        
+        if (enableJmx) {
+            this.jmxListener = new JMXMailProcessorListListener(this);
+            addListener(jmxListener);
+        }
         producerTemplate = getCamelContext().createProducerTemplate();
         
         // Make sure the camel context get started
@@ -119,6 +155,8 @@ public class CamelMailProcessorList impl
         if (getCamelContext().getStatus().isStopped()) {
             getCamelContext().start();
         }
+        
+        
 
     }
 
@@ -129,11 +167,11 @@ public class CamelMailProcessorList impl
     public void dispose() {
         boolean debugEnabled = logger.isDebugEnabled();
 
-        Iterator<List<MailetManagement>> it = mailets.values().iterator();
+        Iterator<List<Mailet>> it = mailets.values().iterator();
         while (it.hasNext()) {
-            List<MailetManagement> mList = it.next();
+            List<Mailet> mList = it.next();
             for (int i = 0; i < mList.size(); i++) {
-                Mailet m = mList.get(i).getMailet();
+                Mailet m = mList.get(i);
                 if (debugEnabled) {
                     logger.debug("Shutdown mailet " + m.getMailetInfo());
                 }
@@ -142,9 +180,9 @@ public class CamelMailProcessorList impl
            
         }
         
-        Iterator<List<MatcherManagement>> mit = matchers.values().iterator();     
+        Iterator<List<Matcher>> mit = matchers.values().iterator();     
         while (mit.hasNext()) {
-            List<MatcherManagement> mList = mit.next();
+            List<Matcher> mList = mit.next();
             for (int i = 0; i < mList.size(); i++) {
                 Matcher m = mList.get(i);
                 if (debugEnabled) {
@@ -153,7 +191,10 @@ public class CamelMailProcessorList impl
                 m.destroy();
             }
            
-        }      
+        }
+        if (jmxListener != null) {
+            jmxListener.dispose();
+        }
     }
     
     /*
@@ -162,6 +203,7 @@ public class CamelMailProcessorList impl
      */
     public void configure(HierarchicalConfiguration config) throws ConfigurationException {
         this.config = config;
+        this.enableJmx = config.getBoolean("enableJmx", true);;
     }
 
     /*
@@ -241,14 +283,30 @@ public class CamelMailProcessorList impl
         return "direct:processor." + processorName;
     }
     
+
     /*
      * (non-Javadoc)
-     * @see org.apache.james.transport.MailProcessor#service(org.apache.mailet.Mail)
+     * @see org.apache.james.mailetcontainer.api.MailProcessor#service(org.apache.mailet.Mail)
      */
     public void service(Mail mail) throws MessagingException {
+        long start = System.currentTimeMillis();
+        MessagingException ex = null;
         MailProcessor processor = getProcessor(mail.getState());
+     
         if (processor != null) {
-            processor.service(mail);
+            try {
+                processor.service(mail);
+            } catch (MessagingException e) {
+                ex = e;
+                throw e;
+            } finally {
+                long end = System.currentTimeMillis() - start;
+                for (int i = 0; i < listeners.size(); i++) {
+                    MailProcessorListListener listener = listeners.get(i);
+                    
+                    listener.afterProcessor(processor, mail.getName(), end, ex);
+                } 
+            }
         } else {
             throw new MessagingException("No processor found for mail " + mail.getName() + " with state " + mail.getState());
         }
@@ -285,20 +343,21 @@ public class CamelMailProcessorList impl
     }
     
     
-    private final class ChildProcessor implements MailetContainer {
+    private final class ChildProcessor implements MailetContainer, Disposable {
        
         
         private String processorName;
-
-        public ChildProcessor(String processorName) {
+        private List<MailetContainerListener> listeners = Collections.synchronizedList(new ArrayList<MailetContainerListener>());
+        private JMXMailetContainerListener jmxListener;
+        
+        public ChildProcessor(String processorName){
             this.processorName = processorName;
         }
         
 
- 
         /*
          * (non-Javadoc)
-         * @see org.apache.james.mailetcontainer.MailProcessor#service(org.apache.mailet.Mail)
+         * @see org.apache.james.mailetcontainer.api.MailProcessor#service(org.apache.mailet.Mail)
          */
         public void service(Mail mail) throws MessagingException {
             try {
@@ -308,28 +367,79 @@ public class CamelMailProcessorList impl
                  throw new MessagingException("Unable to process mail " + mail.getName(),ex);
              }        
          }
-        
+
         /*
          * (non-Javadoc)
-         * @see org.apache.james.transport.MailetContainer#getMailets()
+         * @see org.apache.james.mailetcontainer.api.MailetContainer#getMailets()
          */
         public List<Mailet> getMailets() {
-            return new ArrayList<Mailet>(mailets.get(processorName));
+            return Collections.unmodifiableList(mailets.get(processorName));
         }
 
         /*
          * (non-Javadoc)
-         * @see org.apache.james.transport.MailetContainer#getMatchers()
+         * @see org.apache.james.mailetcontainer.api.MailetContainer#getMatchers()
          */
         public List<Matcher> getMatchers() {
-            return new ArrayList<Matcher>(matchers.get(processorName));       
+            return Collections.unmodifiableList(matchers.get(processorName));       
+        }
+
+
+        /*
+         * (non-Javadoc)
+         * @see org.apache.james.mailetcontainer.api.MailetContainer#addListener(org.apache.james.mailetcontainer.api.MailetContainerListener)
+         */
+        public void addListener(MailetContainerListener listener) {
+            listeners.add(listener);
+        }
+
+        /*
+         * (non-Javadoc)
+         * @see org.apache.james.mailetcontainer.api.MailetContainer#removeListener(org.apache.james.mailetcontainer.api.MailetContainerListener)
+         */
+        public void removeListener(MailetContainerListener listener) {
+            listeners.remove(listener);            
+        }
+
+
+        /*
+         * (non-Javadoc)
+         * @see org.apache.james.mailetcontainer.api.MailetContainer#getListeners()
+         */
+        public List<MailetContainerListener> getListeners() {
+            return listeners;
+        }
+
+
+        /*
+         * (non-Javadoc)
+         * @see org.apache.james.lifecycle.api.Disposable#dispose()
+         */
+        public void dispose() {
+            listeners.clear();
+            if (jmxListener!= null) {
+                jmxListener.dispose();
+            }
+        }
+        
+        public void registerJMX() throws MalformedObjectNameException, JMException {
+            this.jmxListener = new JMXMailetContainerListener(processorName, ChildProcessor.this);
+            addListener(jmxListener);
         }
     }
 
+    /*
+     * (non-Javadoc)
+     * @see org.apache.camel.CamelContextAware#getCamelContext()
+     */
 	public CamelContext getCamelContext() {
         return camelContext;
     }
 
+	/*
+	 * (non-Javadoc)
+	 * @see org.apache.camel.CamelContextAware#setCamelContext(org.apache.camel.CamelContext)
+	 */
     public void setCamelContext(CamelContext camelContext) {
         this.camelContext = camelContext;
     }
@@ -343,7 +453,6 @@ public class CamelMailProcessorList impl
         @SuppressWarnings("unchecked")
         @Override
         public void configure() throws Exception {
-            Processor terminatingMailetProcessor = new MailetProcessor(new TerminatingMailet(), logger);
             Processor disposeProcessor = new DisposeProcessor();
             Processor mailProcessor = new MailCamelProcessor();
             Processor removePropsProcessor = new RemovePropertiesProcessor();
@@ -353,17 +462,20 @@ public class CamelMailProcessorList impl
                 final HierarchicalConfiguration processorConf = processorConfs.get(i);
                 String processorName = processorConf.getString("[@name]");
                 
+                ChildProcessor container = new ChildProcessor(processorName);
+                
+                
                 if (processorName.equals(Mail.GHOST)) throw new ConfigurationException("ProcessorName of " + Mail.GHOST + " is reserved for internal use, choose a different name");
                 
-                mailets.put(processorName, new ArrayList<MailetManagement>());
-                matchers.put(processorName, new ArrayList<MatcherManagement>());
+                mailets.put(processorName, new ArrayList<Mailet>());
+                matchers.put(processorName, new ArrayList<Matcher>());
 
                 RouteDefinition processorDef = from(getEndpoint(processorName)).routeId(processorName).inOnly()
                 // store the logger in properties
-                .setProperty(MatcherSplitter.LOGGER_PROPERTY, constant(logger));   
+                .setProperty(MatcherSplitter.LOGGER_PROPERTY, constant(logger));
 
                 // load composite matchers if there are any
-                Map<String,MatcherManagement> compositeMatchers = new HashMap<String, MatcherManagement>();
+                Map<String,Matcher> compositeMatchers = new HashMap<String, Matcher>();
                 loadCompositeMatchers(processorName, compositeMatchers, processorConf.configurationsAt("matcher"));
                 
                 
@@ -447,32 +559,18 @@ public class CamelMailProcessorList impl
                         throw new ConfigurationException("Unable to init mailet", ex);
                     }
                     if (mailet != null && matcher != null) {
-                        MailetManagement wrappedMailet;
-                        if (mailet instanceof MailetManagement) {
-                            wrappedMailet = (MailetManagement) mailet;
-                        } else {
-                            wrappedMailet  = new MailetManagement(mailet);
-                        }
-                        
-                        MatcherManagement wrappedMatcher;
-                        if (matcher instanceof MatcherManagement) {
-                            wrappedMatcher = (MatcherManagement) matcher;
-                        } else {
-                            wrappedMatcher = new MatcherManagement(matcher);
-                        }
-                        
-                        
+
                         String onMatchException = null;
-                        MailetConfig mailetConfig = wrappedMailet.getMailetConfig();
+                        MailetConfig mailetConfig = mailet.getMailetConfig();
                     
                         if (mailetConfig instanceof MailetConfigImpl) {
                             onMatchException = ((MailetConfigImpl) mailetConfig).getInitAttribute("onMatchException");
                         }
                     
-                        MailetProcessor mailetProccessor = new MailetProcessor(wrappedMailet, logger);
+                        MailetProcessor mailetProccessor = new MailetProcessor(mailet, logger, container);
                         // Store the matcher to use for splitter in properties
                         processorDef
-                            .setProperty(MatcherSplitter.MATCHER_PROPERTY, constant(wrappedMatcher)).setProperty(MatcherSplitter.ON_MATCH_EXCEPTION_PROPERTY, constant(onMatchException))
+                            .setProperty(MatcherSplitter.MATCHER_PROPERTY, constant(matcher)).setProperty(MatcherSplitter.ON_MATCH_EXCEPTION_PROPERTY, constant(onMatchException)).setProperty(MatcherSplitter.MAILETCONTAINER_PROPERTY, constant(container))
                             
                             // do splitting of the mail based on the stored matcher
                             .split().method(MatcherSplitter.class).aggregationStrategy(aggr).parallelProcessing()
@@ -484,13 +582,16 @@ public class CamelMailProcessorList impl
                             .choice().when(new MailStateNotEquals(processorName)).process(mailProcessor).stop().end();
 
                         // store mailet and matcher
-                        mailets.get(processorName).add(wrappedMailet);
-                        matchers.get(processorName).add(wrappedMatcher);
+                        mailets.get(processorName).add(mailet);
+                        matchers.get(processorName).add(matcher);
                     }
               
 
                 }
                 
+                Processor terminatingMailetProcessor = new MailetProcessor(new TerminatingMailet(), logger, container);
+
+                
                 processorDef
                     // start choice
                     .choice()
@@ -505,8 +606,13 @@ public class CamelMailProcessorList impl
                     
                      // route it to the next processor
                     .otherwise().process(mailProcessor).stop();
-                  
-                processors.put(processorName, new ProcessorDetail(processorName,new ChildProcessor(processorName)));
+                
+               
+                
+                processors.put(processorName, container);
+                if (enableJmx) {
+                    container.registerJMX();
+                }
             }
             
             // check if all needed processors are configured
@@ -583,8 +689,8 @@ public class CamelMailProcessorList impl
      * @throws NotCompliantMBeanException
      */
     @SuppressWarnings("unchecked")
-    private List<MatcherManagement> loadCompositeMatchers(String processorName, Map<String,MatcherManagement> compMap, List<HierarchicalConfiguration> compMatcherConfs) throws ConfigurationException, MessagingException, NotCompliantMBeanException {
-        List<MatcherManagement> matchers = new ArrayList<MatcherManagement>();
+    private List<Matcher> loadCompositeMatchers(String processorName, Map<String,Matcher> compMap, List<HierarchicalConfiguration> compMatcherConfs) throws ConfigurationException, MessagingException, NotCompliantMBeanException {
+        List<Matcher> matchers = new ArrayList<Matcher>();
 
         for (int j= 0 ; j < compMatcherConfs.size(); j++) {
             HierarchicalConfiguration c = compMatcherConfs.get(j);
@@ -601,7 +707,7 @@ public class CamelMailProcessorList impl
                 if (matcher instanceof CompositeMatcher) {
                     CompositeMatcher compMatcher = (CompositeMatcher) matcher;
                     
-                    List<MatcherManagement> childMatcher = loadCompositeMatchers(processorName, compMap,c.configurationsAt("matcher"));
+                    List<Matcher> childMatcher = loadCompositeMatchers(processorName, compMap,c.configurationsAt("matcher"));
                     for (int i = 0 ; i < childMatcher.size(); i++) {
                         compMatcher.add(childMatcher.get(i));
                     }
@@ -611,7 +717,7 @@ public class CamelMailProcessorList impl
                 if (m instanceof CompositeMatcher) {
                     CompositeMatcher compMatcher = (CompositeMatcher) m;
                     
-                    List<MatcherManagement> childMatcher = loadCompositeMatchers(processorName, compMap,c.configurationsAt("matcher"));
+                    List<Matcher> childMatcher = loadCompositeMatchers(processorName, compMap,c.configurationsAt("matcher"));
                     for (int i = 0 ; i < childMatcher.size(); i++) {
                         compMatcher.add(childMatcher.get(i));
                     }
@@ -619,12 +725,11 @@ public class CamelMailProcessorList impl
                 matcher = new MatcherInverter(m);
             }
             if (matcher == null) throw new ConfigurationException("Unable to load matcher instance");
-            MatcherManagement mgmtMatcher = new MatcherManagement(matcher);
-            matchers.add(mgmtMatcher);
+            matchers.add(matcher);
             if (compName != null) {
                 // check if there is already a composite Matcher with the name registered in the processor
                 if (compMap.containsKey(compName)) throw new ConfigurationException("CompositeMatcher with name " + compName + " is already defined in processor " + processorName);
-                compMap.put(compName, mgmtMatcher);
+                compMap.put(compName, matcher);
             }
         }
         return matchers;

Modified: james/server/trunk/mailetcontainer-camel/src/main/java/org/apache/james/mailetcontainer/camel/MailetProcessor.java
URL: http://svn.apache.org/viewvc/james/server/trunk/mailetcontainer-camel/src/main/java/org/apache/james/mailetcontainer/camel/MailetProcessor.java?rev=1051470&r1=1051469&r2=1051470&view=diff
==============================================================================
--- james/server/trunk/mailetcontainer-camel/src/main/java/org/apache/james/mailetcontainer/camel/MailetProcessor.java (original)
+++ james/server/trunk/mailetcontainer-camel/src/main/java/org/apache/james/mailetcontainer/camel/MailetProcessor.java Tue Dec 21 12:05:57 2010
@@ -18,6 +18,7 @@
  ****************************************************************/
 package org.apache.james.mailetcontainer.camel;
 
+import java.util.List;
 import java.util.Locale;
 
 import javax.mail.MessagingException;
@@ -25,6 +26,8 @@ import javax.mail.MessagingException;
 import org.apache.camel.Exchange;
 import org.apache.camel.Processor;
 import org.apache.commons.logging.Log;
+import org.apache.james.mailetcontainer.api.MailetContainer;
+import org.apache.james.mailetcontainer.api.MailetContainerListener;
 import org.apache.james.mailetcontainer.lib.MailetConfigImpl;
 import org.apache.james.mailetcontainer.lib.ProcessorUtil;
 import org.apache.mailet.Mail;
@@ -39,15 +42,17 @@ public class MailetProcessor implements 
 
     private Mailet mailet;
     private Log logger;
-   
+    private MailetContainer container;
+    
     /**
      * Mailet to call on process
      * 
      * @param mailet
      */
-    public MailetProcessor(Mailet mailet, Log logger) {
+    public MailetProcessor(Mailet mailet, Log logger, MailetContainer container) {
         this.mailet = mailet;
         this.logger = logger;
+        this.container = container;
     }
     
     /**
@@ -56,11 +61,14 @@ public class MailetProcessor implements 
     @SuppressWarnings("unchecked")
     public void process(Exchange exchange) throws Exception {
         Mail mail = exchange.getIn().getBody(Mail.class);
+        long start = System.currentTimeMillis();
+        MessagingException ex = null;
         try {
-            mailet.service(mail);
+            mailet.service(mail);       
         } catch (MessagingException me) {
+            ex = me;
             String onMailetException = null;
-            
+
             MailetConfig mailetConfig = mailet.getMailetConfig();
             if (mailetConfig instanceof MailetConfigImpl) {
                 onMailetException = ((MailetConfigImpl) mailetConfig).getInitAttribute("onMailetException");
@@ -78,6 +86,14 @@ public class MailetProcessor implements 
             } else {
                 ProcessorUtil.handleException(me, mail, mailet.getMailetConfig().getMailetName(), onMailetException, logger);
             }
+
+        } finally {
+            List<MailetContainerListener> listeners = container.getListeners();
+            long complete = System.currentTimeMillis() - start;
+            for (int i = 0; i < listeners.size(); i++) {
+                MailetContainerListener listener = listeners.get(i);
+                listener.afterMailet(mailet, mail.getName(), mail.getState(), complete, ex);
+            }
         }
     }
 

Modified: james/server/trunk/mailetcontainer-camel/src/main/java/org/apache/james/mailetcontainer/camel/MatcherSplitter.java
URL: http://svn.apache.org/viewvc/james/server/trunk/mailetcontainer-camel/src/main/java/org/apache/james/mailetcontainer/camel/MatcherSplitter.java?rev=1051470&r1=1051469&r2=1051470&view=diff
==============================================================================
--- james/server/trunk/mailetcontainer-camel/src/main/java/org/apache/james/mailetcontainer/camel/MatcherSplitter.java (original)
+++ james/server/trunk/mailetcontainer-camel/src/main/java/org/apache/james/mailetcontainer/camel/MatcherSplitter.java Tue Dec 21 12:05:57 2010
@@ -33,6 +33,8 @@ import org.apache.camel.InOnly;
 import org.apache.camel.Property;
 import org.apache.commons.logging.Log;
 import org.apache.james.core.MailImpl;
+import org.apache.james.mailetcontainer.api.MailetContainer;
+import org.apache.james.mailetcontainer.api.MailetContainerListener;
 import org.apache.james.mailetcontainer.lib.ProcessorUtil;
 import org.apache.mailet.Mail;
 import org.apache.mailet.MailAddress;
@@ -60,6 +62,9 @@ public class MatcherSplitter {
     public final static String ON_MATCH_EXCEPTION_PROPERTY = "onMatchException";
     
     public final static String LOGGER_PROPERTY = "logger";
+    
+    public final static String MAILETCONTAINER_PROPERTY = "container";
+
 
     
     /**
@@ -73,78 +78,101 @@ public class MatcherSplitter {
      */
     @SuppressWarnings("unchecked")
     @Handler
-    public List<Mail> split(@Property(MATCHER_PROPERTY) Matcher matcher, @Property(ON_MATCH_EXCEPTION_PROPERTY) String onMatchException, @Property(LOGGER_PROPERTY) Log logger, @Body Mail mail) throws MessagingException {
-        List<Mail> mails = new ArrayList<Mail>();
-        boolean fullMatch = false;
-        
-        // call the matcher
+    public List<Mail> split(@Property(MATCHER_PROPERTY) Matcher matcher, @Property(ON_MATCH_EXCEPTION_PROPERTY) String onMatchException, @Property(LOGGER_PROPERTY) Log logger, @Property(MAILETCONTAINER_PROPERTY) MailetContainer container,
+            @Body Mail mail) throws MessagingException {
         Collection<MailAddress> matchedRcpts = null;
+        Collection<MailAddress> origRcpts = new ArrayList<MailAddress>(mail.getRecipients());
+        long start = System.currentTimeMillis();
+        MessagingException ex = null;
         
         try {
-            matchedRcpts = matcher.match(mail);
-            if (matchedRcpts == null) {
-                //In case the matcher returned null, create an empty Collection
-                matchedRcpts = new ArrayList<MailAddress>(0);
-            } else if (matchedRcpts != mail.getRecipients()) {
-                //Make sure all the objects are MailAddress objects
-                ProcessorUtil.verifyMailAddresses(matchedRcpts);
-            }
-        } catch (MessagingException me) {
-        
-            if (onMatchException == null) {
-                onMatchException = Mail.ERROR;
-            } else {
-                onMatchException = onMatchException.trim().toLowerCase(Locale.US);
+            List<Mail> mails = new ArrayList<Mail>();
+            boolean fullMatch = false;
+
+            try {
+                // call the matcher
+                matchedRcpts = matcher.match(mail);
+
+                if (matchedRcpts == null) {
+                    // In case the matcher returned null, create an empty
+                    // Collection
+                    matchedRcpts = new ArrayList<MailAddress>(0);
+                } else if (matchedRcpts != mail.getRecipients()) {
+                    // Make sure all the objects are MailAddress objects
+                    ProcessorUtil.verifyMailAddresses(matchedRcpts);
+                }
+
+            } catch (MessagingException me) {
+                ex = me;
+                if (onMatchException == null) {
+                    onMatchException = Mail.ERROR;
+                } else {
+                    onMatchException = onMatchException.trim().toLowerCase(Locale.US);
+                }
+                if (onMatchException.compareTo("nomatch") == 0) {
+                    // In case the matcher returned null, create an empty
+                    // Collection
+                    matchedRcpts = new ArrayList<MailAddress>(0);
+                } else if (onMatchException.compareTo("matchall") == 0) {
+                    matchedRcpts = mail.getRecipients();
+                    // no need to verify addresses
+                } else {
+                    ProcessorUtil.handleException(me, mail, matcher.getMatcherConfig().getMatcherName(), onMatchException, logger);
+                }
             }
-            if (onMatchException.compareTo("nomatch") == 0) {
-                //In case the matcher returned null, create an empty Collection
-                matchedRcpts = new ArrayList<MailAddress>(0);
-            } else if (onMatchException.compareTo("matchall") == 0) {
-                matchedRcpts = mail.getRecipients();
-                // no need to verify addresses
-            } else {
-                ProcessorUtil.handleException(me, mail, matcher.getMatcherConfig().getMatcherName(), onMatchException, logger);
+
+            // check if the matcher matched
+            if (matchedRcpts != null && matchedRcpts.isEmpty() == false) {
+                List<MailAddress> rcpts = new ArrayList<MailAddress>(mail.getRecipients());
+
+                Iterator<MailAddress> rcptsIterator = matchedRcpts.iterator();
+
+                while (rcptsIterator.hasNext()) {
+                    // loop through the recipients and remove the recipients
+                    // that matched
+                    rcpts.remove(rcptsIterator.next());
+                }
+
+                if (rcpts.isEmpty()) {
+                    // all recipients matched
+                    fullMatch = true;
+                } else {
+                    mail.setRecipients(rcpts);
+
+                    Mail newMail = new MailImpl(mail);
+                    newMail.setRecipients(matchedRcpts);
+
+                    // Set a header because the matcher matched. This can be
+                    // used later when processing the route
+                    newMail.setAttribute(MATCHER_MATCHED_ATTRIBUTE, true);
+
+                    // add the new generated mail to the mails list
+                    mails.add(newMail);
+                }
             }
-        }
-        
-        // check if the matcher matched
-        if ( matchedRcpts != null && matchedRcpts.isEmpty() == false) {
-            List<MailAddress> rcpts = new ArrayList<MailAddress>(mail.getRecipients());
-            
-            Iterator<MailAddress> rcptsIterator = matchedRcpts.iterator();
-            
-            while(rcptsIterator.hasNext()) {
-                // loop through the recipients and remove the recipients that matched
-                rcpts.remove(rcptsIterator.next());
+
+            if (fullMatch) {
+                // Set a header because the matcher matched. This can be used
+                // later when processing the route
+                mail.setAttribute(MATCHER_MATCHED_ATTRIBUTE, true);
             }
-            
-            if (rcpts.isEmpty()) {
-                // all recipients matched
-                fullMatch = true;
-            } else {
-                mail.setRecipients(rcpts);
-                
-                Mail newMail = new MailImpl(mail);
-                newMail.setRecipients(matchedRcpts);
-                
-              
-                // Set a header because the matcher matched. This can be used later when processing the route
-                newMail.setAttribute(MATCHER_MATCHED_ATTRIBUTE, true);
-                
-                // add the new generated mail to the mails list
-                mails.add(newMail);
+
+            // add mailMsg to the mails list
+            mails.add(mail);
+
+            return mails;
+        } finally {
+
+            long complete = System.currentTimeMillis() - start;
+            List<MailetContainerListener> listeners = container.getListeners();
+            for (int i = 0; i < listeners.size(); i++) {
+                MailetContainerListener listener = listeners.get(i);
+                if (matchedRcpts.isEmpty()) {
+                    listener.afterMatcher(matcher, mail.getName(), origRcpts, null,  complete, ex);
+                } else {
+                    listener.afterMatcher(matcher, mail.getName(), origRcpts, matchedRcpts, complete, ex);
+                }
             }
         }
-            
-        if (fullMatch) {
-            // Set a header because the matcher matched. This can be used later when processing the route
-            mail.setAttribute(MATCHER_MATCHED_ATTRIBUTE, true);
-        }
-        
-        // add mailMsg to the mails list
-        mails.add(mail);
-        
-        return mails;
     }
-
 }

Modified: james/server/trunk/mailetcontainer-library/src/main/java/org/apache/james/mailetcontainer/lib/JamesMailSpooler.java
URL: http://svn.apache.org/viewvc/james/server/trunk/mailetcontainer-library/src/main/java/org/apache/james/mailetcontainer/lib/JamesMailSpooler.java?rev=1051470&r1=1051469&r2=1051470&view=diff
==============================================================================
--- james/server/trunk/mailetcontainer-library/src/main/java/org/apache/james/mailetcontainer/lib/JamesMailSpooler.java (original)
+++ james/server/trunk/mailetcontainer-library/src/main/java/org/apache/james/mailetcontainer/lib/JamesMailSpooler.java Tue Dec 21 12:05:57 2010
@@ -40,8 +40,8 @@ import org.apache.james.lifecycle.api.Lo
 import org.apache.james.mailetcontainer.api.MailProcessor;
 import org.apache.james.mailetcontainer.api.MailProcessorList;
 import org.apache.james.mailetcontainer.api.MailSpooler;
-import org.apache.james.mailetcontainer.api.MailSpoolerMBean;
 import org.apache.james.mailetcontainer.api.MailetContainer;
+import org.apache.james.mailetcontainer.api.jmx.MailSpoolerMBean;
 import org.apache.james.queue.api.MailQueue;
 import org.apache.james.queue.api.MailQueueFactory;
 import org.apache.james.queue.api.MailQueue.MailQueueItem;

Added: james/server/trunk/mailetcontainer-library/src/main/java/org/apache/james/mailetcontainer/lib/jmx/JMXMailProcessorListListener.java
URL: http://svn.apache.org/viewvc/james/server/trunk/mailetcontainer-library/src/main/java/org/apache/james/mailetcontainer/lib/jmx/JMXMailProcessorListListener.java?rev=1051470&view=auto
==============================================================================
--- james/server/trunk/mailetcontainer-library/src/main/java/org/apache/james/mailetcontainer/lib/jmx/JMXMailProcessorListListener.java (added)
+++ james/server/trunk/mailetcontainer-library/src/main/java/org/apache/james/mailetcontainer/lib/jmx/JMXMailProcessorListListener.java Tue Dec 21 12:05:57 2010
@@ -0,0 +1,139 @@
+/****************************************************************
+ * 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.lib.jmx;
+
+import java.lang.management.ManagementFactory;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import javax.mail.MessagingException;
+import javax.management.JMException;
+import javax.management.MBeanServer;
+import javax.management.MalformedObjectNameException;
+import javax.management.ObjectName;
+
+import org.apache.james.lifecycle.api.Disposable;
+import org.apache.james.mailetcontainer.api.MailProcessor;
+import org.apache.james.mailetcontainer.api.MailProcessorList;
+import org.apache.james.mailetcontainer.api.MailProcessorListListener;
+
+/**
+ * {@link MailProcessorListListener} implementation which register MBeans for its child {@link MailProcessor} 
+ * and keep track of the stats
+ *
+ */
+public class JMXMailProcessorListListener implements MailProcessorListListener, Disposable{
+
+    private MailProcessorList mList;
+    private MBeanServer mbeanserver;
+    private List<ObjectName> mbeans = new ArrayList<ObjectName>();
+    private Map<MailProcessor, MailProcessorManagement> mMap = new HashMap<MailProcessor, MailProcessorManagement>();
+    public JMXMailProcessorListListener(MailProcessorList mList) throws MalformedObjectNameException, JMException {
+        this.mList = mList;
+        
+        mbeanserver = ManagementFactory.getPlatformMBeanServer();
+        registerMBeans();
+    }
+    
+    
+    /**
+     * Unregister all JMX MBeans
+     */
+    private void unregisterMBeans() {
+        List<ObjectName> unregistered = new ArrayList<ObjectName>();
+        for (int i = 0; i < mbeans.size(); i++) {
+            ObjectName name = mbeans.get(i);
+            
+            try {
+                mbeanserver.unregisterMBean(name);
+                unregistered.add(name);
+            } catch (javax.management.JMException e) {
+                //logger.error("Unable to unregister mbean " + name, e);
+            }
+        }
+        mbeans.removeAll(unregistered);
+    }
+
+
+    /**
+     * Register all JMX MBeans
+     * @throws JMException 
+     * @throws MalformedObjectNameException 
+     */
+    private void registerMBeans() throws MalformedObjectNameException, JMException {
+       
+        String baseObjectName = "org.apache.james:type=component,name=processor,";
+
+        String[] processorNames = mList.getProcessorNames();
+        for (int i = 0; i < processorNames.length; i++) {
+            String processorName = processorNames[i];
+            registerProcessorMBean(baseObjectName, processorName);
+        }
+    }
+    
+    /**
+     * Register a JMX MBean for a {@link MailProcessor}
+     * 
+     * @param baseObjectName
+     * @param processorName
+     * @throws JMException 
+     * @throws MalformedObjectNameException 
+     */
+    private void registerProcessorMBean(String baseObjectName, String processorName) throws MalformedObjectNameException, JMException {
+        String processorMBeanName = baseObjectName + "processor=" + processorName;
+        
+        MailProcessorManagement processorDetail = new MailProcessorManagement(processorName);
+        registerMBean(processorMBeanName, processorDetail);
+        mMap.put(mList.getProcessor(processorName), processorDetail);
+
+    }
+    
+
+    private void registerMBean(String mBeanName, Object object) throws MalformedObjectNameException, JMException{
+         ObjectName objectName = new ObjectName(mBeanName);
+       
+        mbeanserver.registerMBean(object, objectName);
+        mbeans.add(objectName);
+       
+    }
+
+    /*
+     * (non-Javadoc)
+     * @see org.apache.james.mailetcontainer.api.MailProcessorListListener#afterProcessor(org.apache.james.mailetcontainer.api.MailProcessor, java.lang.String, long, javax.mail.MessagingException)
+     */
+    public void afterProcessor(MailProcessor processor, String mailName, long processTime, MessagingException e) {
+        MailProcessorManagement m = mMap.get(processor);
+        if (m != null) {
+            m.update(processTime, e == null);
+        }
+    }
+
+
+    /*
+     * (non-Javadoc)
+     * @see org.apache.james.lifecycle.api.Disposable#dispose()
+     */
+    public void dispose() {
+        unregisterMBeans();      
+        mMap.clear();
+    }
+
+}

Added: james/server/trunk/mailetcontainer-library/src/main/java/org/apache/james/mailetcontainer/lib/jmx/JMXMailetContainerListener.java
URL: http://svn.apache.org/viewvc/james/server/trunk/mailetcontainer-library/src/main/java/org/apache/james/mailetcontainer/lib/jmx/JMXMailetContainerListener.java?rev=1051470&view=auto
==============================================================================
--- james/server/trunk/mailetcontainer-library/src/main/java/org/apache/james/mailetcontainer/lib/jmx/JMXMailetContainerListener.java (added)
+++ james/server/trunk/mailetcontainer-library/src/main/java/org/apache/james/mailetcontainer/lib/jmx/JMXMailetContainerListener.java Tue Dec 21 12:05:57 2010
@@ -0,0 +1,204 @@
+/****************************************************************
+ * 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.lib.jmx;
+
+import java.lang.management.ManagementFactory;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+
+import javax.mail.MessagingException;
+import javax.management.JMException;
+import javax.management.MBeanServer;
+import javax.management.MalformedObjectNameException;
+import javax.management.ObjectName;
+
+import org.apache.james.lifecycle.api.Disposable;
+import org.apache.james.mailetcontainer.api.MailetContainer;
+import org.apache.james.mailetcontainer.api.MailetContainerListener;
+import org.apache.james.mailetcontainer.lib.matchers.CompositeMatcher;
+import org.apache.mailet.MailAddress;
+import org.apache.mailet.Mailet;
+import org.apache.mailet.Matcher;
+
+/**
+ * {@link MailetContainerListener} implementation which register MBean's for all the contained
+ * {@link Mailet} and {@link Matcher} and keep track of the stats
+ * 
+ *
+ */
+public class JMXMailetContainerListener implements MailetContainerListener, Disposable{
+
+    private MailetContainer container;
+    private MBeanServer mbeanserver;
+    private List<ObjectName> mbeans = new ArrayList<ObjectName>();
+    private Map<Mailet, MailetManagement> mailetMap = new HashMap<Mailet, MailetManagement>();
+    private Map<Matcher, MatcherManagement> matcherMap = new HashMap<Matcher, MatcherManagement>();
+
+    private String name;
+
+    public JMXMailetContainerListener(String name, MailetContainer container) throws MalformedObjectNameException, JMException {
+        this.container = container;
+        this.name = name;
+        
+        mbeanserver = ManagementFactory.getPlatformMBeanServer();
+        registerMBeans();
+    }
+    
+
+    /*
+     * (non-Javadoc)
+     * @see org.apache.james.mailetcontainer.api.MailetContainerListener#afterMailet(org.apache.mailet.Mailet, java.lang.String, java.lang.String, long, javax.mail.MessagingException)
+     */
+    public void afterMailet(Mailet m, String mailName, String state, long processTime, MessagingException e) {
+        MailetManagement mgmt = mailetMap.get(m);
+        if (mgmt != null) {
+            mgmt.update(processTime, e == null);
+        }
+    }
+
+
+    /*
+     * (non-Javadoc)
+     * @see org.apache.james.mailetcontainer.api.MailetContainerListener#afterMatcher(org.apache.mailet.Matcher, java.lang.String, java.util.Collection, java.util.Collection, long, javax.mail.MessagingException)
+     */
+    public void afterMatcher(Matcher m,  String mailName, Collection<MailAddress> rcpts,Collection<MailAddress> matches, long processTime, MessagingException e) {
+        MatcherManagement mgmt = matcherMap.get(m);
+        
+        if (mgmt != null) {
+            boolean matched = false;
+            if (matches != null) {
+                matched = !matches.isEmpty();
+            }
+            mgmt.update(processTime, e == null, matched);
+        }
+    }
+    
+
+    /**
+     * Register all JMX MBeans
+     * @throws JMException 
+     * @throws MalformedObjectNameException 
+     */
+    private void registerMBeans() throws MalformedObjectNameException, JMException {
+        String baseObjectName = "org.apache.james:type=component,name=processor,processor=" + name;
+        
+        registerMailets(baseObjectName, container.getMailets().iterator());
+        registerMatchers(baseObjectName, container.getMatchers().iterator(), 0);
+    }
+
+   
+    
+    /**
+     * Register the Mailets as JMX MBeans
+     * 
+     * @param parentMBeanName
+     * @param mailets
+     * @throws JMException 
+     * @throws MalformedObjectNameException 
+     */
+    private void registerMailets(String parentMBeanName, Iterator<Mailet> mailets) throws MalformedObjectNameException, JMException {
+        int i = 0;
+        while(mailets.hasNext()) {
+            Mailet mailet = mailets.next();
+            MailetManagement mailetManagement = new MailetManagement(mailet.getMailetConfig());
+
+            String mailetMBeanName = parentMBeanName + ",subtype=mailet,index=" + (i++) + ",mailetname=" + mailetManagement.getMailetName();
+            registerMBean(mailetMBeanName, mailetManagement);
+            mailetMap.put(mailet, mailetManagement);
+        }
+        
+    }
+    
+
+    /**
+     * Register the {@link Matcher}'s as JMX MBeans
+     * 
+     * @param parentMBeanName
+     * @param matchers
+     * @param nestingLevel
+     * @throws JMException 
+     * @throws MalformedObjectNameException 
+     */
+    @SuppressWarnings("unchecked")
+    private void registerMatchers(String parentMBeanName, Iterator<Matcher> matchers, int nestingLevel) throws MalformedObjectNameException, JMException {
+        // current level
+        int currentLevel = nestingLevel;
+        int i = 0;
+
+        while (matchers.hasNext()) {
+            Matcher matcher = matchers.next();
+            MatcherManagement matcherManagement = new MatcherManagement(matcher.getMatcherConfig());
+
+
+            String matcherMBeanName = parentMBeanName + ",subtype" + currentLevel +"=matcher,index" + currentLevel+"=" + (i++) + ",matchername" + currentLevel+"=" + matcherManagement.getMatcherName();
+            registerMBean(matcherMBeanName, matcherManagement);
+            matcherMap.put(matcher, matcherManagement);           
+            // Handle CompositeMatcher which were added by JAMES-948
+            if (matcher instanceof CompositeMatcher) {
+                // we increment the nesting as we have one more child level and register the child matchers
+                registerMatchers(matcherMBeanName, ((CompositeMatcher) matcher).iterator(), ++nestingLevel);
+            }
+            
+        }
+    }
+
+    private void registerMBean(String mBeanName, Object object) throws MalformedObjectNameException, JMException{
+         ObjectName objectName = new ObjectName(mBeanName);
+       
+        mbeanserver.registerMBean(object, objectName);
+        mbeans.add(objectName);
+       
+    }
+
+
+    /*
+     * (non-Javadoc)
+     * @see org.apache.james.lifecycle.api.Disposable#dispose()
+     */
+    public void dispose() {
+        unregisterMBeans();
+        mailetMap.clear();
+        matcherMap.clear();
+    }
+
+    
+    /**
+     * Unregister all JMX MBeans
+     */
+    private void unregisterMBeans() {
+        List<ObjectName> unregistered = new ArrayList<ObjectName>();
+        for (int i = 0; i < mbeans.size(); i++) {
+            ObjectName name = mbeans.get(i);
+            
+            try {
+                mbeanserver.unregisterMBean(name);
+                unregistered.add(name);
+            } catch (javax.management.JMException e) {
+                //logger.error("Unable to unregister mbean " + name, e);
+            }
+        }
+        mbeans.removeAll(unregistered);
+    }
+
+
+}

Copied: james/server/trunk/mailetcontainer-library/src/main/java/org/apache/james/mailetcontainer/lib/jmx/MailProcessorManagement.java (from r1051383, james/server/trunk/mailetcontainer-library/src/main/java/org/apache/james/mailetcontainer/lib/ProcessorDetail.java)
URL: http://svn.apache.org/viewvc/james/server/trunk/mailetcontainer-library/src/main/java/org/apache/james/mailetcontainer/lib/jmx/MailProcessorManagement.java?p2=james/server/trunk/mailetcontainer-library/src/main/java/org/apache/james/mailetcontainer/lib/jmx/MailProcessorManagement.java&p1=james/server/trunk/mailetcontainer-library/src/main/java/org/apache/james/mailetcontainer/lib/ProcessorDetail.java&r1=1051383&r2=1051470&rev=1051470&view=diff
==============================================================================
--- james/server/trunk/mailetcontainer-library/src/main/java/org/apache/james/mailetcontainer/lib/ProcessorDetail.java (original)
+++ james/server/trunk/mailetcontainer-library/src/main/java/org/apache/james/mailetcontainer/lib/jmx/MailProcessorManagement.java Tue Dec 21 12:05:57 2010
@@ -17,94 +17,63 @@
  * under the License.                                           *
  ****************************************************************/
 
-package org.apache.james.mailetcontainer.lib;
+package org.apache.james.mailetcontainer.lib.jmx;
 
-import java.util.ArrayList;
-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.MailProcessor;
 import org.apache.james.mailetcontainer.api.MailetContainer;
-import org.apache.james.mailetcontainer.api.ProcessorDetailMBean;
-import org.apache.mailet.Mail;
-import org.apache.mailet.Mailet;
-import org.apache.mailet.Matcher;
+import org.apache.james.mailetcontainer.api.jmx.MailProcessorManagementMBean;
 
 /**
  * Wrapper which helps to expose JMX statistics for {@link MailProcessor} and {@link MailetContainer} implementations
  * 
  *
  */
-public class ProcessorDetail extends StandardMBean implements MailProcessor, MailetContainer, ProcessorDetailMBean{
+public class MailProcessorManagement extends StandardMBean implements MailProcessorManagementMBean{
     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) throws NotCompliantMBeanException {
-        super(ProcessorDetailMBean.class);
+    private AtomicLong errorCount = new AtomicLong(0);
+    private AtomicLong successCount = new AtomicLong(0);
+    private AtomicLong fastestProcessing = new AtomicLong(-1);
+    private AtomicLong slowestProcessing = new AtomicLong(-1);
+
+        
+    public MailProcessorManagement(String processorName) throws NotCompliantMBeanException {
+        super(MailProcessorManagementMBean.class);
         this.processorName = processorName;
-        this.processor = processor;
     }
-    
 
     /*
      * (non-Javadoc)
-     * @see org.apache.james.transport.MailProcessor#service(org.apache.mailet.Mail)
+     * @see org.apache.james.mailetcontainer.api.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;
-         }        
+    public void update(long processTime, boolean success) {
+        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();
+        }
+       
      }
     
-    /*
-     * (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
-     * ()
+     * @see org.apache.james.mailetcontainer.api.jmx.MailProcessingMBean#getHandledMailCount()
      */
     public long getHandledMailCount() {
         return getSuccessCount() + getErrorCount();
@@ -112,8 +81,7 @@ public class ProcessorDetail extends Sta
 
     /*
      * (non-Javadoc)
-     * 
-     * @see org.apache.james.mailetcontainer.ProcessorDetailMBean#getName()
+     * @see org.apache.james.mailetcontainer.api.jmx.MailProcessorDetailMBean#getName()
      */
     public String getName() {
         return processorName;
@@ -121,42 +89,35 @@ public class ProcessorDetail extends Sta
 
     /*
      * (non-Javadoc)
-     * 
-     * @seeorg.apache.james.mailetcontainer.ProcessorDetailMBean#
-     * getFastestProcessing()
+     * @see org.apache.james.mailetcontainer.api.jmx.MailProcessingMBean#getFastestProcessing()
      */
     public long getFastestProcessing() {
-        return fastestProcessing;
+        return fastestProcessing.get();
     }
 
     /*
      * (non-Javadoc)
-     * 
-     * @seeorg.apache.james.mailetcontainer.ProcessorDetailMBean#
-     * getSlowestProcessing()
+     * @see org.apache.james.mailetcontainer.api.jmx.MailProcessingMBean#getSlowestProcessing()
      */
     public long getSlowestProcessing() {
-        return slowestProcessing;
+        return slowestProcessing.get();
     }
 
     /*
      * (non-Javadoc)
-     * 
-     * @see
-     * org.apache.james.mailetcontainer.ProcessorDetailMBean#getErrorCount()
+     * @see org.apache.james.mailetcontainer.api.jmx.MailProcessingMBean#getErrorCount()
      */
     public long getErrorCount() {
-        return errorCount;
+        return errorCount.get();
     }
 
+
     /*
      * (non-Javadoc)
-     * 
-     * @see
-     * org.apache.james.mailetcontainer.ProcessorDetailMBean#getSuccessCount
-     * ()
+     * @see org.apache.james.mailetcontainer.api.jmx.MailProcessingMBean#getSuccessCount()
      */
     public long getSuccessCount() {
-        return successCount;
+        return successCount.get();
     }
+
 }



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