Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Merge all static functions in Aspirin class, and get configuration fr…

…om this instead using Configuration.getInstance.
  • Loading branch information...
commit 878a4e9b931a35f1a132a9ca822d20a83069b2ae 1 parent 91611aa
@lsolova lsolova authored
View
41 src/main/java/org/apache/james/core/MailImpl.java
@@ -60,10 +60,17 @@
//import org.apache.avalon.framework.activity.Disposable;
-import org.apache.james.util.RFC2822Headers;
-import org.apache.mailet.Mail;
-import org.apache.mailet.MailAddress;
-import org.masukomi.aspirin.core.Configuration;
+import java.io.BufferedReader;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.io.OutputStream;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Date;
+import java.util.Enumeration;
+import java.util.HashSet;
+import java.util.Iterator;
import javax.mail.Address;
import javax.mail.Message;
@@ -71,13 +78,11 @@
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeMessage;
import javax.mail.internet.ParseException;
-import java.io.*;
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.Date;
-import java.util.Enumeration;
-import java.util.HashSet;
-import java.util.Iterator;
+
+import org.apache.james.util.RFC2822Headers;
+import org.apache.mailet.Mail;
+import org.apache.mailet.MailAddress;
+import org.masukomi.aspirin.core.Aspirin;
/**
* Wraps a MimeMessage adding routing information (from SMTP) and some simple
@@ -307,7 +312,7 @@ public String getErrorMessage() {
* @return the MimeMessage associated with this MailImpl
*/
public MimeMessage getMessage() throws MessagingException {
- MimeMessage mMsg = Configuration.getInstance().getMailStore().get(this.name);
+ MimeMessage mMsg = Aspirin.getConfiguration().getMailStore().get(this.name);
if( mMsg == null )
throw new MessagingException("No message found for this mail: "+this.name);
return mMsg;
@@ -326,14 +331,14 @@ public void setName(String name) {
if( oldName != null )
{
try {
- MimeMessage mMsg = Configuration.getInstance().getMailStore().get(oldName);
+ MimeMessage mMsg = Aspirin.getConfiguration().getMailStore().get(oldName);
if( mMsg != null )
{
- Configuration.getInstance().getMailStore().remove(oldName);
- Configuration.getInstance().getMailStore().set(this.name, mMsg);
+ Aspirin.getConfiguration().getMailStore().remove(oldName);
+ Aspirin.getConfiguration().getMailStore().set(this.name, mMsg);
}
} catch (Exception e) {
- Configuration.getInstance().getLog().error("Could not change message object in mail store."+oldName+"/"+this.name);
+ Aspirin.getConfiguration().getLog().error("Could not change message object in mail store."+oldName+"/"+this.name);
}
}
@@ -454,7 +459,7 @@ public void setErrorMessage(String msg) {
* the new MimeMessage associated with this MailImpl
*/
public void setMessage(MimeMessage message) {
- Configuration.getInstance().getMailStore().set(this.name, message);
+ Aspirin.getConfiguration().getMailStore().set(this.name, message);
// this.message = message;
}
@@ -682,7 +687,7 @@ public void dispose() {
}
public void release() {
- Configuration.getInstance().getMailStore().remove(this.name);
+ Aspirin.getConfiguration().getMailStore().remove(this.name);
}
}
View
147 src/main/java/org/masukomi/aspirin/core/Aspirin.java
@@ -1,18 +1,26 @@
package org.masukomi.aspirin.core;
import java.text.SimpleDateFormat;
+import java.util.ArrayList;
+import java.util.Collection;
import java.util.Date;
+import javax.mail.Address;
+import javax.mail.Message;
import javax.mail.MessagingException;
import javax.mail.Session;
+import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeMessage;
+import javax.mail.internet.MimeMessage.RecipientType;
-import org.masukomi.aspirin.core.queue.AbstractQueueInfo;
-import org.masukomi.aspirin.core.queue.QueueStore;
-import org.masukomi.aspirin.core.queue.SimpleQueueStore;
-import org.masukomi.aspirin.core.store.FileMailStore;
-import org.masukomi.aspirin.core.store.MailStore;
-import org.masukomi.aspirin.core.store.SimpleMailStore;
+import org.masukomi.aspirin.core.delivery.DeliveryManager;
+import org.masukomi.aspirin.core.listener.ListenerManager;
+import org.masukomi.aspirin.core.store.mail.FileMailStore;
+import org.masukomi.aspirin.core.store.mail.MailStore;
+import org.masukomi.aspirin.core.store.mail.SimpleMailStore;
+import org.masukomi.aspirin.core.store.queue.QueueInfo;
+import org.masukomi.aspirin.core.store.queue.QueueStore;
+import org.masukomi.aspirin.core.store.queue.SimpleQueueStore;
/**
* This is the facade class of the Aspirin package. You should to use this
@@ -29,7 +37,7 @@
* stores all MimeMessage objects on filesystem.) If no one of these default
* stores is good for you, you can implement the MailStore interface.</p>
*
- * <p>A QueueInfo {@link AbstractQueueInfo}, which represents an email and a
+ * <p>A QueueInfo {@link QueueInfo}, which represents an email and a
* recipient together, so one email could associated to more QueueInfo objects.
* This is an inside object, which contains all control informations of a mail
* item. In Aspirin package there is a {@link QueueStore} for in-memory use
@@ -69,10 +77,16 @@
/** This session is used to generate new MimeMessage objects. */
private static Session defaultSession = null;
+
/** This counter is used to generate unique message ids. */
private static Integer idCounter = 0;
- /** This is the configuration object of Aspirin. */
+
+ /** Configuration object of Aspirin. */
private static Configuration configuration = new Configuration();
+ /** AspirinListener management object. Create on first request. */
+ private static ListenerManager listenerManager = null;
+ /** Delivery and QoS service management. Create on first request. */
+ private static DeliveryManager deliveryManager = new DeliveryManager();
/**
* You can get configuration object, which could be changed to set up new
@@ -85,12 +99,53 @@ public static Configuration getConfiguration() {
return configuration;
}
- // TODO
- public static void add(MimeMessage msg) {}
- // TODO
- public static void add(MimeMessage msg, long expire) {}
- // TODO
- public static void addListener(AspirinListener listener) {}
+ /**
+ * Add MimeMessage to deliver it.
+ * @param msg MimeMessage to deliver.
+ * @throws MessagingException If delivery add failed.
+ */
+ public static void add(MimeMessage msg) throws MessagingException {
+ deliveryManager.add(msg);
+ }
+
+ /**
+ * Add MimeMessage to delivery.
+ * @param msg MimeMessage
+ * @param expiry Expiration of this email in milliseconds from now.
+ * @throws MessagingException If delivery add failed.
+ */
+ public static void add(MimeMessage msg, long expiry) throws MessagingException {
+ setExpiry(msg, expiry);
+ add(msg);
+ }
+
+ /**
+ * Add mail delivery status listener.
+ * @param listener AspirinListener object
+ */
+ public static void addListener(AspirinListener listener) {
+ if( listenerManager == null )
+ listenerManager = new ListenerManager();
+ listenerManager.add(listener);
+ }
+
+ /**
+ * Remove an email from delivery.
+ * @param mailid Unique Aspirin ID of this email.
+ * @throws MessagingException If removing failed.
+ */
+ public static void remove(String mailid) throws MessagingException {
+ deliveryManager.remove(mailid);
+ }
+
+ /**
+ * Remove delivery status listener.
+ * @param listener AspirinListener
+ */
+ public static void removeListener(AspirinListener listener) {
+ if( listenerManager != null )
+ listenerManager.remove(listener);
+ }
/**
* It creates a new MimeMessage with standard Aspirin ID header.
@@ -107,20 +162,51 @@ public static MimeMessage createNewMimeMessage() {
String newId = nowTime+"."+Integer.toHexString(idCounter++);
try {
mMesg.setHeader(Aspirin.HEADER_MAIL_ID, newId);
-// Expiry set is not used - user should set it explicitly
-// mMesg.setHeader(Aspirin.HEADER_EXPIRY, expiryFormat.format(
-// (0 < configuration.getExpiry())
-// ? new Date(System.currentTimeMillis()+configuration.getExpiry()) // Default +expiry
-// : new Date(System.currentTimeMillis()+8640000000L) // Default +100 days
-// ));
} catch (MessagingException msge) {
- Configuration.getInstance().getLog().warn("Aspirin Mail ID could not be generated.", msge);
+ configuration.getLog().warn("Aspirin Mail ID could not be generated.", msge);
msge.printStackTrace();
}
}
return mMesg;
}
+ public static Collection<InternetAddress> extractRecipients(MimeMessage message) throws MessagingException {
+ Collection<InternetAddress> recipients = new ArrayList<InternetAddress>();
+
+ Address[] addresses;
+ Message.RecipientType[] types = new Message.RecipientType[]{
+ RecipientType.TO,
+ RecipientType.CC,
+ RecipientType.BCC
+ };
+ for( Message.RecipientType recType : types )
+ {
+ addresses = message.getRecipients(recType);
+ if (addresses != null)
+ {
+ for (Address addr : addresses)
+ {
+ try {
+ recipients.add((InternetAddress)addr);
+ } catch (Exception e) {
+ configuration.getLog().warn("Recipient parsing failed.", e);
+ }
+ }
+ }
+ }
+ return recipients;
+ }
+
+ /**
+ * Format expiry header content.
+ * @param date Expiry date of a message.
+ * @return Formatted date of expiry - as String. It could be add as
+ * MimeMessage header. Please use HEADER_EXPIRY constant as header name.
+ */
+ public static String formatExpiry(Date date) {
+ return expiryFormat.format(date);
+ }
+
/**
* Decode mail ID from MimeMessage. If no such header was defined, then we
* get MimeMessage's toString() method result back.
@@ -140,7 +226,13 @@ public static String getMailID(MimeMessage message) {
return message.toString();
}
+ /**
+ * It gives back expiry value of a message in epoch milliseconds.
+ * @param message The MimeMessage which expiry is needed.
+ * @return Expiry in milliseconds.
+ */
public static long getExpiry(MimeMessage message) {
+ // FIXME
String headers[];
try {
headers = message.getHeader(Aspirin.HEADER_EXPIRY);
@@ -161,13 +253,12 @@ public static long getExpiry(MimeMessage message) {
return System.currentTimeMillis()+configuration.getExpiry();
}
- public static String formatExpiry(Date date) {
- return expiryFormat.format(date);
+ public static void setExpiry(MimeMessage message, long expiry) {
+ try {
+ message.setHeader(Aspirin.HEADER_EXPIRY, expiryFormat.format(new Date(System.currentTimeMillis()+expiry)));
+ } catch (MessagingException e) {
+ configuration.getLog().error("Could not set Expiry of the MimeMessage: "+getMailID(message), e);
+ }
}
-
- //TODO
- public static void remove(String mailid) {}
- //TODO
- public static void removeListener(AspirinListener listener) {}
}
View
4 src/main/java/org/masukomi/aspirin/core/Bouncer.java
@@ -47,7 +47,7 @@
* Comments
*/
public class Bouncer {
- static private Log log = Configuration.getInstance().getLog();
+ static private Log log = Aspirin.getConfiguration().getLog();
/** An RFC822 date formatter used to format dates in mail headers */
private static RFC822DateFormat rfc822DateFormat = new RFC822DateFormat();
/**
@@ -69,7 +69,7 @@
static public void bounce(MailQue que, Mail mail, String message, MailAddress bouncer)
throws MessagingException {
- if ( !Configuration.getInstance().isDeliveryBounceOnFailure() )
+ if ( !Aspirin.getConfiguration().isDeliveryBounceOnFailure() )
return;
if (bouncer != null) {
View
8 src/main/java/org/masukomi/aspirin/core/GenericPoolableRemoteDeliveryFactory.java
@@ -46,13 +46,13 @@ public Object makeObject() throws Exception {
rd.setName(RemoteDelivery.class.getSimpleName()+"-"+rdCount);
}
rd.setParentPool(myParentPool);
- Configuration.getInstance().getLog().trace(getClass().getSimpleName()+".makeObject(): New RemoteDelivery object created: "+rd.getName());
+ Aspirin.getConfiguration().getLog().trace(getClass().getSimpleName()+".makeObject(): New RemoteDelivery object created: "+rd.getName());
/*
* This will be started after first borrow of this object, because the
* first item to process will be set after first borrow too.
*/
// rd.start();
- Configuration.getInstance().addListener(rd);
+ Aspirin.getConfiguration().addListener(rd);
return rd;
}
@@ -61,9 +61,9 @@ public void destroyObject(Object obj) throws Exception {
if( obj instanceof RemoteDelivery )
{
RemoteDelivery rd = (RemoteDelivery)obj;
- Configuration.getInstance().getLog().trace(getClass().getSimpleName()+".destroyObject(): destroy thread "+rd.getName());
+ Aspirin.getConfiguration().getLog().trace(getClass().getSimpleName()+".destroyObject(): destroy thread "+rd.getName());
rd.shutdown();
- Configuration.getInstance().removeListener(rd);
+ Aspirin.getConfiguration().removeListener(rd);
}
}
View
2  src/main/java/org/masukomi/aspirin/core/MailQue.java
@@ -47,7 +47,7 @@
*
*/
public class MailQue implements MailQueMBean {
- private Log log = Configuration.getInstance().getLog();
+ private Log log = Aspirin.getConfiguration().getLog();
protected QueManager qm;
protected Vector<QuedItem> que;
protected Vector<AspirinListener> listeners;
View
14 src/main/java/org/masukomi/aspirin/core/QueManager.java
@@ -50,7 +50,7 @@
private ObjectPool remoteDeliveryObjectPool = null;
protected MailQue que;
- static private Log log = Configuration.getInstance().getLog();
+ static private Log log = Aspirin.getConfiguration().getLog();
protected boolean pauseNewSends = false;
/**
@@ -66,8 +66,8 @@ public QueManager(MailQue que) {
// Configure pool of RemoteDelivery threads
GenericObjectPool.Config gopConf = new GenericObjectPool.Config();
gopConf.lifo = false;
- gopConf.maxActive = Configuration.getInstance().getDeliveryThreadsActiveMax();
- gopConf.maxIdle = Configuration.getInstance().getDeliveryThreadsIdleMax();
+ gopConf.maxActive = Aspirin.getConfiguration().getDeliveryThreadsActiveMax();
+ gopConf.maxIdle = Aspirin.getConfiguration().getDeliveryThreadsIdleMax();
gopConf.maxWait = 5000;
gopConf.testOnReturn = true;
gopConf.whenExhaustedAction = GenericObjectPool.WHEN_EXHAUSTED_BLOCK;
@@ -87,7 +87,7 @@ public QueManager(MailQue que) {
remoteDeliveryObjectPool
);
- Configuration.getInstance().addListener(this);
+ Aspirin.getConfiguration().addListener(this);
}
@@ -233,17 +233,17 @@ public synchronized void notifyWithMail() {
public void configChanged(String parameterName) {
if( ConfigurationMBean.PARAM_DELIVERY_THREADS_ACTIVE_MAX.equals(parameterName) )
{
- ((GenericObjectPool)remoteDeliveryObjectPool).setMaxActive(Configuration.getInstance().getDeliveryThreadsActiveMax());
+ ((GenericObjectPool)remoteDeliveryObjectPool).setMaxActive(Aspirin.getConfiguration().getDeliveryThreadsActiveMax());
}else
if( ConfigurationMBean.PARAM_DELIVERY_THREADS_IDLE_MAX.equals(parameterName) )
{
- ((GenericObjectPool)remoteDeliveryObjectPool).setMaxIdle(Configuration.getInstance().getDeliveryThreadsIdleMax());
+ ((GenericObjectPool)remoteDeliveryObjectPool).setMaxIdle(Aspirin.getConfiguration().getDeliveryThreadsIdleMax());
}
}
@Override
protected void finalize() throws Throwable {
- Configuration.getInstance().removeListener(this);
+ Aspirin.getConfiguration().removeListener(this);
super.finalize();
}
View
10 src/main/java/org/masukomi/aspirin/core/QuedItem.java
@@ -40,7 +40,7 @@
*
*/
public class QuedItem implements Comparable<QuedItem> {
- static private Log log = Configuration.getInstance().getLog();
+ static private Log log = Aspirin.getConfiguration().getLog();
/** A Collection of MailWatchers */
//protected Collection watchers;
/** The mail to be sent */
@@ -132,7 +132,7 @@ public void failForRecipient(MailQue que, MailAddress recipient, MessagingExcept
recipientFailures = new HashMap<MailAddress, Integer>();
}
recipientFailures.put(recipient,
- new Integer(Configuration.getInstance().getDeliveryAttemptCount()));
+ new Integer(Aspirin.getConfiguration().getDeliveryAttemptCount()));
// tell anyone who cares
if (que.getListeners() != null) {
que.incrementNotifiersCount();
@@ -172,7 +172,7 @@ public void retry(MailQue que, MailAddress recipient) {
recipientFailures.put(recipient, new Integer(1));
}
- nextAttempt = System.currentTimeMillis() + Configuration.getInstance().getDeliveryAttemptDelay();
+ nextAttempt = System.currentTimeMillis() + Aspirin.getConfiguration().getDeliveryAttemptDelay();
// It will be released after processing
// release();
// setStatus(QuedItem.IN_QUE);
@@ -184,7 +184,7 @@ public void retry(MailQue que, MailAddress recipient) {
try {
failForRecipient(que, recipient, null);
Bouncer.bounce(que, getMail(), "Maxumum retries exceeded for " +recipient,
- Configuration.getInstance().getPostmaster());
+ Aspirin.getConfiguration().getPostmaster());
} catch (MessagingException e) {
log.error(getClass().getSimpleName()+".retry(): ",e);
}
@@ -222,7 +222,7 @@ public boolean retryable(MailAddress recipient) {
}
if (recipientFailures.containsKey(recipient)) {
Integer numFailures = (Integer) recipientFailures.get(recipient);
- if ((numFailures.intValue() + 1) < Configuration.getInstance()
+ if ((numFailures.intValue() + 1) < Aspirin.getConfiguration()
.getDeliveryAttemptCount()) {
return true;
}
View
28 src/main/java/org/masukomi/aspirin/core/RemoteDelivery.java
@@ -103,7 +103,7 @@
private static final String MAIL_SMTP_LOCALHOST = "mail.smtp.localhost";
private static final String MAIL_SMTP_TIMEOUT = "mail.smtp.timeout";
- static private Log log = Configuration.getInstance().getLog();
+ static private Log log = Aspirin.getConfiguration().getLog();
protected QuedItem qi;
protected MailQue que;
@@ -116,14 +116,14 @@ public RemoteDelivery(ThreadGroup parentThreadGroup) {
// Set up default session
Properties mailSessionProps = System.getProperties();
- mailSessionProps.put(MAIL_SMTP_HOST, Configuration.getInstance().getHostname()); //The SMTP server to connect to.
- mailSessionProps.put(MAIL_SMTP_LOCALHOST, Configuration.getInstance().getHostname()); //Local host name. Defaults to InetAddress.getLocalHost().getHostName(). Should not normally need to be set if your JDK and your name service are configured properly.
- mailSessionProps.put(MAIL_MIME_CHARSET, Configuration.getInstance().getEncoding()); //The mail.mime.charset System property can be used to specify the default MIME charset to use for encoded words and text parts that don't otherwise specify a charset. Normally, the default MIME charset is derived from the default Java charset, as specified in the file.encoding System property. Most applications will have no need to explicitly set the default MIME charset. In cases where the default MIME charset to be used for mail messages is different than the charset used for files stored on the system, this property should be set.
- mailSessionProps.put(MAIL_SMTP_CONNECTIONTIMEOUT, Configuration.getInstance().getDeliveryTimeout()); //Socket connection timeout value in milliseconds. Default is infinite timeout.
- mailSessionProps.put(MAIL_SMTP_TIMEOUT, Configuration.getInstance().getDeliveryTimeout()); //Socket I/O timeout value in milliseconds. Default is infinite timeout.
+ mailSessionProps.put(MAIL_SMTP_HOST, Aspirin.getConfiguration().getHostname()); //The SMTP server to connect to.
+ mailSessionProps.put(MAIL_SMTP_LOCALHOST, Aspirin.getConfiguration().getHostname()); //Local host name. Defaults to InetAddress.getLocalHost().getHostName(). Should not normally need to be set if your JDK and your name service are configured properly.
+ mailSessionProps.put(MAIL_MIME_CHARSET, Aspirin.getConfiguration().getEncoding()); //The mail.mime.charset System property can be used to specify the default MIME charset to use for encoded words and text parts that don't otherwise specify a charset. Normally, the default MIME charset is derived from the default Java charset, as specified in the file.encoding System property. Most applications will have no need to explicitly set the default MIME charset. In cases where the default MIME charset to be used for mail messages is different than the charset used for files stored on the system, this property should be set.
+ mailSessionProps.put(MAIL_SMTP_CONNECTIONTIMEOUT, Aspirin.getConfiguration().getDeliveryTimeout()); //Socket connection timeout value in milliseconds. Default is infinite timeout.
+ mailSessionProps.put(MAIL_SMTP_TIMEOUT, Aspirin.getConfiguration().getDeliveryTimeout()); //Socket I/O timeout value in milliseconds. Default is infinite timeout.
mailSession = Session.getInstance(mailSessionProps);
// Set communication debug
- if( log.isDebugEnabled() && Configuration.getInstance().isDeliveryDebug() )
+ if( log.isDebugEnabled() && Aspirin.getConfiguration().isDeliveryDebug() )
mailSession.setDebug(true);
}
@@ -573,7 +573,7 @@ private boolean failMessage(QuedItem qi, MailAddress recepient,
}
try
{
- Bouncer.bounce(que, mail, ex.toString(), Configuration.getInstance().getPostmaster());
+ Bouncer.bounce(que, mail, ex.toString(), Aspirin.getConfiguration().getPostmaster());
}catch (MessagingException me)
{
log.error(getClass().getSimpleName()+" ("+getName()+").failMessage(): failed to bounce",me);
@@ -823,25 +823,25 @@ public void configChanged(String parameterName) {
if( ConfigurationMBean.PARAM_DELIVERY_TIMEOUT.equals(parameterName) )
{
Properties sessProps = mailSession.getProperties();
- sessProps.setProperty(MAIL_SMTP_CONNECTIONTIMEOUT, String.valueOf(Configuration.getInstance().getDeliveryTimeout()));
- sessProps.setProperty(MAIL_SMTP_TIMEOUT, String.valueOf(Configuration.getInstance().getDeliveryTimeout()));
+ sessProps.setProperty(MAIL_SMTP_CONNECTIONTIMEOUT, String.valueOf(Aspirin.getConfiguration().getDeliveryTimeout()));
+ sessProps.setProperty(MAIL_SMTP_TIMEOUT, String.valueOf(Aspirin.getConfiguration().getDeliveryTimeout()));
}else
if( ConfigurationMBean.PARAM_ENCODING.equals(parameterName) )
{
Properties sessProps = mailSession.getProperties();
- sessProps.setProperty(MAIL_MIME_CHARSET, Configuration.getInstance().getEncoding());
+ sessProps.setProperty(MAIL_MIME_CHARSET, Aspirin.getConfiguration().getEncoding());
}else
if( ConfigurationMBean.PARAM_HOSTNAME.equals(parameterName) )
{
Properties sessProps = mailSession.getProperties();
- sessProps.setProperty(MAIL_SMTP_HOST, Configuration.getInstance().getHostname());
- sessProps.setProperty(MAIL_SMTP_LOCALHOST, Configuration.getInstance().getHostname());
+ sessProps.setProperty(MAIL_SMTP_HOST, Aspirin.getConfiguration().getHostname());
+ sessProps.setProperty(MAIL_SMTP_LOCALHOST, Aspirin.getConfiguration().getHostname());
}else
if( ConfigurationMBean.PARAM_DELIVERY_DEBUG.equals(parameterName) )
{
mailSession.setDebug(
log.isDebugEnabled() &&
- Configuration.getInstance().isDeliveryDebug()
+ Aspirin.getConfiguration().isDeliveryDebug()
);
}
}
View
2  src/main/java/org/masukomi/aspirin/core/SimpleMailWatcherImpl.java
@@ -18,7 +18,7 @@
* sophisticated MailWatcher is capable of.
*/
public class SimpleMailWatcherImpl implements AspirinListener {
- static private Log log = Configuration.getInstance().getLog();
+ static private Log log = Aspirin.getConfiguration().getLog();
boolean hasSucceeded = false;
boolean hasFailed = false;
MimeMessage message;
View
12 src/main/java/org/masukomi/aspirin/core/store/mail/FileMailStore.java
@@ -14,7 +14,7 @@
import javax.mail.Session;
import javax.mail.internet.MimeMessage;
-import org.masukomi.aspirin.core.Configuration;
+import org.masukomi.aspirin.core.Aspirin;
/**
* This store implementation is designed to reduce memory
@@ -54,11 +54,11 @@ public void set(String name, MimeMessage msg) {
if( !msgFile.exists() ) { msgFile.createNewFile(); }
msg.writeTo(new FileOutputStream(msgFile));
} catch (FileNotFoundException e) {
- Configuration.getInstance().getLog().error(getClass().getSimpleName()+" No file representation found for name "+name,e);
+ Aspirin.getConfiguration().getLog().error(getClass().getSimpleName()+" No file representation found for name "+name,e);
} catch (IOException e) {
- Configuration.getInstance().getLog().error(getClass().getSimpleName()+" Could not write file for name "+name,e);
+ Aspirin.getConfiguration().getLog().error(getClass().getSimpleName()+" Could not write file for name "+name,e);
} catch (MessagingException e) {
- Configuration.getInstance().getLog().error(getClass().getSimpleName()+" There is a messaging exception with name "+name,e);
+ Aspirin.getConfiguration().getLog().error(getClass().getSimpleName()+" There is a messaging exception with name "+name,e);
}
}
@@ -75,9 +75,9 @@ public MimeMessage get(String name) {
msg = new MimeMessage(Session.getDefaultInstance(System.getProperties()),new FileInputStream(new File(messagePathMap.get(name))));
msgRef = new WeakReference<MimeMessage>(msg);
} catch (FileNotFoundException e) {
- Configuration.getInstance().getLog().error(getClass().getSimpleName()+" No file representation found for name "+name,e);
+ Aspirin.getConfiguration().getLog().error(getClass().getSimpleName()+" No file representation found for name "+name,e);
} catch (MessagingException e) {
- Configuration.getInstance().getLog().error(getClass().getSimpleName()+" There is a messaging exception with name "+name,e);
+ Aspirin.getConfiguration().getLog().error(getClass().getSimpleName()+" There is a messaging exception with name "+name,e);
}
}
}
View
4 src/test/java/org/masukomi/aspirin/core/DefunctModuleTest.java
@@ -21,7 +21,7 @@
public void testAspirin(String[] args) throws Exception {
// 1. Configure aspirin
- Configuration config = Configuration.getInstance();
+ Configuration config = Aspirin.getConfiguration();
config.setDeliveryAttemptCount(3);
config.setDeliveryAttemptDelay(5);
config.setDeliveryDebug(true);
@@ -39,7 +39,7 @@ public void testAspirin(String[] args) throws Exception {
config.setMailStore(fms);
MBeanServer mbS = ManagementFactory.getPlatformMBeanServer();
- mbS.registerMBean(Configuration.getInstance(), new ObjectName("org.masukomi.aspirin:type=Configuration"));
+ mbS.registerMBean(config, new ObjectName("org.masukomi.aspirin:type=Configuration"));
// @SuppressWarnings("unused")
// Logger logger = Logger.getLogger("MailService");
View
2  src/test/java/org/masukomi/aspirin/core/MailQueTest.java
@@ -33,7 +33,7 @@
final String testFrom = "jUnit-aspirin-test@masukomi.org";
public void testQueMail() throws Exception {
- final Configuration config = Configuration.getInstance();
+ final Configuration config = Aspirin.getConfiguration();
config.setDeliveryAttemptCount(1);
config.setPostmasterEmail("root@localhost");
View
6 src/test/java/org/masukomi/aspirin/core/TestMailWatcher.java
@@ -25,18 +25,18 @@ public TestMailWatcher() {}
* @see org.masukomi.aspirin.core.MailWatcher#deliverySuccess(javax.mail.internet.MimeMessage, org.apache.mailet.MailAddress)
*/
public void deliverySuccess(MimeMessage message, String recepient) {
- Configuration.getInstance().getLog().debug(getClass().getSimpleName()+".deliverySuccess(): recipient="+recepient+"; msg="+message);
+ Aspirin.getConfiguration().getLog().debug(getClass().getSimpleName()+".deliverySuccess(): recipient="+recepient+"; msg="+message);
}
/* (non-Javadoc)
* @see org.masukomi.aspirin.core.MailWatcher#deliveryFailure(javax.mail.internet.MimeMessage, org.apache.mailet.MailAddress)
*/
public void deliveryFailure(MimeMessage message, String recepient, MessagingException mex) {
- Configuration.getInstance().getLog().debug(getClass().getSimpleName()+".deliveryFailure(): recipient="+recepient+"; msg="+message,mex);
+ Aspirin.getConfiguration().getLog().debug(getClass().getSimpleName()+".deliveryFailure(): recipient="+recepient+"; msg="+message,mex);
}
@Override
public void deliveryFinished(MimeMessage message) {
- Configuration.getInstance().getLog().debug(getClass().getSimpleName()+".deliveryFinished(): msg="+message);
+ Aspirin.getConfiguration().getLog().debug(getClass().getSimpleName()+".deliveryFinished(): msg="+message);
}
}
Please sign in to comment.
Something went wrong with that request. Please try again.