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/10/27 20:04:46 UTC

svn commit: r1028058 - in /james/server/trunk: container-spring/src/main/config/james/ mailbox-adapter/src/main/java/org/apache/james/adapter/mailbox/

Author: norman
Date: Wed Oct 27 18:04:46 2010
New Revision: 1028058

URL: http://svn.apache.org/viewvc?rev=1028058&view=rev
Log:
Add JMX implementation for manage mailboxes for users. This need to get called after a user is deleted to make sure the mailbox and emails get deleted (JAMES-1009)

Added:
    james/server/trunk/mailbox-adapter/src/main/java/org/apache/james/adapter/mailbox/MailboxManagerManagement.java
    james/server/trunk/mailbox-adapter/src/main/java/org/apache/james/adapter/mailbox/MailboxManagerManagementMBean.java
Modified:
    james/server/trunk/container-spring/src/main/config/james/spring-beans.xml

Modified: james/server/trunk/container-spring/src/main/config/james/spring-beans.xml
URL: http://svn.apache.org/viewvc/james/server/trunk/container-spring/src/main/config/james/spring-beans.xml?rev=1028058&r1=1028057&r2=1028058&view=diff
==============================================================================
--- james/server/trunk/container-spring/src/main/config/james/spring-beans.xml (original)
+++ james/server/trunk/container-spring/src/main/config/james/spring-beans.xml Wed Oct 27 18:04:46 2010
@@ -41,11 +41,13 @@
           <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"/>
+          <entry key="org.apache.james:type=component,name=mailboxmanagement" value-ref="mailboxmanagermanagement"/>
+         
         </map>
       </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"/>
+            <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"/>
           </bean>
       </property>
     </bean>
@@ -62,6 +64,8 @@
 
     <bean id="domainlistmanagement" class="org.apache.james.domainlist.lib.DomainListManagement" />
 
+    <bean id="mailboxmanagermanagement" class="org.apache.james.adapter.mailbox.MailboxManagerManagement" />
+
     <bean class="org.apache.james.container.spring.lifecycle.CommonsConfigurableBeanPostProcessor">
         <property name="configurationProvider" ref="configurationProvider" />
         <property name="order" value="1" />

Added: james/server/trunk/mailbox-adapter/src/main/java/org/apache/james/adapter/mailbox/MailboxManagerManagement.java
URL: http://svn.apache.org/viewvc/james/server/trunk/mailbox-adapter/src/main/java/org/apache/james/adapter/mailbox/MailboxManagerManagement.java?rev=1028058&view=auto
==============================================================================
--- james/server/trunk/mailbox-adapter/src/main/java/org/apache/james/adapter/mailbox/MailboxManagerManagement.java (added)
+++ james/server/trunk/mailbox-adapter/src/main/java/org/apache/james/adapter/mailbox/MailboxManagerManagement.java Wed Oct 27 18:04:46 2010
@@ -0,0 +1,125 @@
+
+package org.apache.james.adapter.mailbox;
+
+/****************************************************************
+ * 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.                                           *
+ ****************************************************************/
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+
+import javax.annotation.Resource;
+import javax.management.NotCompliantMBeanException;
+import javax.management.StandardMBean;
+
+import org.apache.commons.logging.Log;
+import org.apache.james.lifecycle.LogEnabled;
+import org.apache.james.mailbox.MailboxException;
+import org.apache.james.mailbox.MailboxManager;
+import org.apache.james.mailbox.MailboxMetaData;
+import org.apache.james.mailbox.MailboxPath;
+import org.apache.james.mailbox.MailboxQuery;
+import org.apache.james.mailbox.MailboxSession;
+
+/**
+ * JMX managmenent for Mailboxes
+ * 
+ *
+ */
+public class MailboxManagerManagement extends StandardMBean implements MailboxManagerManagementMBean, LogEnabled {
+
+    private MailboxManager mailboxManager;
+    private Log log;
+    
+    @Resource(name="mailboxmanager")
+    public void setMailboxManager(MailboxManager mailboxManager) {
+        this.mailboxManager = mailboxManager;
+    }
+    
+    public MailboxManagerManagement() throws NotCompliantMBeanException {
+        super(MailboxManagerManagementMBean.class);
+    }
+    
+    
+    /*
+     * (non-Javadoc)
+     * @see org.apache.james.adapter.mailbox.MailboxManagerManagementMBean#deleteMailboxes(java.lang.String)
+     */
+    public boolean deleteMailboxes(String username) {
+        MailboxSession session = null;
+        try {
+            session = mailboxManager.createSystemSession(username, log);
+            mailboxManager.startProcessingRequest(session);
+            List<MailboxMetaData> mList = mailboxManager.search(new MailboxQuery(MailboxPath.inbox(username), "", '*', '%'), session);
+            for (int i = 0; i < mList.size(); i++) {
+                mailboxManager.deleteMailbox(mList.get(i).getPath(),session);
+            }
+            return true;
+        } catch (MailboxException e) {
+            log.error("Error while remove mailboxes for user " + username, e);
+        } finally {
+            if (session != null) {
+                mailboxManager.endProcessingRequest(session);
+                try {
+                    mailboxManager.logout(session, true);
+                } catch (MailboxException e) {
+                    // ignore here
+                }
+            }
+        }
+        return false;
+    }
+
+    /*
+     * (non-Javadoc)
+     * @see org.apache.james.lifecycle.LogEnabled#setLog(org.apache.commons.logging.Log)
+     */
+    public void setLog(Log log) {
+        this.log = log;
+    }
+
+    /*
+     * (non-Javadoc)
+     * @see org.apache.james.adapter.mailbox.MailboxManagerManagementMBean#listMailboxes(java.lang.String)
+     */
+    public List<String> listMailboxes(String username) {
+        List<String> boxes = new ArrayList<String>();
+        MailboxSession session = null;
+        try {
+            session = mailboxManager.createSystemSession(username, log);
+            mailboxManager.startProcessingRequest(session);
+            List<MailboxMetaData> mList = mailboxManager.search(new MailboxQuery(MailboxPath.inbox(username), "", '*', '%'), session);
+            for (int i = 0; i < mList.size(); i++) {
+                boxes.add(mList.get(i).getPath().getName());
+            }
+            Collections.sort(boxes);
+        } catch (MailboxException e) {
+            log.error("Error list mailboxes for user " + username, e);
+        } finally {
+            if (session != null) {
+                mailboxManager.endProcessingRequest(session);
+                try {
+                    mailboxManager.logout(session, true);
+                } catch (MailboxException e) {
+                    // ignore here
+                }
+            }
+        }
+        return boxes;
+    }
+}
\ No newline at end of file

Added: james/server/trunk/mailbox-adapter/src/main/java/org/apache/james/adapter/mailbox/MailboxManagerManagementMBean.java
URL: http://svn.apache.org/viewvc/james/server/trunk/mailbox-adapter/src/main/java/org/apache/james/adapter/mailbox/MailboxManagerManagementMBean.java?rev=1028058&view=auto
==============================================================================
--- james/server/trunk/mailbox-adapter/src/main/java/org/apache/james/adapter/mailbox/MailboxManagerManagementMBean.java (added)
+++ james/server/trunk/mailbox-adapter/src/main/java/org/apache/james/adapter/mailbox/MailboxManagerManagementMBean.java Wed Oct 27 18:04:46 2010
@@ -0,0 +1,44 @@
+/****************************************************************
+ * 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.adapter.mailbox;
+
+import java.util.List;
+
+/**
+ * JMX MBean for Mailbox management
+ *
+ */
+public interface MailboxManagerManagementMBean {
+
+    /**
+     * Delete all Mailboxes which belong to the user
+     * 
+     * @param username
+     * @return successful
+     */
+    public boolean deleteMailboxes(String username);
+    
+    /**
+     * List all mailboxes for a user
+     * 
+     * @param username
+     * @return mailboxes
+     */
+    public List<String> listMailboxes(String username);
+}
\ No newline at end of file



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