package utility;

public class DataConnectionHandler implements Runnable

{
	public  AgentIdentity id;
	public  DataServerHandler svrHandler = null;
  	public  Thread t = null;
	public volatile boolean stop = false;

	public DataConnectionHandler(AgentIdentity id , DataServerHandler sh)
	{
    		this.id = id;
    		svrHandler = sh;
  		t=new Thread(this);
		t.start();
	}
  	public void run()
	{
    		System.out.println("Starting data connection  handler for connection  " + id.getLoginName());
    		while (!stop)
		{
      			try
			{
        			boolean result = svrHandler.readStream(id);
        			if(result == true)
				{
					System.out.println("Reading successful");
        				//svrHandler.doThis(req,id);
      				}
			}
      			catch (Exception e)
			{
				e.printStackTrace();
				System.out.println(e + " : closing it(4)");
				svrHandler.removeConnection(id.getId());
				break;
			}

		}
  		System.out.println("stopping connection handler for : "+id);
	}
}
