/**
 * Copyright 2008-2009. Chongqing Communications Industry Services Co.,Ltd Information Technology Branch. All rights reserved. <a>http://www.crunii.com</a>
 */
package com.crunii.micro.platform.log.impl;

import com.crunii.micro.common.queue.FastQueue;
import com.crunii.micro.common.queue.impl.FastQueueImpl;
import com.crunii.micro.domain.entitysql.main.TOperLogS;
import com.crunii.micro.platform.log.OperLogHandler;
import com.lmax.disruptor.dsl.ProducerType;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;
import javax.annotation.PreDestroy;
import java.util.List;

/**
 * @author 田平 create 2019年5月15日下午4:58:21
 */
@Component
public class OperLogHandlerImpl implements OperLogHandler {

	@Autowired
	private OperLogFastQueueHandler operLogFastQueueHandler;

	private FastQueue<TOperLogS> fastQueue;

	@Override
	public void doOperLogs(List<TOperLogS> operLogs) {
		operLogs.forEach(log -> fastQueue.add(log));
	}

	@PostConstruct
	public void init() {
		fastQueue = new FastQueueImpl<>(1024 * 64, ProducerType.MULTI, operLogFastQueueHandler);
		fastQueue.init();
	}

	@PreDestroy
	public void destroy() {
		if (fastQueue != null) {
			fastQueue.destroy();
		}
	}
}
