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

NewMsgsWorker

public class NewMsgsWorker extends Object implements javax.resource.spi.work.Work, javax.resource.spi.work.WorkListener
author
Scott.Stark@jboss.org
version
$Revision: 57189 $

Fields Summary
private static Logger
log
private boolean
released
private javax.resource.spi.work.WorkManager
mgr
private EDU.oswego.cs.dl.util.concurrent.BoundedPriorityQueue
pollQueue
private boolean
trace
Constructors Summary
public NewMsgsWorker(javax.resource.spi.work.WorkManager mgr)


     
   
      this.mgr = mgr;
      // The capacity needs to be externalized
      this.pollQueue = new BoundedPriorityQueue(1024);
      this.trace = log.isTraceEnabled();
   
Methods Summary
public voidrelease()

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

      if( trace )
         log.trace("Begin run");
      while( released == false )
      {
         try
         {
            MailActivation ma = (MailActivation) pollQueue.take();
            if( ma.isReleased() )
               continue;
            // Wait until its time to check for new msgs
            long now = System.currentTimeMillis();
            long nextTime = ma.getNextNewMsgCheckTime();
            long sleepMS = nextTime - now;
            Thread.sleep(sleepMS);
            if( released )
               break;

            // Now schedule excecution of the new msg check
            mgr.scheduleWork(ma, WorkManager.INDEFINITE, null, this);
         }
         catch(InterruptedException e)
         {
            log.warn("Interrupted waiting for new msg check", e);
         }
         catch (WorkException e)
         {
            log.warn("Failed to schedule new msg check", e);            
         }
      }
      if( trace )
         log.trace("End run");
   
public voidwatch(MailActivation activation)

      long now = System.currentTimeMillis();
      activation.updateNextNewMsgCheckTime(now);
      pollQueue.put(activation);
   
public voidworkAccepted(javax.resource.spi.work.WorkEvent e)

      if( trace )
         log.trace("workAccepted, e="+e);
   
public voidworkCompleted(javax.resource.spi.work.WorkEvent e)

      if( trace )
         log.trace("workCompleted, e="+e);
      MailActivation activation = (MailActivation) e.getWork();
      try
      {
         watch(activation);
      }
      catch(InterruptedException ex)
      {
         log.warn("Failed to reschedule new msg check", ex);
      }
   
public voidworkRejected(javax.resource.spi.work.WorkEvent e)

      if( trace )
         log.trace("workRejected, e="+e);
   
public voidworkStarted(javax.resource.spi.work.WorkEvent e)

      if( trace )
         log.trace("workStarted, e="+e);