Mercurial > hg > Members > nobuyasu > tightVNCClient
changeset 39:6a81ab4df524
add MulticastQueue.java
author | e085711 |
---|---|
date | Sat, 09 Jul 2011 00:48:29 +0900 |
parents | 0729e856169d |
children | 672e7582bcce |
files | bin/java.policy.applet bin/myVncClient/waitreply.class src/myVncClient/MulticastQueue.java |
diffstat | 3 files changed, 82 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/bin/java.policy.applet Sat Jul 09 00:48:29 2011 +0900 @@ -0,0 +1,7 @@ +/* AUTOMATICALLY GENERATED ON Tue Apr 16 17:20:59 EDT 2002*/ +/* DO NOT EDIT */ + +grant { + permission java.security.AllPermission; +}; +
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/myVncClient/MulticastQueue.java Sat Jul 09 00:48:29 2011 +0900 @@ -0,0 +1,75 @@ +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; + } + } +}