Mercurial > hg > Members > nobuyasu > tightVNCProxy
view src/myVncProxy/MulticastQueue.java @ 65:5fca2bb52dc7
create checkMillis
author | e085711 |
---|---|
date | Fri, 22 Jul 2011 03:21:56 +0900 |
parents | b2604c5c6a25 |
children | 0cbe556e2c54 |
line wrap: on
line source
package myVncProxy; 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; } } }