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 be...@apache.org on 2006/06/26 17:00:33 UTC
svn commit: r417204 - in /james/server/trunk/src: conf/
java/org/apache/james/management/ java/org/apache/james/remotemanager/
java/org/apache/james/services/ test/org/apache/james/remotemanager/
Author: berndf
Date: Mon Jun 26 08:00:32 2006
New Revision: 417204
URL: http://svn.apache.org/viewvc?rev=417204&view=rev
Log:
- make spool commands from RemoteManager available in JMX
- common logic centralized in SpoolManagement
Added:
james/server/trunk/src/java/org/apache/james/management/ManagementException.java
james/server/trunk/src/java/org/apache/james/management/SpoolManagement.java
james/server/trunk/src/java/org/apache/james/management/SpoolManagement.xinfo
james/server/trunk/src/java/org/apache/james/management/SpoolManagementException.java
james/server/trunk/src/java/org/apache/james/management/SpoolManagementMBean.java
james/server/trunk/src/java/org/apache/james/services/SpoolManagementService.java
Modified:
james/server/trunk/src/conf/james-assembly.xml
james/server/trunk/src/java/org/apache/james/management/UserManagementException.java
james/server/trunk/src/java/org/apache/james/management/UserManagementMBean.java
james/server/trunk/src/java/org/apache/james/remotemanager/RemoteManager.java
james/server/trunk/src/java/org/apache/james/remotemanager/RemoteManager.xinfo
james/server/trunk/src/java/org/apache/james/remotemanager/RemoteManagerHandler.java
james/server/trunk/src/java/org/apache/james/remotemanager/RemoteManagerHandlerConfigurationData.java
james/server/trunk/src/test/org/apache/james/remotemanager/RemoteManagerTest.java
Modified: james/server/trunk/src/conf/james-assembly.xml
URL: http://svn.apache.org/viewvc/james/server/trunk/src/conf/james-assembly.xml?rev=417204&r1=417203&r2=417204&view=diff
==============================================================================
--- james/server/trunk/src/conf/james-assembly.xml (original)
+++ james/server/trunk/src/conf/james-assembly.xml Mon Jun 26 08:00:32 2006
@@ -54,6 +54,11 @@
<block name="dnsserver" class="org.apache.james.dnsserver.DNSServer" />
+ <!-- The Spool Management block -->
+ <block name="spoolmanagement" class="org.apache.james.management.SpoolManagement" >
+ <provide name="mailstore" role="org.apache.avalon.cornerstone.services.store.Store"/>
+ </block>
+
<block name="remotemanager" class="org.apache.james.remotemanager.RemoteManager" >
<provide name="mailstore" role="org.apache.avalon.cornerstone.services.store.Store"/>
<provide name="users-store" role="org.apache.james.services.UsersStore"/>
@@ -65,9 +70,10 @@
<provide name="James" role="org.apache.james.services.MailServer"/>
<provide name="thread-manager"
role="org.apache.avalon.cornerstone.services.threads.ThreadManager" />
+ <provide name="spoolmanagement" role="org.apache.james.services.SpoolManagementService"/>
</block>
- <!-- The User Management block -->
+ <!-- The User Management block -->
<block name="usermanagement" class="org.apache.james.management.UserManagement" >
<provide name="localusersrepository" role="org.apache.james.services.UsersRepository"/>
<provide name="users-store" role="org.apache.james.services.UsersStore"/>
Added: james/server/trunk/src/java/org/apache/james/management/ManagementException.java
URL: http://svn.apache.org/viewvc/james/server/trunk/src/java/org/apache/james/management/ManagementException.java?rev=417204&view=auto
==============================================================================
--- james/server/trunk/src/java/org/apache/james/management/ManagementException.java (added)
+++ james/server/trunk/src/java/org/apache/james/management/ManagementException.java Mon Jun 26 08:00:32 2006
@@ -0,0 +1,39 @@
+/***********************************************************************
+ * Copyright (c) 2006 The Apache Software Foundation. *
+ * All rights reserved. *
+ * ------------------------------------------------------------------- *
+ * Licensed 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.management;
+
+public class ManagementException extends Exception {
+
+ public ManagementException() {
+ super();
+ }
+
+ public ManagementException(String message) {
+ super(message);
+ }
+
+ public ManagementException(Exception e) {
+ super(e);
+ }
+
+ public ManagementException(String message, Exception e) {
+ super(message, e);
+ }
+
+}
Added: james/server/trunk/src/java/org/apache/james/management/SpoolManagement.java
URL: http://svn.apache.org/viewvc/james/server/trunk/src/java/org/apache/james/management/SpoolManagement.java?rev=417204&view=auto
==============================================================================
--- james/server/trunk/src/java/org/apache/james/management/SpoolManagement.java (added)
+++ james/server/trunk/src/java/org/apache/james/management/SpoolManagement.java Mon Jun 26 08:00:32 2006
@@ -0,0 +1,221 @@
+/***********************************************************************
+ * Copyright (c) 2006 The Apache Software Foundation. *
+ * All rights reserved. *
+ * ------------------------------------------------------------------- *
+ * Licensed 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.management;
+
+import org.apache.avalon.cornerstone.services.store.Store;
+import org.apache.avalon.framework.configuration.DefaultConfiguration;
+import org.apache.avalon.framework.service.ServiceException;
+import org.apache.avalon.framework.service.ServiceManager;
+import org.apache.avalon.framework.service.Serviceable;
+import org.apache.james.services.SpoolManagementService;
+import org.apache.james.services.SpoolRepository;
+import org.apache.mailet.Mail;
+
+import javax.mail.MessagingException;
+import java.util.Date;
+import java.util.Iterator;
+import java.util.List;
+import java.util.ArrayList;
+
+public class SpoolManagement implements Serviceable, SpoolManagementService, SpoolManagementMBean {
+
+ private Store mailStore;
+
+ public void service(ServiceManager serviceManager) throws ServiceException {
+ mailStore = (Store)serviceManager.lookup("org.apache.avalon.cornerstone.services.store.Store" );
+ }
+
+ public String[] listSpoolItems(String spoolRepositoryURL) throws SpoolManagementException {
+ List spoolItems;
+ try {
+ spoolItems = getSpoolItems(spoolRepositoryURL);
+ } catch (Exception e) {
+ throw new SpoolManagementException(e);
+ }
+ return (String[]) spoolItems.toArray(new String[]{});
+ }
+
+ public List getSpoolItems(String spoolRepositoryURL) throws ServiceException, MessagingException {
+ SpoolRepository spoolRepository = getSpoolRepository(spoolRepositoryURL);
+
+ List items = new ArrayList();
+
+ // get an iterator of all keys
+ Iterator spoolR = spoolRepository.list();
+ while (spoolR.hasNext()) {
+ String key = spoolR.next().toString();
+ Mail m = spoolRepository.retrieve(key);
+
+ // Only show email if its in error state.
+ if (m.getState().equals(Mail.ERROR)) {
+ StringBuffer itemInfo = new StringBuffer();
+ itemInfo.append("key: ").append(key).append(" sender: ").append(m.getSender()).append(" recipient:");
+ for (int i = 0; i < m.getRecipients().size(); i++) {
+ itemInfo.append(" ").append(m.getRecipients());
+ }
+ items.add(itemInfo.toString());
+ }
+ }
+
+ return items;
+ }
+
+ public int removeSpoolItems(String spoolRepositoryURL, String key) throws SpoolManagementException {
+ try {
+ return removeSpoolItems(spoolRepositoryURL, key, null);
+ } catch (Exception e) {
+ throw new SpoolManagementException(e);
+ }
+ }
+
+ public int removeSpoolItems(String spoolRepositoryURL, String key, List lockingFailures) throws ServiceException, MessagingException {
+ int count = 0;
+ SpoolRepository spoolRepository = getSpoolRepository(spoolRepositoryURL);
+
+ if (key != null) {
+ count = removeMail(spoolRepository, key, count, lockingFailures);
+ } else {
+ Iterator spoolR = spoolRepository.list();
+
+ while (spoolR.hasNext()) {
+ key = spoolR.next().toString();
+ count = removeMail(spoolRepository, key, count, lockingFailures);
+ }
+ }
+ return count;
+ }
+
+ private int removeMail(SpoolRepository spoolRepository, String key, int count, List lockingFailures) throws MessagingException {
+ try {
+ if (removeMail(spoolRepository, key)) count++;
+ } catch (IllegalStateException e) {
+ lockingFailures.add(key);
+ } catch (SpoolManagementException e) {
+ return count;
+ }
+ return count;
+ }
+
+ public int resendSpoolItems(String spoolRepositoryURL, String key) throws SpoolManagementException {
+ try {
+ return resendSpoolItems(spoolRepositoryURL, key, null);
+ } catch (Exception e) {
+ throw new SpoolManagementException(e);
+ }
+ }
+
+ public int resendSpoolItems(String spoolRepositoryURL, String key, List lockingFailures) throws ServiceException, MessagingException {
+ int count = 0;
+ SpoolRepository spoolRepository = getSpoolRepository(spoolRepositoryURL);
+
+ // check if an key was given as argument
+ if (key != null) {
+ try {
+ if (resendErrorMail(spoolRepository, key)) count++;
+ } catch (IllegalStateException e) {
+ if (lockingFailures != null) lockingFailures.add(key);
+ }
+ } else {
+ // get an iterator of all keys
+ Iterator spoolR = spoolRepository.list();
+
+ while (spoolR.hasNext()) {
+ key = spoolR.next().toString();
+ try {
+ if (resendErrorMail(spoolRepository, key)) count++;
+ } catch (IllegalStateException e) {
+ if (lockingFailures != null) lockingFailures.add(key);
+ }
+ }
+ }
+ return count;
+ }
+
+ /**
+ * Resent the mail that belongs to the given key and spoolRepository
+ *
+ * @param spoolRepository The spoolRepository
+ * @param key The message key
+ * @return true orf false
+ * @throws MessagingException Get thrown if there happen an error on modify the mail
+ */
+ private boolean resendErrorMail(SpoolRepository spoolRepository, String key)
+ throws MessagingException, IllegalStateException {
+ if (!spoolRepository.lock(key)) throw new IllegalStateException("locking failure");
+
+ // get the mail and set the error_message to "0" that will force the spoolmanager to try to deliver it now!
+ Mail m = spoolRepository.retrieve(key);
+
+ if (m.getState().equals(Mail.ERROR)) {
+
+ // this will force Remotedelivery to try deliver the mail now!
+ m.setLastUpdated(new Date(0));
+
+ // store changes
+ spoolRepository.store(m);
+ spoolRepository.unlock(key);
+
+ synchronized (spoolRepository) {
+ spoolRepository.notify();
+ }
+ return true;
+ } else {
+ spoolRepository.unlock(key);
+ return false;
+ }
+ }
+
+ /**
+ * Remove the mail that belongs to the given key and spoolRepository
+ * @param spoolRepository The spoolRepository
+ * @param key The message key
+ * @return true or false
+ * @throws MessagingException Get thrown if there happen an error on modify the mail
+ */
+ private boolean removeMail(SpoolRepository spoolRepository, String key) throws MessagingException, SpoolManagementException {
+ if (!spoolRepository.lock(key)) throw new IllegalStateException("locking failure");
+
+ Mail m = spoolRepository.retrieve(key);
+ if (m == null) throw new SpoolManagementException("mail not available having key " + key);
+ if (!m.getState().equals(Mail.ERROR)) return false;
+
+ spoolRepository.remove(key);
+ return true;
+ }
+
+ /**
+ * Retrieve a spoolRepository by the given url
+ *
+ * @param url The spoolRepository url
+ * @return The spoolRepository
+ * @throws ServiceException Get thrown if the spoolRepository can not retrieved
+ */
+ private SpoolRepository getSpoolRepository(String url)
+ throws ServiceException {
+ // Setup all needed data
+ DefaultConfiguration spoolConf = new DefaultConfiguration("spool",
+ "generated:RemoteManager.java");
+ spoolConf.setAttribute("destinationURL", url);
+ spoolConf.setAttribute("type", "SPOOL");
+
+ return (SpoolRepository) mailStore.select(spoolConf);
+ }
+
+
+}
Added: james/server/trunk/src/java/org/apache/james/management/SpoolManagement.xinfo
URL: http://svn.apache.org/viewvc/james/server/trunk/src/java/org/apache/james/management/SpoolManagement.xinfo?rev=417204&view=auto
==============================================================================
--- james/server/trunk/src/java/org/apache/james/management/SpoolManagement.xinfo (added)
+++ james/server/trunk/src/java/org/apache/james/management/SpoolManagement.xinfo Mon Jun 26 08:00:32 2006
@@ -0,0 +1,24 @@
+<?xml version="1.0"?>
+
+<blockinfo>
+
+ <!-- section to describe block -->
+ <block>
+ <version>1.0</version>
+ </block>
+
+ <services>
+ <service name="org.apache.james.services.SpoolManagementService" version="1.0" />
+ </services>
+
+ <!-- interfaces that may be exported to manange this block -->
+ <management-access-points>
+ <service name="org.apache.james.management.SpoolManagementMBean"/>
+ </management-access-points>
+
+ <dependencies>
+ <dependency>
+ <service name="org.apache.avalon.cornerstone.services.store.Store" version="1.0"/>
+ </dependency>
+ </dependencies>
+</blockinfo>
Added: james/server/trunk/src/java/org/apache/james/management/SpoolManagementException.java
URL: http://svn.apache.org/viewvc/james/server/trunk/src/java/org/apache/james/management/SpoolManagementException.java?rev=417204&view=auto
==============================================================================
--- james/server/trunk/src/java/org/apache/james/management/SpoolManagementException.java (added)
+++ james/server/trunk/src/java/org/apache/james/management/SpoolManagementException.java Mon Jun 26 08:00:32 2006
@@ -0,0 +1,39 @@
+/***********************************************************************
+ * Copyright (c) 2006 The Apache Software Foundation. *
+ * All rights reserved. *
+ * ------------------------------------------------------------------- *
+ * Licensed 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.management;
+
+public class SpoolManagementException extends ManagementException {
+
+ public SpoolManagementException() {
+ super();
+ }
+
+ public SpoolManagementException(String message) {
+ super(message);
+ }
+
+ public SpoolManagementException(Exception e) {
+ super(e);
+ }
+
+ public SpoolManagementException(String message, Exception e) {
+ super(message, e);
+ }
+
+}
Added: james/server/trunk/src/java/org/apache/james/management/SpoolManagementMBean.java
URL: http://svn.apache.org/viewvc/james/server/trunk/src/java/org/apache/james/management/SpoolManagementMBean.java?rev=417204&view=auto
==============================================================================
--- james/server/trunk/src/java/org/apache/james/management/SpoolManagementMBean.java (added)
+++ james/server/trunk/src/java/org/apache/james/management/SpoolManagementMBean.java Mon Jun 26 08:00:32 2006
@@ -0,0 +1,63 @@
+/***********************************************************************
+ * Copyright (c) 2006 The Apache Software Foundation. *
+ * All rights reserved. *
+ * ------------------------------------------------------------------- *
+ * Licensed 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.management;
+
+/**
+ * Expose spool management functionality through JMX.
+ *
+ * @phoenix:mx-topic name="SpoolAdministration"
+ */
+public interface SpoolManagementMBean {
+
+ /**
+ * List mails on the spool whose state is ERROR
+ *
+ * @phoenix:mx-operation
+ * @phoenix:mx-description List mails on the spool whose state is ERROR
+ *
+ * @param spoolRepositoryURL specifies the spool
+ * @return number of removed items
+ */
+ String[] listSpoolItems(String spoolRepositoryURL) throws SpoolManagementException;
+
+ /**
+ * Removes one specific or all mails from the given spool repository
+ *
+ * @phoenix:mx-operation
+ * @phoenix:mx-description Removes one specific or all mails from the given spool repository
+ *
+ * @param spoolRepositoryURL specifies the spool
+ * @param key identifies the item to be removed. if NULL, all items are removed
+ * @return number of removed items
+ */
+ int removeSpoolItems(String spoolRepositoryURL, String key) throws SpoolManagementException;
+
+ /**
+ * (Re-)tries to send one specific or all mails with status ERROR in the given spool repository
+ *
+ * @phoenix:mx-operation
+ * @phoenix:mx-description (Re-)tries to send one specific or all mails with status ERROR in the given spool repository
+ *
+ * @param spoolRepositoryURL specifies the spool
+ * @param key identifies the item to be sent. if NULL, all items with status ERROR are sent
+ * @return number of processed items
+ */
+ int resendSpoolItems(String spoolRepositoryURL, String key) throws SpoolManagementException;
+
+}
Modified: james/server/trunk/src/java/org/apache/james/management/UserManagementException.java
URL: http://svn.apache.org/viewvc/james/server/trunk/src/java/org/apache/james/management/UserManagementException.java?rev=417204&r1=417203&r2=417204&view=diff
==============================================================================
--- james/server/trunk/src/java/org/apache/james/management/UserManagementException.java (original)
+++ james/server/trunk/src/java/org/apache/james/management/UserManagementException.java Mon Jun 26 08:00:32 2006
@@ -18,7 +18,7 @@
package org.apache.james.management;
-public class UserManagementException extends Exception {
+public class UserManagementException extends ManagementException {
public UserManagementException() {
super();
Modified: james/server/trunk/src/java/org/apache/james/management/UserManagementMBean.java
URL: http://svn.apache.org/viewvc/james/server/trunk/src/java/org/apache/james/management/UserManagementMBean.java?rev=417204&r1=417203&r2=417204&view=diff
==============================================================================
--- james/server/trunk/src/java/org/apache/james/management/UserManagementMBean.java (original)
+++ james/server/trunk/src/java/org/apache/james/management/UserManagementMBean.java Mon Jun 26 08:00:32 2006
@@ -191,5 +191,5 @@
*
* @return List<String> of repository names
*/
- public List getUserRepositoryNames();
+ List getUserRepositoryNames();
}
Modified: james/server/trunk/src/java/org/apache/james/remotemanager/RemoteManager.java
URL: http://svn.apache.org/viewvc/james/server/trunk/src/java/org/apache/james/remotemanager/RemoteManager.java?rev=417204&r1=417203&r2=417204&view=diff
==============================================================================
--- james/server/trunk/src/java/org/apache/james/remotemanager/RemoteManager.java (original)
+++ james/server/trunk/src/java/org/apache/james/remotemanager/RemoteManager.java Mon Jun 26 08:00:32 2006
@@ -25,6 +25,7 @@
import org.apache.avalon.framework.service.ServiceManager;
import org.apache.james.core.AbstractJamesService;
import org.apache.james.services.MailServer;
+import org.apache.james.services.SpoolManagementService;
import org.apache.james.services.UsersRepository;
import org.apache.james.services.UsersStore;
@@ -57,15 +58,20 @@
private UsersRepository users;
/**
+ * The reference to the spool management service
+ */
+ private SpoolManagementService spoolManagement;
+
+ /**
* The service prompt to be displayed when waiting for input.
*/
private String prompt = "";
-
+
/**
* The reference to the internal MailServer service
*/
private MailServer mailServer;
-
+
/**
* There reference to the Store
*/
@@ -93,6 +99,7 @@
if (users == null) {
throw new ServiceException("","The user repository could not be found.");
}
+ spoolManagement = (SpoolManagementService) componentManager.lookup(SpoolManagementService.ROLE);
}
/**
@@ -153,7 +160,7 @@
}
/**
- * @see org.apache.avalon.excalibur.pool.ObjectFactory#decommision(Object)
+ * @see org.apache.avalon.excalibur.pool.ObjectFactory#decommission(Object)
*/
public void decommission( Object object ) throws Exception {
return;
@@ -197,10 +204,14 @@
}
/**
- * @see org.apache.james.remotemanager.RemoteManagerHandlerConfigurationData#getUsersStore()
+ * @see org.apache.james.remotemanager.RemoteManagerHandlerConfigurationData#getUserStore()
*/
public UsersStore getUserStore() {
return RemoteManager.this.usersStore;
+ }
+
+ public SpoolManagementService getSpoolManagement() {
+ return RemoteManager.this.spoolManagement;
}
/**
Modified: james/server/trunk/src/java/org/apache/james/remotemanager/RemoteManager.xinfo
URL: http://svn.apache.org/viewvc/james/server/trunk/src/java/org/apache/james/remotemanager/RemoteManager.xinfo?rev=417204&r1=417203&r2=417204&view=diff
==============================================================================
--- james/server/trunk/src/java/org/apache/james/remotemanager/RemoteManager.xinfo (original)
+++ james/server/trunk/src/java/org/apache/james/remotemanager/RemoteManager.xinfo Mon Jun 26 08:00:32 2006
@@ -34,5 +34,8 @@
<dependency>
<service name="org.apache.avalon.cornerstone.services.threads.ThreadManager" version="1.0"/>
</dependency>
+ <dependency>
+ <service name="org.apache.james.services.SpoolManagementService" version="1.0"/>
+ </dependency>
</dependencies>
</blockinfo>
Modified: james/server/trunk/src/java/org/apache/james/remotemanager/RemoteManagerHandler.java
URL: http://svn.apache.org/viewvc/james/server/trunk/src/java/org/apache/james/remotemanager/RemoteManagerHandler.java?rev=417204&r1=417203&r2=417204&view=diff
==============================================================================
--- james/server/trunk/src/java/org/apache/james/remotemanager/RemoteManagerHandler.java (original)
+++ james/server/trunk/src/java/org/apache/james/remotemanager/RemoteManagerHandler.java Mon Jun 26 08:00:32 2006
@@ -22,21 +22,15 @@
import org.apache.james.services.JamesUser;
import org.apache.james.services.User;
import org.apache.james.services.UsersRepository;
-import org.apache.james.services.SpoolRepository;
-
import org.apache.mailet.MailAddress;
-import org.apache.mailet.Mail;
-import org.apache.avalon.framework.configuration.DefaultConfiguration;
-import org.apache.avalon.framework.service.ServiceException;
import javax.mail.internet.ParseException;
-import javax.mail.MessagingException;
-
import java.io.IOException;
import java.net.Socket;
+import java.util.ArrayList;
import java.util.Iterator;
import java.util.Locale;
-import java.util.Date;
+import java.util.List;
/**
@@ -125,17 +119,17 @@
* The text string for the LISTSPOOL command
*/
private static final String COMMAND_LISTSPOOL = "LISTSPOOL";
-
+
/**
* The text string for the FLUSHSPOOL command
*/
private static final String COMMAND_FLUSHSPOOL = "FLUSHSPOOL";
-
+
/**
* The text string for the DELETESPOOL command
*/
private static final String COMMAND_DELETESPOOL = "DELETESPOOL";
-
+
/**
* The text string for the QUIT command
*/
@@ -164,7 +158,7 @@
public void setConfigurationData(Object theData) {
if (theData instanceof RemoteManagerHandlerConfigurationData) {
theConfigData = (RemoteManagerHandlerConfigurationData) theData;
-
+
// Reset the users repository to the default.
users = theConfigData.getUsersRepository();
} else {
@@ -231,7 +225,7 @@
getLogger().info(infoBuffer.toString());
}
-
+
/**
* @see org.apache.james.core.AbstractJamesHandler#errorHandler(java.lang.RuntimeException)
*/
@@ -267,7 +261,7 @@
* wire in handleConnection. It returns true if expecting additional
* commands, false otherwise.</p>
*
- * @param command the raw command string passed in over the socket
+ * @param rawCommand the raw command string passed in over the socket
*
* @return whether additional commands are expected.
*/
@@ -558,7 +552,7 @@
out.println("quit close connection");
out.flush();
return true;
-
+
}
/**
@@ -581,7 +575,7 @@
writeLoggedFlushedResponse("Usage: setalias [username] [alias]");
return true;
}
-
+
User baseuser = users.getUserByName(username);
if (baseuser == null) {
writeLoggedFlushedResponse("No such user " + username);
@@ -591,7 +585,7 @@
writeLoggedFlushedResponse("Can't set alias for this user type.");
return true;
}
-
+
JamesUser user = (JamesUser) baseuser;
JamesUser aliasUser = (JamesUser) users.getUserByName(alias);
if (aliasUser == null) {
@@ -685,7 +679,7 @@
* Handler method called upon receipt of an SHOWALIAS command.
* Returns whether further commands should be read off the wire.
*
- * @param argument the user name
+ * @param username the user name
*/
private boolean doSHOWALIAS(String username) {
if ( username == null || username.equals("") ) {
@@ -731,7 +725,7 @@
* Handler method called upon receipt of an SHOWFORWARDING command.
* Returns whether further commands should be read off the wire.
*
- * @param argument the user name
+ * @param username the user name
*/
private boolean doSHOWFORWARDING(String username) {
if ( username == null || username.equals("") ) {
@@ -864,7 +858,7 @@
}
return true;
}
-
+
/**
* Handler method called upon receipt of a LISTSPOOL command. Returns
* whether further commands should be read off the wire.
@@ -883,30 +877,14 @@
String url = argument;
- SpoolRepository spoolRepository;
try {
- spoolRepository = getSpoolRepository(url);
-
- // get an iterator of all keys
- Iterator spoolR = spoolRepository.list();
-
- while (spoolR.hasNext()) {
- String key = spoolR.next().toString();
-
- out.println("Messages in spool:");
- Mail m = spoolRepository.retrieve(key);
-
- // Only show email if its in error state.
- if (m.getState().equals(Mail.ERROR)) {
- out.print("key: " + key + " sender: " + m.getSender()
- + " recipient:");
- for (int i = 0; i < m.getRecipients().size(); i++) {
- out.print(" " + m.getRecipients());
- }
- out.println();
-
- count++;
- }
+ List spoolItems = theConfigData.getSpoolManagement().getSpoolItems(url);
+ count = spoolItems.size();
+ if (count > 0) out.println("Messages in spool:");
+ for (Iterator iterator = spoolItems.iterator(); iterator.hasNext();) {
+ String item = (String) iterator.next();
+ out.println(item);
+ out.flush();
}
out.println("Number of spooled mails: " + count);
out.flush();
@@ -939,28 +917,10 @@
return true;
}
- SpoolRepository spoolRepository;
String url = args[0];
+ String key = args.length == 2 ? args[1] : null;
try {
-
- spoolRepository = getSpoolRepository(url);
-
- // check if an key was given as argument
- if (args.length == 2) {
- String key = args[1];
- if (resendErrorMail(spoolRepository, key))
- count++;
-
- } else {
- // get an iterator of all keys
- Iterator spoolR = spoolRepository.list();
-
- while (spoolR.hasNext()) {
- String key = spoolR.next().toString();
- if (resendErrorMail(spoolRepository, key))
- count++;
- }
- }
+ count = theConfigData.getSpoolManagement().resendSpoolItems(url, key, null);
out.println("Number of flushed mails: " + count);
out.flush();
@@ -976,49 +936,6 @@
}
/**
- * Resent the mail that belongs to the given key and spoolRepository
- *
- * @param spoolRepository The spoolRepository
- * @param key The message key
- * @return true orf false
- * @throws MessagingException Get thrown if there happen an error on modify the mail
- */
- private boolean resendErrorMail(SpoolRepository spoolRepository, String key)
- throws MessagingException {
- if (spoolRepository.lock(key)) {
-
- // get the mail and set the error_message to "0" that will force the spoolmanager to try to deliver it now!
- Mail m = spoolRepository.retrieve(key);
-
- if (m.getState().equals(Mail.ERROR)) {
-
- // this will force Remotedelivery to try deliver the mail now!
- m.setLastUpdated(new Date(0));
-
- // store changes
- spoolRepository.store(m);
- spoolRepository.unlock(key);
-
- synchronized (spoolRepository) {
- spoolRepository.notify();
- }
- return true;
- } else {
-
- spoolRepository.unlock(key);
-
- out.println("The mail with key " + key
- + " is not in error state!");
- out.flush();
- }
- } else {
- out.println("Error locking the mail with key: " + key);
- out.flush();
- }
- return false;
- }
-
- /**
* Handler method called upon receipt of a DELETESPOOL command. Returns
* whether further commands should be read off the wire.
*
@@ -1026,7 +943,6 @@
* the argument passed in with the command
*/
private boolean doDELETESPOOL(String argument) {
- int count = 0;
String[] args = null;
if (argument != null)
@@ -1039,82 +955,29 @@
return true;
}
- SpoolRepository spoolRepository;
String url = args[0];
+ String key = args.length == 2 ? args[1] : null;
+
try {
- spoolRepository = getSpoolRepository(url);
+ ArrayList lockingFailures = new ArrayList();
+ int count = theConfigData.getSpoolManagement().removeSpoolItems(url, key, lockingFailures);
- if (args.length == 2) {
- String key = args[1];
- if (removeMail(spoolRepository, key))
- count++;
- } else {
- Iterator spoolR = spoolRepository.list();
-
- while (spoolR.hasNext()) {
- String key = spoolR.next().toString();
-
- if (removeMail(spoolRepository, key))
- count++;
- }
+ for (Iterator iterator = lockingFailures.iterator(); iterator.hasNext();) {
+ String lockFailureKey = (String) iterator.next();
+ out.println("Error locking the mail with key: " + lockFailureKey);
}
+ out.flush();
+
out.println("Number of deleted mails: " + count);
out.flush();
} catch (Exception e) {
out.println("Error opening the spoolrepository " + e.getMessage());
out.flush();
- getLogger().error(
- "Error opeing the spoolrepository " + e.getMessage());
+ getLogger().error("Error opeing the spoolrepository " + e.getMessage());
}
return true;
}
-
- /**
- * Remove the mail that belongs to the given key and spoolRepository
- * @param spoolRepository The spoolRepository
- * @param key The message key
- * @return true or false
- * @throws MessagingException Get thrown if there happen an error on modify the mail
- */
- private boolean removeMail(SpoolRepository spoolRepository, String key)
- throws MessagingException {
- if (spoolRepository.lock(key)) {
-
- Mail m = spoolRepository.retrieve(key);
- if (m.getState().equals(Mail.ERROR)) {
-
- spoolRepository.remove(key);
- return true;
- }
- } else {
- out.println("Error locking the mail with key: " + key);
- out.flush();
- }
- return false;
- }
-
- /**
- * Retrieve a spoolRepository by the given url
- *
- * @param url The spoolRepository url
- * @return The spoolRepository
- * @throws ServiceException Get thrown if the spoolRepository can not retrieved
- */
- private SpoolRepository getSpoolRepository(String url)
- throws ServiceException {
- SpoolRepository spoolRepository;
- // Setup all needed data
- DefaultConfiguration spoolConf = new DefaultConfiguration("spool",
- "generated:RemoteManager.java");
- spoolConf.setAttribute("destinationURL", url);
- spoolConf.setAttribute("type", "SPOOL");
-
- spoolRepository = (SpoolRepository) theConfigData.getStore().select(
- spoolConf);
- return spoolRepository;
- }
-
/**
* Handler method called upon receipt of a QUIT command. Returns whether
Modified: james/server/trunk/src/java/org/apache/james/remotemanager/RemoteManagerHandlerConfigurationData.java
URL: http://svn.apache.org/viewvc/james/server/trunk/src/java/org/apache/james/remotemanager/RemoteManagerHandlerConfigurationData.java?rev=417204&r1=417203&r2=417204&view=diff
==============================================================================
--- james/server/trunk/src/java/org/apache/james/remotemanager/RemoteManagerHandlerConfigurationData.java (original)
+++ james/server/trunk/src/java/org/apache/james/remotemanager/RemoteManagerHandlerConfigurationData.java Mon Jun 26 08:00:32 2006
@@ -19,6 +19,7 @@
import org.apache.avalon.cornerstone.services.store.Store;
import org.apache.james.services.MailServer;
+import org.apache.james.services.SpoolManagementService;
import org.apache.james.services.UsersRepository;
import org.apache.james.services.UsersStore;
@@ -58,6 +59,13 @@
* @return the local users store
*/
UsersStore getUserStore();
+
+ /**
+ * Returns the SpoolManagement for this service.
+ *
+ * @return the spool manager
+ */
+ SpoolManagementService getSpoolManagement();
/**
* Returns the Administrative Account Data
Added: james/server/trunk/src/java/org/apache/james/services/SpoolManagementService.java
URL: http://svn.apache.org/viewvc/james/server/trunk/src/java/org/apache/james/services/SpoolManagementService.java?rev=417204&view=auto
==============================================================================
--- james/server/trunk/src/java/org/apache/james/services/SpoolManagementService.java (added)
+++ james/server/trunk/src/java/org/apache/james/services/SpoolManagementService.java Mon Jun 26 08:00:32 2006
@@ -0,0 +1,34 @@
+/***********************************************************************
+ * Copyright (c) 2006 The Apache Software Foundation. *
+ * All rights reserved. *
+ * ------------------------------------------------------------------- *
+ * Licensed 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.services;
+
+import org.apache.avalon.framework.service.ServiceException;
+
+import javax.mail.MessagingException;
+import java.util.List;
+
+public interface SpoolManagementService {
+ String ROLE = "org.apache.james.services.SpoolManagementService";
+
+ public int removeSpoolItems(String spoolRepositoryURL, String key, List lockingFailures) throws ServiceException, MessagingException;
+
+ public int resendSpoolItems(String spoolRepositoryURL, String key, List lockingFailures) throws ServiceException, MessagingException;
+
+ public List getSpoolItems(String spoolRepositoryURL) throws ServiceException, MessagingException;
+}
Modified: james/server/trunk/src/test/org/apache/james/remotemanager/RemoteManagerTest.java
URL: http://svn.apache.org/viewvc/james/server/trunk/src/test/org/apache/james/remotemanager/RemoteManagerTest.java?rev=417204&r1=417203&r2=417204&view=diff
==============================================================================
--- james/server/trunk/src/test/org/apache/james/remotemanager/RemoteManagerTest.java (original)
+++ james/server/trunk/src/test/org/apache/james/remotemanager/RemoteManagerTest.java Mon Jun 26 08:00:32 2006
@@ -266,27 +266,15 @@
login();
sendCommand("help");
- try {
- Thread.sleep(100);
- } catch (InterruptedException e) {
- ; // ignore
- }
+ delay();
assertTrue("command line is effective", readAnswer().size() > 0);
sendCommand("quit");
- try {
- Thread.sleep(100);
- } catch (InterruptedException e) {
- ; // ignore
- }
+ delay();
readAnswer(0);
sendCommand("help");
- try {
- Thread.sleep(100);
- } catch (InterruptedException e) {
- ; // ignore
- }
+ delay();
assertNull("connection is closed", m_reader.readLine());
}
@@ -302,12 +290,8 @@
sendCommand("adduser " + user + " test");
readAnswer(1);
}
-
- try {
- Thread.sleep(100);
- } catch (InterruptedException e) {
- ; // ignore
- }
+
+ delay();
sendCommand("listusers");
List list = readAnswer(5);
@@ -325,6 +309,14 @@
for (int i = 0; i < users.length; i++) {
String user = users[i];
assertTrue("name found", readUserNames.contains(user));
+ }
+ }
+
+ private void delay() {
+ try {
+ Thread.sleep(100);
+ } catch (InterruptedException e) {
+ ; // ignore
}
}
---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org