package com.persagy.communication.util; import lombok.extern.slf4j.Slf4j; import java.util.concurrent.LinkedBlockingQueue; @Slf4j public class PacketBuffer { private final LinkedBlockingQueue buffer = new LinkedBlockingQueue(); public PacketBuffer() { } // put ����������������� // add ��������������쳣 // offer �����������������false public void offer(T packet, int size) { if (this.buffer.size() >= size) { return; } this.buffer.offer(packet); } // take ��������ѿգ����� // remove ��������ѿգ��쳣 // poll ��������ѿգ�����null public T poll() { T MyPackage = null; try { MyPackage = this.buffer.take(); } catch (InterruptedException e) { log.error(e.getMessage(), e); } return MyPackage; } public T take() throws InterruptedException { T MyPackage = this.buffer.take(); return MyPackage; } public int BufferSize() { return this.buffer.size(); } }