org.apache.james.queue.jms
Class JMSMailQueue

java.lang.Object
  extended by org.apache.james.queue.jms.JMSMailQueue
All Implemented Interfaces:
MailPrioritySupport, MailQueue, ManageableMailQueue, JMSSupport

public class JMSMailQueue
extends Object
implements ManageableMailQueue, JMSSupport, MailPrioritySupport

MailQueue implementation which use a JMS Queue for the
MailQueue. This implementation should work with every JMS 1.1.0 implementation

It use ObjectMessage with a byte array as payload to store the Mail objects.


Nested Class Summary
 
Nested classes/interfaces inherited from interface org.apache.james.queue.api.ManageableMailQueue
ManageableMailQueue.MailQueueItemView, ManageableMailQueue.MailQueueIterator, ManageableMailQueue.Type
 
Nested classes/interfaces inherited from interface org.apache.james.queue.api.MailQueue
MailQueue.MailQueueException, MailQueue.MailQueueItem
 
Field Summary
protected  javax.jms.ConnectionFactory connectionFactory
           
static String FORCE_DELIVERY
           
protected  org.slf4j.Logger logger
           
protected  String queuename
           
 
Fields inherited from interface org.apache.james.queue.api.MailQueue
NO_DELAY
 
Fields inherited from interface org.apache.james.queue.jms.JMSSupport
JAMES_MAIL_ATTRIBUTE_NAMES, JAMES_MAIL_ERROR_MESSAGE, JAMES_MAIL_LAST_UPDATED, JAMES_MAIL_MESSAGE_SIZE, JAMES_MAIL_NAME, JAMES_MAIL_RECIPIENTS, JAMES_MAIL_REMOTEADDR, JAMES_MAIL_REMOTEHOST, JAMES_MAIL_SENDER, JAMES_MAIL_SEPARATOR, JAMES_MAIL_STATE, JAMES_NEXT_DELIVERY
 
Fields inherited from interface org.apache.james.queue.api.MailPrioritySupport
HIGH_PRIORITY, LOW_PRIORITY, MAIL_PRIORITY, NORMAL_PRIORITY
 
Constructor Summary
JMSMailQueue(javax.jms.ConnectionFactory connectionFactory, String queuename, org.slf4j.Logger logger)
           
 
Method Summary
 ManageableMailQueue.MailQueueIterator browse()
           
 long clear()
           
protected  Object convertAttributeValue(Object value)
          Convert the attribute value if necessary.
protected  javax.jms.Message copy(javax.jms.Session session, javax.jms.Message m)
          Create a copy of the given Message.
protected  long count(List<javax.jms.Message> msgs)
           
protected  org.apache.mailet.Mail createMail(javax.jms.Message message)
          Create the complete Mail from the JMS Message.
protected  MailQueue.MailQueueItem createMailQueueItem(javax.jms.Connection connection, javax.jms.Session session, javax.jms.MessageConsumer consumer, javax.jms.Message message)
          Create a MailQueueItem for the given parameters
 MailQueue.MailQueueItem deQueue()
           Execute the given DequeueOperation when a mail is ready to process.
 void enQueue(org.apache.mailet.Mail mail)
           
 void enQueue(org.apache.mailet.Mail mail, long delay, TimeUnit unit)
           
 long flush()
           
protected  Map<String,Object> getJMSProperties(org.apache.mailet.Mail mail, long delayInMillis)
          Get JMS Message properties with values
protected  String getMessageSelector()
           
 long getSize()
           
protected  void populateMail(javax.jms.Message message, MailImpl mail)
          Populate Mail with values from Message.
protected  void populateMailMimeMessage(javax.jms.Message message, org.apache.mailet.Mail mail)
          Populat the given Mail instance with a MimeMessage.
protected  void produceMail(javax.jms.Session session, Map<String,Object> props, int msgPrio, org.apache.mailet.Mail mail)
          Produce the mail to the JMS Queue
 long remove(ManageableMailQueue.Type type, String value)
           
 List<javax.jms.Message> removeWithSelector(String selector)
          Remove messages with the given selector
 String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

queuename

protected final String queuename

connectionFactory

protected final javax.jms.ConnectionFactory connectionFactory

logger

protected final org.slf4j.Logger logger

FORCE_DELIVERY

public static final String FORCE_DELIVERY
See Also:
Constant Field Values
Constructor Detail

JMSMailQueue

public JMSMailQueue(javax.jms.ConnectionFactory connectionFactory,
                    String queuename,
                    org.slf4j.Logger logger)
Method Detail

deQueue

public MailQueue.MailQueueItem deQueue()
                                throws MailQueue.MailQueueException

Execute the given DequeueOperation when a mail is ready to process. As JMS does not support delay scheduling out-of-the box, we use a messageselector to check if a mail is ready. For this a {@link MessageConsumer#receive(long) is used with a timeout of 10 seconds.

Many JMS implementations support better solutions for this, so this should get overridden by these implementations

Specified by:
deQueue in interface MailQueue
Throws:
MailQueue.MailQueueException

enQueue

public void enQueue(org.apache.mailet.Mail mail,
                    long delay,
                    TimeUnit unit)
             throws MailQueue.MailQueueException
Specified by:
enQueue in interface MailQueue
Throws:
MailQueue.MailQueueException

enQueue

public void enQueue(org.apache.mailet.Mail mail)
             throws MailQueue.MailQueueException
Specified by:
enQueue in interface MailQueue
Throws:
MailQueue.MailQueueException

produceMail

protected void produceMail(javax.jms.Session session,
                           Map<String,Object> props,
                           int msgPrio,
                           org.apache.mailet.Mail mail)
                    throws javax.jms.JMSException,
                           javax.mail.MessagingException,
                           IOException
Produce the mail to the JMS Queue

Throws:
javax.jms.JMSException
javax.mail.MessagingException
IOException

getJMSProperties

protected Map<String,Object> getJMSProperties(org.apache.mailet.Mail mail,
                                              long delayInMillis)
                                       throws javax.jms.JMSException,
                                              javax.mail.MessagingException
Get JMS Message properties with values

Parameters:
message -
mail -
delayInMillis -
Throws:
javax.jms.JMSException
javax.mail.MessagingException

createMail

protected final org.apache.mailet.Mail createMail(javax.jms.Message message)
                                           throws javax.mail.MessagingException,
                                                  javax.jms.JMSException
Create the complete Mail from the JMS Message. So the created Mail is completly populated

Parameters:
message -
Returns:
Throws:
javax.mail.MessagingException
javax.jms.JMSException

populateMailMimeMessage

protected void populateMailMimeMessage(javax.jms.Message message,
                                       org.apache.mailet.Mail mail)
                                throws javax.mail.MessagingException,
                                       javax.jms.JMSException
Populat the given Mail instance with a MimeMessage. The MimeMessage is read from the JMS Message. This implementation use a BytesMessage

Parameters:
message -
mail -
Throws:
javax.mail.MessagingException
javax.jms.JMSException

populateMail

protected void populateMail(javax.jms.Message message,
                            MailImpl mail)
                     throws javax.jms.JMSException
Populate Mail with values from Message. This exclude the MimeMessage

Parameters:
message -
mail -
Throws:
javax.jms.JMSException

convertAttributeValue

protected Object convertAttributeValue(Object value)
Convert the attribute value if necessary.

Parameters:
value -
Returns:
convertedValue

toString

public String toString()
Overrides:
toString in class Object

createMailQueueItem

protected MailQueue.MailQueueItem createMailQueueItem(javax.jms.Connection connection,
                                                      javax.jms.Session session,
                                                      javax.jms.MessageConsumer consumer,
                                                      javax.jms.Message message)
                                               throws javax.jms.JMSException,
                                                      javax.mail.MessagingException
Create a MailQueueItem for the given parameters

Parameters:
connection -
session -
consumer -
message -
Returns:
item
Throws:
javax.jms.JMSException
javax.mail.MessagingException

getMessageSelector

protected String getMessageSelector()

getSize

public long getSize()
             throws MailQueue.MailQueueException
Specified by:
getSize in interface ManageableMailQueue
Throws:
MailQueue.MailQueueException

flush

public long flush()
           throws MailQueue.MailQueueException
Specified by:
flush in interface ManageableMailQueue
Throws:
MailQueue.MailQueueException

clear

public long clear()
           throws MailQueue.MailQueueException
Specified by:
clear in interface ManageableMailQueue
Throws:
MailQueue.MailQueueException

count

protected long count(List<javax.jms.Message> msgs)

removeWithSelector

public List<javax.jms.Message> removeWithSelector(String selector)
                                           throws MailQueue.MailQueueException
Remove messages with the given selector

Parameters:
selector -
Returns:
messages
Throws:
MailQueue.MailQueueException

copy

protected javax.jms.Message copy(javax.jms.Session session,
                                 javax.jms.Message m)
                          throws javax.jms.JMSException
Create a copy of the given Message. This includes the properties and the payload

Parameters:
session -
m -
Returns:
copy
Throws:
javax.jms.JMSException

remove

public long remove(ManageableMailQueue.Type type,
                   String value)
            throws MailQueue.MailQueueException
Specified by:
remove in interface ManageableMailQueue
Throws:
MailQueue.MailQueueException

browse

public ManageableMailQueue.MailQueueIterator browse()
                                             throws MailQueue.MailQueueException
Specified by:
browse in interface ManageableMailQueue
Throws:
MailQueue.MailQueueException


Copyright © 2002-2011 The Apache Software Foundation. All Rights Reserved.