changeset 86:f6946d4fe926

add comment
author Shinji KONO <kono@ie.u-ryukyu.ac.jp>
date Thu, 01 May 2014 10:20:11 +0900
parents 432dac0b9dae
children 9a485070f831
files src/main/java/jp/ac/u_ryukyu/treevnc/MulticastQueue.java
diffstat 1 files changed, 30 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- 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<T>
 {
-	
+
 	Node<T> 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<T>(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<T> next = new Node<T>(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<T> newClient()
 	{
 		return new Client<T>(tail);
 	}
 	
+	/**
+	 * @author kono
+	 * Inner Client class
+	 * @param <T>
+	 */
 	public static class Client<T>
 	{
 		Node<T> 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<T> 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;
 		}
 	}