@Override
	    public Boolean call() throws Exception {
	    	Boolean ynRC = Boolean.FALSE;
	    	final Socket socket = new Socket();
	    	HumanReadableMessages msgs = DefaultFactory.getFactory().getMessages();
	        try {
	            socket.connect(new InetSocketAddress(getHostPort().hostNameOrIpAddress, getHostPort().port));
	            getHostPort().setIp(socket.getInetAddress().getHostAddress());
	            getConnectionDetail().setSocket(socket);
	            getMasterCallback().setConnectionStatusMsg( 
	            		msgs.getConnectionSuccessful( getHostPort() ) );
	            getMasterCallback().setConnectState(ConnectState.CONNECTED);
	            ynRC = Boolean.TRUE;
	        } catch (Exception e) {
	        	  getMasterCallback().setConnectionStatusMsg( msgs.getFailedConnection(getHostPort(), e) );
	        	  getMasterCallback().setConnectState(ConnectState.DISCONNECTED_ERR);
	        	  getConnectionDetail().setSocket(null);
	        	  ynRC = Boolean.FALSE;
	        }
	        return ynRC;
	    }
	}	
	public void connect_ORIG(String host, int port, IAgentCommand[] startupCommandAry ) throws ConnectionTimeout, ConnectionException, BadCompletedRequestListener {
		setHostPort( new HostPort(host,port));
		
		addCallback(new DefaultCallback());
		try {
			DefaultConnectionList.getSingleton().connect(getMasterCallback(), m_hostPort , startupCommandAry);
			Thread.sleep(DefaultFactory.getFactory().getConfig().getConnectWaitMs());
		} catch (InterruptedException e) {
			throw new ConnectionTimeout(m_hostPort, DefaultFactory.getFactory().getConfig().getConnectWaitMs());
		}
		
		IConnection c = DefaultConnectionList.getSingleton().locateConnection(m_hostPort);

		//TODO TODO TODO
//		NetworkDataReceiverThread2 ntt2 = c.getConn.getNetworkTraceThread2();
//		ntt2.addTraceWriter(m_traceWriter);
	}
	
	@Override
	public HostPort getHostPort() {
		return m_hostPort;
	}
	@Override
	public void setHostPort(HostPort hostPort) {
		this.m_hostPort = hostPort;
	}
	@Override
	public void disconnect() {
		IConnectionList connectionList = DefaultConnectionList.getSingleton();
		//IConnection cpt = connectionList.locateConnection(m_hostPort);
		
		try {
			this.getConnectionDetail().disconnect();
			//this.getNetworkTraceThread2().disconnect();
			connectionList.disconnect(this, getMasterCallback());
		} catch(DisconnectionException de) {
			//Since our goal is to disconnect, no need to do anything with the exception.
		}
	}
	@Override
	public ITraceWriter getTraceWriter() {
		return m_traceWriter;
	}
	@Override
	public void setTraceWriter(ITraceWriter traceWriter) {
		this.m_traceWriter = traceWriter;
	}
	@Override
	public boolean connect(String host, int port, IAgentCommand[] startupCommandAry)
			throws ConnectionTimeout, ConnectionException,
			BadCompletedRequestListener {
		HostPort hostPort = new HostPort(host,port);
		return connect(hostPort,startupCommandAry);
		
	}
	  /**
	   * Returns the count of callbacks still listening to 'this'.
	   * This method will perform a hard disconnect if 0 is returned.
	   * @param criteria
	   * @return
	   */
	  public int removeCallback(IConnectionStateCallback criteria) {
		  
		  List<IConnectionStateCallback> listCallbacks = getConnectionDetail().getConnCallbacks();
		  /**
		   * If this method is about to delete the last callback, then
		   * there are no windows left listening, so it is safe to
		   * do a hard disconnect.
		   */
		  if (listCallbacks.size() <= 1) {
			  getConnectionDetail().unHappyDisconnect();
			  listCallbacks.remove(criteria);
			  
			  DefaultConnectionList connList = (DefaultConnectionList) DefaultConnectionList.getSingleton();
			  connList.remove(this);
			  
		  } else {
			//utter a last dying gasp (DISCONNECTED status) before removing the callback.
			  //criteria.setConnectionState(ConnectState.DISCONNECTED);
			  //broadcastConnectionState(criteria);
			  listCallbacks.remove(criteria);
		  }
		  return listCallbacks.size();
	  }
	
	@Override
	public int removeConnectionStatusCallback(IConnectionStateCallback cb) {
		return removeCallback(cb);
		
	}
	@Override
	public boolean isConnected() {
		boolean ynRC = false;
		if (getConnectionDetail().getConnectState().equals(ConnectState.CONNECTED))
			ynRC = true;
		return ynRC;
	}
	@Override
	public void executeStartupCommands() {
		getConnectionDetail().executeStartupCommands();
		
	}
	@Override
	public NetworkDataReceiverThread2 getNetworkTraceThread2() {
		return getConnectionDetail().getNetworkTraceThread2();
	}