/*
 * $Id: $
 * $URL:  $
 */

package org.subethamail.core.queue;

import javax.ejb.TransactionAttribute;
import javax.ejb.TransactionAttributeType;
import javax.inject.Inject;
import javax.jms.JMSException;
import javax.jms.Message;
import javax.jms.MessageListener;
import javax.jms.ObjectMessage;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.subethamail.common.NotFoundException;
import org.subethamail.core.deliv.i.Deliverator;

/**
 * Processes delivery queue messages by creating an actual STMP message
 * using JavaMail, relaying it through the {@link Deliverator}.
 */
//@MessageDriven	// declared in resin-web.xml
@TransactionAttribute(TransactionAttributeType.REQUIRED)
public class DeliveryListener implements MessageListener
{
	/** */
	private final static Logger log = LoggerFactory.getLogger(DeliveryListener.class);

	/** */
	@Inject Deliverator deliverator;

	/**
	 */
	public void onMessage(Message qMsg)
	{
		try
		{
			DeliveryQueueItem item = (DeliveryQueueItem)((ObjectMessage) qMsg).getObject();

			Long mailId = item.getMailId();
			Long personId = item.getPersonId();

			if (log.isDebugEnabled())
				log.debug("Delivering mailId:" + mailId + " to personId:" + personId);
			
			try
			{
				this.deliverator.deliver(mailId, personId);
			}
			catch (NotFoundException ex)
			{
				// Just log a warning and accept the JMS message
				// It possible the message/subscription has been deleted since we queued the orig request.
				if (log.isWarnEnabled())
					log.warn("Unknown mailId(" + mailId + ") or personId(" + personId + ")", ex);
			}
		}
		catch (JMSException ex)
		{
			if (log.isErrorEnabled())
				log.error("Error getting data out of message.", ex);
			
			throw new RuntimeException(ex);
		}
	}
}

/*
 * $Id: $
 * $URL:  $
 */

package org.subethamail.core.queue;

import java.util.logging.Level;
import java.util.logging.LogRecord;

import javax.ejb.TransactionAttribute;
import javax.ejb.TransactionAttributeType;
import javax.inject.Inject;
import javax.jms.JMSException;
import javax.jms.Message;
import javax.jms.MessageListener;
import javax.jms.ObjectMessage;

import lombok.extern.java.Log;

import org.subethamail.common.NotFoundException;
import org.subethamail.core.deliv.i.Deliverator;

/**
 * Processes delivery queue messages by creating an actual STMP message
 * using JavaMail, relaying it through the {@link Deliverator}.
 */
//@MessageDriven	// declared in resin-web.xml
@TransactionAttribute(TransactionAttributeType.REQUIRED)
@Log
public class DeliveryListener implements MessageListener
{
	/** */
	@Inject Deliverator deliverator;

	/**
	 */
	public void onMessage(Message qMsg)
	{
		try
		{
			DeliveryQueueItem item = (DeliveryQueueItem)((ObjectMessage) qMsg).getObject();

			Long mailId = item.getMailId();
			Long personId = item.getPersonId();

			log.log(Level.FINE,"Delivering mailId:{0} to personId:{1}", new Object[]{mailId, personId});
			
			try
			{
				this.deliverator.deliver(mailId, personId);
			}
			catch (NotFoundException ex)
			{
                // Just log a warning and accept the JMS message
				// It possible the message/subscription has been deleted since we queued the orig request.
                LogRecord logRecord=new LogRecord(Level.WARNING, "Unknown mailId({0}) or personId({1})");
                logRecord.setParameters(new Object[]{mailId, personId});
                logRecord.setThrown(ex);
				log.log(logRecord);
			}
		}
		catch (JMSException ex)
		{
				log.log(Level.SEVERE,"Error getting data out of message.", ex);
			
			throw new RuntimeException(ex);
		}
	}
}

switch logging framework