POPListener.java :  » Forum » JForum-2.1.8 » net » jforum » api » integration » mail » pop » Java Open Source

Java Open Source » Forum » JForum 2.1.8 
JForum 2.1.8 » net » jforum » api » integration » mail » pop » POPListener.java
/*
 * Created on 21/08/2006 21:07:36
 */
package net.jforum.api.integration.mail.pop;

import java.util.Iterator;
import java.util.List;

import net.jforum.dao.DataAccessDriver;
import net.jforum.entities.MailIntegration;

import org.apache.log4j.Logger;
import org.quartz.Job;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;

/**
 * @author Rafael Steil
 * @version $Id: POPListener.java,v 1.9 2006/10/10 01:59:55 rafaelsteil Exp $
 */
public class POPListener implements Job
{
  private static final Logger logger = Logger.getLogger(POPListener.class);
  private static boolean working;
  protected POPConnector connector = new POPConnector();
  
  /**
   * @see org.quartz.Job#execute(org.quartz.JobExecutionContext)
   */
  public void execute(JobExecutionContext jobContext) throws JobExecutionException
  {
    if (!working) {
      try {
        working = true;

        List integrationList = DataAccessDriver.getInstance().newMailIntegrationDAO().findAll();
        POPParser parser = new POPParser();
        
        for (Iterator iter = integrationList.iterator(); iter.hasNext(); ) {
          MailIntegration integration = (MailIntegration)iter.next();
          
          connector.setMailIntegration(integration);
          
          try {
            logger.debug("Going to check " + integration);
            
            connector.openConnection();
            parser.parseMessages(connector);
            
            POPPostAction postAction = new POPPostAction();
            postAction.insertMessages(parser);
          }
          finally {
            connector.closeConnection();
          }
        }
      }
      finally {
        working = false;
      }
    }
    else {
      logger.debug("Already working. Leaving for now.");
    }
  }
  
  POPConnector getConnector()
  {
    return this.connector;
  }
}
java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.