@@ -0,0 +1,2204 @@
+/*%0D%0A * Copyright (c) 2012 Philipp Meinen %3Cphilipp@bind.ch%3E%0D%0A *%0D%0A * Permission is hereby granted, free of charge, to any person obtaining a copy%0D%0A * of this software and associated documentation files (the %22Software%22),%0D%0A * to deal in the Software without restriction, including without limitation%0D%0A * the rights to use, copy, modify, merge, publish, distribute, sublicense,%0D%0A * and/or sell copies of the Software, and to permit persons to whom the Software%0D%0A * is furnished to do so, subject to the following conditions:%0D%0A *%0D%0A * The above copyright notice and this permission notice shall be included%0D%0A * in all copies or substantial portions of the Software.%0D%0A *%0D%0A * THE SOFTWARE IS PROVIDED %22AS IS%22, WITHOUT WARRANTY OF ANY KIND,%0D%0A * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF%0D%0A * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.%0D%0A * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,%0D%0A * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,%0D%0A * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH%0D%0A * THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.%0D%0A */%0D%0Apackage ch.bind.philib.io;%0D%0A%0D%0Aimport java.util.Queue;%0D%0Aimport java.util.concurrent.ConcurrentLinkedQueue;%0D%0Aimport java.util.concurrent.Semaphore;%0D%0A%0D%0Aimport ch.bind.philib.validation.SimpleValidation;%0D%0A%0D%0A/**%0D%0A * A notifying queue. Every time an item is added to the queue semaphore is%0D%0A * released.%0D%0A */%0D%0Apublic final class NQueue%3CE%3E %7B%0D%0A%0D%0A%09private final Semaphore sem;%0D%0A%0D%0A%09private final Queue%3CE%3E queue;%0D%0A%0D%0A%09public NQueue(Semaphore sem) %7B%0D%0A%09%09this(sem, new ConcurrentLinkedQueue%3CE%3E());%0D%0A%09%7D%0D%0A%0D%0A%09public NQueue(Semaphore sem, Queue%3CE%3E queue) %7B%0D%0A%09%09SimpleValidation.notNull(sem);%0D%0A%09%09SimpleValidation.notNull(queue);%0D%0A%09%09this.sem = sem;%0D%0A%09%09this.queue = queue;%0D%0A%09%7D%0D%0A%0D%0A%09public boolean offer(E e) %7B%0D%0A%09%09boolean added = queue.add(e);%0D%0A%09%09if (added) %7B%0D%0A%09%09%09sem.release();%0D%0A%09%09%7D%0D%0A%09%09return added;%0D%0A%09%7D%0D%0A%0D%0A%09public int size() %7B%0D%0A%09%09return queue.size();%0D%0A%09%7D%0D%0A%0D%0A%09public boolean isEmpty() %7B%0D%0A%09%09return queue.isEmpty();%0D%0A%09%7D%0D%0A%0D%0A%09public void clear() %7B%0D%0A%09%09queue.clear();%0D%0A%09%7D%0D%0A%0D%0A%09public E poll() %7B%0D%0A%09%09return queue.poll();%0D%0A%09%7D%0D%0A%0D%0A%09public E peek() %7B%0D%0A%09%09return queue.peek();%0D%0A%09%7D%0D%0A%7D%0D%0A

undo netqueue deletion