package gov.nasa.jpl.mbee.ems.sync;

import java.util.Iterator;
import java.util.concurrent.LinkedBlockingQueue;

import javax.swing.SwingUtilities;

import org.apache.log4j.Logger;

import gov.nasa.jpl.mbee.lib.Utils;

public class OutputQueue extends LinkedBlockingQueue<Request> {
    private Logger log = Logger.getLogger(OutputQueue.class);
    private final static OutputQueue instance = new OutputQueue();
    private volatile Request current = null;
    private OutputQueue() {
        super();
    }
    
    @Override
    public boolean offer(Request e) {
    	boolean result = super.offer(e);
    	SwingUtilities.invokeLater(new Runnable() {
        	@Override
            public void run() {
        		OutputQueueStatusConfigurator.getOutputQueueStatusAction().update(true);
            }
        });
    	return result;
    }
    
    public static OutputQueue getInstance() {
        return instance;
    }
    
    public void setCurrent(Request r) {
        this.current = r;
    }
    
    public Request getCurrent() {
        return current;
    }
    public void remove(int _rowNum ){
    	//linkedQueue not contain current so the index of removing row is (_rowNum -1)
    	Request toBeRemoved = (Request) this.toArray()[_rowNum-1];
    	log.info("[INFO] Removing  a queue: " + toBeRemoved.getJson());
    	super.remove(toBeRemoved);
    }
    
}
@@ -1186,17 +1186,62 @@
 -1)%0A    
-%09
+    if (this.size() %3E= _rowNum) %7B%0A            
 Request 
@@ -1295,17 +1295,98 @@
 1%5D;%0A    
-%09
+        if (toBeRemoved != null && toBeRemoved.getJson() != null)%0A                
 log.info
@@ -1445,17 +1445,24 @@
 ));%0A    
-%09
+        
 super.re
@@ -1480,16 +1480,26 @@
 moved);%0A
+        %7D%0A
     %7D%0A  

add some checks