public Message poll() { if (isEmpty()) return null; Message m = realtimeQueue.poll(); if (m == null) { m = priorityQueue.poll(); } if (m == null) { m = orderedQueue.poll(); } if (m == null) { m = basicQueue.poll(); } if (size > 0) size--; return m; }
public void add(Message message) { if (message == null) throw new NullPointerException("Message must not be null"); if (size == max) throw new QueueFullException("Queue reached max size: " + max); boolean increment = true; if (message instanceof RealtimeMessage) { increment = !realtimeQueue.addRemoves(message); } else if (message instanceof PriorityMessage) { priorityQueue.add(message); } else if (message instanceof OrderedMessage) { orderedQueue.add(message); } else { basicQueue.add(message); } if (increment) size++; total++; }