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 ba...@apache.org on 2006/05/12 23:30:05 UTC
svn commit: r405882 - in /james/server/trunk/src:
java/org/apache/james/transport/JamesSpoolManager.java
java/org/apache/james/transport/LinearProcessor.java
test/org/apache/james/transport/LinearProcessorTest.java
Author: bago
Date: Fri May 12 14:30:04 2006
New Revision: 405882
URL: http://svn.apache.org/viewcvs?rev=405882&view=rev
Log:
Moved LinearProcessor configuration/initialization in the LinearProcessor: it does not make sense to "instrument" it from the SpoolManager (part of JAMES-491)
Modified:
james/server/trunk/src/java/org/apache/james/transport/JamesSpoolManager.java
james/server/trunk/src/java/org/apache/james/transport/LinearProcessor.java
james/server/trunk/src/test/org/apache/james/transport/LinearProcessorTest.java
Modified: james/server/trunk/src/java/org/apache/james/transport/JamesSpoolManager.java
URL: http://svn.apache.org/viewcvs/james/server/trunk/src/java/org/apache/james/transport/JamesSpoolManager.java?rev=405882&r1=405881&r2=405882&view=diff
==============================================================================
--- james/server/trunk/src/java/org/apache/james/transport/JamesSpoolManager.java (original)
+++ james/server/trunk/src/java/org/apache/james/transport/JamesSpoolManager.java Fri May 12 14:30:04 2006
@@ -22,18 +22,14 @@
import org.apache.avalon.framework.configuration.Configurable;
import org.apache.avalon.framework.configuration.Configuration;
import org.apache.avalon.framework.configuration.ConfigurationException;
+import org.apache.avalon.framework.container.ContainerUtil;
import org.apache.avalon.framework.logger.AbstractLogEnabled;
-import org.apache.avalon.framework.service.DefaultServiceManager;
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.MailetLoader;
-import org.apache.james.services.MatcherLoader;
import org.apache.james.services.SpoolRepository;
import org.apache.mailet.Mail;
-import org.apache.mailet.Mailet;
import org.apache.mailet.MailetException;
-import org.apache.mailet.Matcher;
import javax.mail.MessagingException;
@@ -56,7 +52,7 @@
/**
* System component manager
*/
- private DefaultServiceManager compMgr;
+ private ServiceManager compMgr;
/**
* The configuration object used by this spool manager.
@@ -115,7 +111,8 @@
*/
public void service(ServiceManager comp) throws ServiceException {
// threadManager = (ThreadManager) comp.lookup(ThreadManager.ROLE);
- compMgr = new DefaultServiceManager(comp);
+ compMgr = comp;
+ spool = (SpoolRepository) compMgr.lookup(SpoolRepository.ROLE);
}
/**
@@ -132,12 +129,6 @@
public void initialize() throws Exception {
getLogger().info("JamesSpoolManager init...");
- spool = (SpoolRepository) compMgr.lookup(SpoolRepository.ROLE);
-
- MailetLoader mailetLoader
- = (MailetLoader) compMgr.lookup(MailetLoader.ROLE);
- MatcherLoader matchLoader
- = (MatcherLoader) compMgr.lookup(MatcherLoader.ROLE);
//A processor is a Collection of
processors = new HashMap();
@@ -149,93 +140,12 @@
String processorName = processorConf.getAttribute("name");
try {
LinearProcessor processor = new LinearProcessor();
- setupLogger(processor, processorName);
- processor.setSpool(spool);
- processor.initialize();
processors.put(processorName, processor);
-
- final Configuration[] mailetConfs
- = processorConf.getChildren( "mailet" );
- // Loop through the mailet configuration, load
- // all of the matcher and mailets, and add
- // them to the processor.
- for ( int j = 0; j < mailetConfs.length; j++ )
- {
- Configuration c = mailetConfs[j];
- String mailetClassName = c.getAttribute("class");
- String matcherName = c.getAttribute("match");
- Mailet mailet = null;
- Matcher matcher = null;
- try {
- matcher = matchLoader.getMatcher(matcherName);
- //The matcher itself should log that it's been inited.
- if (getLogger().isInfoEnabled()) {
- StringBuffer infoBuffer =
- new StringBuffer(64)
- .append("Matcher ")
- .append(matcherName)
- .append(" instantiated.");
- getLogger().info(infoBuffer.toString());
- }
- } catch (MessagingException ex) {
- // **** Do better job printing out exception
- if (getLogger().isErrorEnabled()) {
- StringBuffer errorBuffer =
- new StringBuffer(256)
- .append("Unable to init matcher ")
- .append(matcherName)
- .append(": ")
- .append(ex.toString());
- getLogger().error( errorBuffer.toString(), ex );
- if (ex.getNextException() != null) {
- getLogger().error( "Caused by nested exception: ", ex.getNextException());
- }
- }
- System.err.println("Unable to init matcher " + matcherName);
- System.err.println("Check spool manager logs for more details.");
- //System.exit(1);
- throw ex;
- }
- try {
- mailet = mailetLoader.getMailet(mailetClassName, c);
- if (getLogger().isInfoEnabled()) {
- StringBuffer infoBuffer =
- new StringBuffer(64)
- .append("Mailet ")
- .append(mailetClassName)
- .append(" instantiated.");
- getLogger().info(infoBuffer.toString());
- }
- } catch (MessagingException ex) {
- // **** Do better job printing out exception
- if (getLogger().isErrorEnabled()) {
- StringBuffer errorBuffer =
- new StringBuffer(256)
- .append("Unable to init mailet ")
- .append(mailetClassName)
- .append(": ")
- .append(ex.toString());
- getLogger().error( errorBuffer.toString(), ex );
- if (ex.getNextException() != null) {
- getLogger().error( "Caused by nested exception: ", ex.getNextException());
- }
- }
- System.err.println("Unable to init mailet " + mailetClassName);
- System.err.println("Check spool manager logs for more details.");
- //System.exit(1);
- throw ex;
- }
- //Add this pair to the processor
- processor.add(matcher, mailet);
- }
-
- // Close the processor matcher/mailet lists.
- //
- // Please note that this is critical to the proper operation
- // of the LinearProcessor code. The processor will not be
- // able to service mails until this call is made.
- processor.closeProcessorLists();
-
+
+ setupLogger(processor, processorName);
+ ContainerUtil.service(processor, compMgr);
+ ContainerUtil.configure(processor, processorConf);
+
if (getLogger().isInfoEnabled()) {
StringBuffer infoBuffer =
new StringBuffer(64)
Modified: james/server/trunk/src/java/org/apache/james/transport/LinearProcessor.java
URL: http://svn.apache.org/viewcvs/james/server/trunk/src/java/org/apache/james/transport/LinearProcessor.java?rev=405882&r1=405881&r2=405882&view=diff
==============================================================================
--- james/server/trunk/src/java/org/apache/james/transport/LinearProcessor.java (original)
+++ james/server/trunk/src/java/org/apache/james/transport/LinearProcessor.java Fri May 12 14:30:04 2006
@@ -17,11 +17,18 @@
package org.apache.james.transport;
-import org.apache.avalon.framework.activity.Initializable;
import org.apache.avalon.framework.activity.Disposable;
+import org.apache.avalon.framework.configuration.Configurable;
+import org.apache.avalon.framework.configuration.Configuration;
+import org.apache.avalon.framework.configuration.ConfigurationException;
import org.apache.avalon.framework.logger.AbstractLogEnabled;
+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.core.MailImpl;
import org.apache.james.core.MailetConfigImpl;
+import org.apache.james.services.MailetLoader;
+import org.apache.james.services.MatcherLoader;
import org.apache.james.services.SpoolRepository;
import org.apache.mailet.GenericMailet;
import org.apache.mailet.GenericMatcher;
@@ -33,15 +40,16 @@
import org.apache.mailet.Matcher;
import javax.mail.MessagingException;
+
import java.io.PrintWriter;
import java.io.StringWriter;
import java.util.ArrayList;
import java.util.Collection;
+import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
-import java.util.Random;
-import java.util.Iterator;
import java.util.Locale;
+import java.util.Random;
/**
* Implements a processor for mails, directing the mail down
@@ -78,7 +86,7 @@
*/
public class LinearProcessor
extends AbstractLogEnabled
- implements Initializable, Disposable {
+ implements Disposable, Configurable, Serviceable {
private static final Random random = new Random(); // Used to generate new mail names
@@ -105,6 +113,12 @@
private volatile boolean listsClosed; // Whether the matcher/mailet lists have been closed.
private SpoolRepository spool; // The spool on which this processor is acting
+ private ServiceManager compMgr;
+
+ private MailetLoader mailetLoader;
+
+ private MatcherLoader matchLoader;
+
/**
* Set the spool to be used by this LinearProcessor.
*
@@ -120,14 +134,6 @@
}
/**
- * @see org.apache.avalon.framework.activity.Initializable#initialize()
- */
- public void initialize() {
- matchers = new ArrayList();
- mailets = new ArrayList();
- }
-
- /**
* <p>The dispose operation is called at the end of a components lifecycle.
* Instances of this class use this method to release and destroy any
* resources that they own.</p>
@@ -529,5 +535,113 @@
mail.setErrorMessage(errorString);
getLogger().error(errorString);
throw me;
+ }
+
+ /**
+ * <p>Initialize the processor matcher/mailet list.</p>
+ */
+ public void openProcessorList() {
+ matchers = new ArrayList();
+ mailets = new ArrayList();
+ }
+
+ /**
+ * @see org.apache.avalon.framework.configuration.Configurable#configure(org.apache.avalon.framework.configuration.Configuration)
+ */
+ public void configure(Configuration processorConf) throws ConfigurationException {
+ openProcessorList();
+
+ final Configuration[] mailetConfs
+ = processorConf.getChildren( "mailet" );
+ // Loop through the mailet configuration, load
+ // all of the matcher and mailets, and add
+ // them to the processor.
+ for ( int j = 0; j < mailetConfs.length; j++ )
+ {
+ Configuration c = mailetConfs[j];
+ String mailetClassName = c.getAttribute("class");
+ String matcherName = c.getAttribute("match");
+ Mailet mailet = null;
+ Matcher matcher = null;
+ try {
+ matcher = matchLoader.getMatcher(matcherName);
+ //The matcher itself should log that it's been inited.
+ if (getLogger().isInfoEnabled()) {
+ StringBuffer infoBuffer =
+ new StringBuffer(64)
+ .append("Matcher ")
+ .append(matcherName)
+ .append(" instantiated.");
+ getLogger().info(infoBuffer.toString());
+ }
+ } catch (MessagingException ex) {
+ // **** Do better job printing out exception
+ if (getLogger().isErrorEnabled()) {
+ StringBuffer errorBuffer =
+ new StringBuffer(256)
+ .append("Unable to init matcher ")
+ .append(matcherName)
+ .append(": ")
+ .append(ex.toString());
+ getLogger().error( errorBuffer.toString(), ex );
+ if (ex.getNextException() != null) {
+ getLogger().error( "Caused by nested exception: ", ex.getNextException());
+ }
+ }
+ System.err.println("Unable to init matcher " + matcherName);
+ System.err.println("Check spool manager logs for more details.");
+ //System.exit(1);
+ throw new ConfigurationException("Unable to init matcher",c,ex);
+ }
+ try {
+ mailet = mailetLoader.getMailet(mailetClassName, c);
+ if (getLogger().isInfoEnabled()) {
+ StringBuffer infoBuffer =
+ new StringBuffer(64)
+ .append("Mailet ")
+ .append(mailetClassName)
+ .append(" instantiated.");
+ getLogger().info(infoBuffer.toString());
+ }
+ } catch (MessagingException ex) {
+ // **** Do better job printing out exception
+ if (getLogger().isErrorEnabled()) {
+ StringBuffer errorBuffer =
+ new StringBuffer(256)
+ .append("Unable to init mailet ")
+ .append(mailetClassName)
+ .append(": ")
+ .append(ex.toString());
+ getLogger().error( errorBuffer.toString(), ex );
+ if (ex.getNextException() != null) {
+ getLogger().error( "Caused by nested exception: ", ex.getNextException());
+ }
+ }
+ System.err.println("Unable to init mailet " + mailetClassName);
+ System.err.println("Check spool manager logs for more details.");
+ //System.exit(1);
+ throw new ConfigurationException("Unable to init mailet",c,ex);
+ }
+ //Add this pair to the processor
+ add(matcher, mailet);
+ }
+
+ // Close the processor matcher/mailet lists.
+ //
+ // Please note that this is critical to the proper operation
+ // of the LinearProcessor code. The processor will not be
+ // able to service mails until this call is made.
+ closeProcessorLists();
+ }
+
+ /**
+ * @see org.apache.avalon.framework.service.Serviceable#service(ServiceManager)
+ */
+ public void service(ServiceManager comp) throws ServiceException {
+ compMgr = comp;
+ mailetLoader = (MailetLoader) compMgr.lookup(MailetLoader.ROLE);
+ matchLoader = (MatcherLoader) compMgr.lookup(MatcherLoader.ROLE);
+ spool = (SpoolRepository) compMgr.lookup(SpoolRepository.ROLE);
+ setSpool(spool);
}
}
Modified: james/server/trunk/src/test/org/apache/james/transport/LinearProcessorTest.java
URL: http://svn.apache.org/viewcvs/james/server/trunk/src/test/org/apache/james/transport/LinearProcessorTest.java?rev=405882&r1=405881&r2=405882&view=diff
==============================================================================
--- james/server/trunk/src/test/org/apache/james/transport/LinearProcessorTest.java (original)
+++ james/server/trunk/src/test/org/apache/james/transport/LinearProcessorTest.java Fri May 12 14:30:04 2006
@@ -147,6 +147,7 @@
changeBody.init(mockMailetConfig);
checkerMailet = new CheckerMailet();
+ t.openProcessorList();
t.add(recipientIs,changeBody);
t.add(all,changeBody);
t.add(all,dumpSystemErr);
@@ -189,6 +190,7 @@
Mailet dumpSystemErr = new DumpSystemErr();
checkerMailet = new CheckerMailet();
+ t.openProcessorList();
t.add(recipientIs,dumpSystemErr);
t.add(all,dumpSystemErr);
t.add(all,checkerMailet);
@@ -219,8 +221,6 @@
t = new LinearProcessor();
Logger l = new ConsoleLogger();
ContainerUtil.enableLogging(t, l);
- ContainerUtil.initialize(t);
-
}
public void tearDown() throws Exception {
---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org