/**
 * 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.gateway.queue.impl;

import com.crunii.micro.common.queue.FastQueue;
import com.crunii.micro.common.queue.impl.FastQueueImpl;
import com.crunii.micro.domain.entitysql.main.TCallLogS;
import com.crunii.micro.gateway.queue.CallLogHandler;
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;

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

	@Autowired
	private CallLogFastQueueHandler callLogFastQueueHandler;

	private FastQueue<TCallLogS> fastQueue;

	@Override
	public void doCallLog(TCallLogS sqlLog) {
		fastQueue.add(sqlLog);
	}

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

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