# HG changeset patch # User Shinji KONO # Date 1398907211 -32400 # Node ID f6946d4fe9268f468a22b251a4eb30d3e32085a5 # Parent 432dac0b9dae3210ca4447c82c4035503bc93d25 add comment diff -r 432dac0b9dae -r f6946d4fe926 src/main/java/jp/ac/u_ryukyu/treevnc/MulticastQueue.java --- a/src/main/java/jp/ac/u_ryukyu/treevnc/MulticastQueue.java Wed Apr 30 20:30:22 2014 +0900 +++ b/src/main/java/jp/ac/u_ryukyu/treevnc/MulticastQueue.java Thu May 01 10:20:11 2014 +0900 @@ -5,9 +5,15 @@ public class MulticastQueue { - + Node tail; + /** + * Multicastcast Queue + * Pass a data to multiple clients. + * element Node T + * Another time out thread should be used to limit the total size. + */ public MulticastQueue() { tail = new Node(null); @@ -19,8 +25,6 @@ * * try to allocate byteBuffer. * wait until heap is available. - * - * */ public ByteBuffer allocate(int size) { @@ -47,6 +51,11 @@ notifyAll(); } + /** + * put item to the queue + * all client threads start read it + * @param item + */ public synchronized void put(T item) { Node next = new Node(item); @@ -54,11 +63,20 @@ tail = next; } + /** + * register new clients. Clients read this queue, if all clients read the queue, item is removed + * @return + */ public Client newClient() { return new Client(tail); } + /** + * @author kono + * Inner Client class + * @param + */ public static class Client { Node node; @@ -68,7 +86,13 @@ node = tail; } - synchronized public T poll() + /** + * try to read next item, if not available, wait for the next item + * All clients wait for a CountDownLatch in the next item. + * set operation count down it, and all clients get the item. + * @return + */ + public T poll() { Node next = null; T item = null; @@ -98,7 +122,7 @@ latch = new CountDownLatch(1); } - synchronized public T getItem() { + public T getItem() { return item; } @@ -114,7 +138,7 @@ return next; } - synchronized public void clear() { + public void clear() { item = null; } }