重构航班缓存发送代码
This commit is contained in:
@@ -0,0 +1,41 @@
|
||||
package com.gzzn.omms.msgexchangeapi.service;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.ConcurrentLinkedQueue;
|
||||
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import com.gzzn.omms.msgexchangeapi.entity.msg.SCHD;
|
||||
import com.gzzn.omms.msgexchangeapi.entity.msg.SCHD.FLTR;
|
||||
|
||||
/**
|
||||
* 要发到kafka 的航班动态信息,先在这里做缓存。
|
||||
* @author zhouxiunai
|
||||
*
|
||||
*/
|
||||
@Service("msgbufferservice")
|
||||
public class FltrSendBufferService implements IFltrSendBufferService {
|
||||
private static ConcurrentLinkedQueue<SCHD.FLTR> fltrBuffer = new ConcurrentLinkedQueue<SCHD.FLTR>();
|
||||
|
||||
@Override
|
||||
public void addFltr(SCHD.FLTR fltr) {
|
||||
fltrBuffer.add(fltr);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public List<FLTR> takeAllFltr() {
|
||||
if(fltrBuffer.size() <= 0)
|
||||
{
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
//
|
||||
FLTR[] fltrs = (FLTR[]) fltrBuffer.toArray(new FLTR[fltrBuffer.size()]); // TODO 转换出错
|
||||
fltrBuffer.clear();//to fix ,获取及清空过程中是否要加锁
|
||||
|
||||
return Arrays.asList(fltrs);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user