FileDocCategorySizeDatePackage
MailActivation.javaAPI DocJBoss 4.2.14829Fri Jul 13 21:01:14 BST 2007org.jboss.resource.adapter.mail.inflow

MailActivation

public class MailActivation extends Object implements Comparable, javax.resource.spi.work.Work
The MailActivation encapsulates a MailResourceAdapter#endpointActivation {@link javax.resource.spi.ResourceAdapter#endpointActivation(MessageEndpointFactory,javax.resource.spi.ActivationSpec)}
author
Scott.Stark@jboss.org
version
$Revision: 57754 $

Fields Summary
private static final Logger
log
public static final Method
ON_MESSAGE
The MailListener.onMessage method
private boolean
released
A flag indicated if the unit of work has been released
private boolean
trace
The logging trace level flag
private long
nextNewMsgCheckTime
The time at which the next new msgs check should be performed
protected org.jboss.resource.adapter.mail.MailResourceAdapter
ra
The resource adapter
protected MailActivationSpec
spec
The activation spec for the mail folder
protected javax.resource.spi.endpoint.MessageEndpointFactory
endpointFactory
The message endpoint factory
Constructors Summary
public MailActivation(org.jboss.resource.adapter.mail.MailResourceAdapter ra, javax.resource.spi.endpoint.MessageEndpointFactory endpointFactory, MailActivationSpec spec)

      this.ra = ra;
      this.endpointFactory = endpointFactory;
      this.spec = spec;
      this.trace = log.isTraceEnabled();
   
Methods Summary
public intcompareTo(java.lang.Object obj)

      MailActivation ma = (MailActivation) obj;
      long compareTo = nextNewMsgCheckTime - ma.getNextNewMsgCheckTime();
      return (int) compareTo;
   
private voiddeliverMsg(javax.mail.Message msg)

      MessageEndpoint endpoint = null;
      try
      {
         endpoint = endpointFactory.createEndpoint(null);
         if (endpoint != null)
         {
            if( trace )
               log.trace("deliverMsg, msg subject="+msg.getSubject());
            MailListener listener = (MailListener) endpoint;
            listener.onMessage(msg);
         }
      }
      catch (Throwable e)
      {
         log.debug("onMessage delivery failure", e);
      }
      finally
      {
         if (endpoint != null)
         {
            endpoint.release();
         }
      }
   
public longgetNextNewMsgCheckTime()

      return nextNewMsgCheckTime;
   
public booleanisReleased()

      return released;
   
public voidrelease()

      released = true;
      if( trace )
         log.trace("released");
   
public voidrun()

      released = false;
      if( trace )
         log.trace("Begin new msgs check");
      try
      {
         MailFolder mailFolder = new MailFolder(spec);
         mailFolder.open();
         Message[] msgs = mailFolder.getNewMessages();
         for(int n = 0; released == false && n < msgs.length; n ++)
         {
            Message msg = msgs[n];
            deliverMsg(msg);
         }
         mailFolder.close();
      }
      catch (Exception e)
      {
         log.error("Failed to execute folder check, spec="+ spec, e);
      }
      
      if( trace )
         log.trace("End new msgs check");
   
public voidupdateNextNewMsgCheckTime(long now)

      nextNewMsgCheckTime = now + spec.getPollingInterval();