package weaver.interfaces.htsc.payment.common.pdfprocess;

import com.engine.htsc.payment.log.PaymentLogger;
import com.engine.htsc.payment.log.PaymentLoggerFactory;

import java.util.List;
import java.util.concurrent.LinkedBlockingDeque;

/**
 *
 *
 * @author K1810012
 */
public class PdfConsumer implements Runnable {
  private static final PaymentLogger LOGGER = PaymentLoggerFactory.getLogger(PdfConsumer.class);
  private List<SyncPdf> data;
  private PDFBizProcessor bizProcessor;
  private LinkedBlockingDeque<Runnable> consumer;

  public PdfConsumer(PDFBizProcessor bizProcessor, LinkedBlockingDeque<Runnable> consumer) {
    this.bizProcessor = bizProcessor;
    this.consumer = consumer;
  }

  @Override
  public void run() {
    try {
      bizProcessor.handle(data);
    } catch (Exception e) {
      LOGGER.error("消费者异常===>" + e);
    } finally {
      try {
        //添加队列，队列满时阻塞
        consumer.put(this);
      } catch (InterruptedException e) {
        LOGGER.error(e);
      }
    }
  }

  public void setData(List<SyncPdf> data) {
    this.data = data;
  }

}
