Mercurial > hg > Members > nobuyasu > tightVNCClient
view src/myVncClient/MulticastQueue.java @ 109:13b430dae64a default tip
Added tag Version-1.0 for changeset e66137b514eb
author | Yu Taninari <you@cr.ie.u-ryukyu.ac.jp> |
---|---|
date | Tue, 29 Nov 2011 15:53:08 +0900 |
parents | 6a81ab4df524 |
children |
line wrap: on
line source
package myVncClient; import java.util.concurrent.CountDownLatch; public class MulticastQueue<T> { Node<T> tail; public MulticastQueue() { tail = new Node<T>(null); } public synchronized void put(T item) { Node<T> next = new Node<T>(item); tail.set(next); tail = next; } public Client<T> newClient() { return new Client<T>(tail); } static class Client<T> { Node<T> node; Client(Node<T> tail) { node = tail; } public T poll() { Node<T> next = null; try { next = node.next(); }catch(InterruptedException _e){ _e.printStackTrace(); } node = next; return next.item; } } private static class Node<T> { private T item; private Node<T> next; private CountDownLatch latch; public Node(T item) { this.item = item; this.next = null; latch = new CountDownLatch(1); } public void set(Node<T> next) { this.next = next; latch.countDown(); } public Node<T> next() throws InterruptedException { latch.await(); return next; } } }