package org.moparscape.msc.ls.net; import java.util.ArrayList; import java.util.List; /** * Synchronized packet queue */ public class PacketQueue { /** * The list of packets in the queue */ private ArrayList packets = new ArrayList(); /** * Adds a packet to the queue */ public void add(T p) { synchronized (packets) { packets.add(p); } } /** * Returns the packets currently in the list and removes them from the * backing store */ @SuppressWarnings("unchecked") public List getPackets() { List tmpList; synchronized (packets) { tmpList = (List) packets.clone(); packets.clear(); } return tmpList; } /** * Returns if there is packets to process */ public boolean hasPackets() { return !packets.isEmpty(); } }