package com.mercury.chat.client.protocol;

import java.util.concurrent.BlockingQueue;
import java.util.concurrent.LinkedBlockingQueue;

import com.mercury.chat.common.struct.protocol.Message;

public class MessageBox {

	private BlockingQueue<Message> box = new LinkedBlockingQueue<Message>(1);
	
	public void put(Message msg){
		box.offer(msg);
	}
	
	public Message get(){
		Message msg = null;
		try {
			msg = box.take();
		} catch (InterruptedException e) {
			//ignore
		}
		return msg;
	}
	
}

@@ -131,16 +131,55 @@
 gQueue;%0D
+%0Aimport java.util.concurrent.TimeUnit;%0D
 %0A%0D%0Aimpor
@@ -261,16 +261,63 @@
 ox %7B%0D%0A%0D%0A
+%09private volatile boolean discard = false;%0D%0A%09%0D%0A
 %09private
@@ -419,16 +419,34 @@
  msg)%7B%0D%0A
+%09%09if(!discard)%7B%0D%0A%09
 %09%09box.of
@@ -456,16 +456,21 @@
 (msg);%0D%0A
+%09%09%7D%0D%0A
 %09%7D%0D%0A%09%0D%0A%09
@@ -541,13 +541,41 @@
 box.
-take(
+poll(10000, TimeUnit.MILLISECONDS
 );%0D%0A
@@ -636,18 +636,206 @@
 %0D%0A%09%09
-return msg
+%0D%0A%09%09if(msg == null)%7B%0D%0A%09%09%09setDiscard(true);%0D%0A%09%09%7D%0D%0A%09%09%0D%0A%09%09return msg;%0D%0A%09%7D%0D%0A%0D%0A%09public boolean isDiscard() %7B%0D%0A%09%09return discard;%0D%0A%09%7D%0D%0A%0D%0A%09public void setDiscard(boolean discard) %7B%0D%0A%09%09this.discard = discard
 ;%0D%0A%09

add discard flag to message box.