package wbModule;
import utility.*;
import java.util.Vector;
import java.awt.Point;
class PointSender implements Runnable
{
	Thread t ;
	volatile boolean stop = false;
	WbClientHandler cliHandler;
  	Vector cliHeaders = new Vector();
  	public PointSender(WbClientHandler cliHandler)
	{
    		this.cliHandler = cliHandler;
  		stop = false;
		t= new Thread (this);
		t.start();
		System.out.println("starting point sender");
	}
  	public void addHeader(WbPoint pt,String reqType)
	{
		Request req =new Request(pt,reqType);
		ClientHeader toBeSent =new ClientHeader( req);
		synchronized (cliHeaders)
		{
      			cliHeaders.addElement(toBeSent);
    		}
 	}

	public boolean stopSender()
	{
		stop = true;
		return stop;
	}
	public void run()
	{

		while (!stop)
		{
      			try
			{
        			ClientHeader toBeSent = null;
        			if(cliHeaders.size() >0)
				{
					synchronized (cliHeaders)
					{
          					toBeSent= (ClientHeader)cliHeaders.elementAt(0);
          					cliHeaders.removeElementAt(0);
        				}
					boolean res = cliHandler.sendRequest(toBeSent);
      		
				}
			}
      			catch (Exception e) {}
    		}
  	}
}
