see if anyone is updating host's port list, if not start , update this host itself
timeout is 45 seconds

@param hostPath
@throws InterruptedException
@throws IOException
19639
private void tryHostLock(String hostPath) throws Exception {

        //if path has created 60 seconds ago, then delete
        if (registryOperations.exists(hostPath)) {
            try {
                ServiceRecord host = registryOperations.resolve(hostPath);
                Long cTime = Long.parseLong(host.get(JOYConstants.CTIME, JOYConstants.DEFAULT_CTIME));
                Date now = new Date();
                if (now.getTime() - cTime > JOYConstants.HOST_LOCK_TIMEOUT || cTime > now.getTime())
                    registryOperations.delete(hostPath, true);
            } catch (Exception ex) {
                LOG.error(ex);
            }
        }

        int failedCount = JOYConstants.RETRY_TIMES;
        while (!registryOperations.mknode(hostPath, true)) {
            Thread.sleep(JOYConstants.SLEEP_INTERVAL);
            failedCount--;
            if (failedCount <= 0)
                break;
        }

        if (failedCount > 0) {
            ServiceRecord sr = new ServiceRecord();
            Date date = new Date();
            date.getTime();
            sr.set(JOYConstants.CTIME, String.valueOf(date.getTime()));
            registryOperations.bind(hostPath, sr, BindFlags.OVERWRITE);
            return;
        }
        throw new Exception("can't get host lock");
    }
909888
public static void main(String[] args) throws InterruptedException {
    List<Feature> features;
    try {
      features = RouteGuideUtil.parseFeatures(RouteGuideUtil.getDefaultFeaturesFile());
    } catch (IOException ex) {
      ex.printStackTrace();
      return;
    }

    RouteGuideClient client = new RouteGuideClient("localhost", 8980);
    try {
      // Looking for a valid feature
      client.getFeature(409146138, -746188906);

      // Feature missing.
      client.getFeature(0, 0);

      // Looking for features between 40, -75 and 42, -73.
      client.listFeatures(400000000, -750000000, 420000000, -730000000);

      // Record a few randomly selected points from the features file.
      client.recordRoute(features, 10);

      // Send and receive some notes.
      CountDownLatch finishLatch = client.routeChat();

      if (!finishLatch.await(1, TimeUnit.MINUTES)) {
        client.warning("routeChat can not finish within 1 minutes");
      }
    } finally {
      client.shutdown();
    }
  }
661894
private void doTimeoutCheck(CassandraHost cassandraHost) {
    if ( hostTimeoutTracker != null && hostPools.size() > 1) {
      if (hostTimeoutTracker.checkTimeout(cassandraHost) ) {
        suspendCassandraHost(cassandraHost);
      }
    }
  }
1345322
public void reconnect (int timeout) throws IOException {
		if (connectHost == null) throw new IllegalStateException("This client has never been connected.");
		connect(timeout, connectHost, connectTcpPort, connectUdpPort);
	}
1313668
public void asyncRequest(String host,int port,HttpRequest request,final CallBack<HttpResponse> callback,long timeOut)
	{
		synchronized (request) {
			final HttpListener listener=new HttpListener(request);
			final NettyClient client=new NettyClient(config,new InetSocketAddress(host, port),new HttpClientInitHandler(listener));
			client.start();
			if(callback!=null)
			{
				scheduExec.execute(new Runnable() {
					@Override
					public void run() {
						HttpResponse result=listener.waitResponse(timeOut);
						callback.call(result!=null,Optional.ofNullable(result));
						client.stop();
					}
				});
			}
		}
	}
1235635
@Override
    public List<String> setTargetHostsFromLineByLineText(String sourcePath,
            HostsSourceType sourceType) throws TargetHostsLoadException {

        List<String> targetHosts = new ArrayList<String>();
        try {
            String content = getContentFromPath(sourcePath, sourceType);

            targetHosts = setTargetHostsFromString(content);

        } catch (IOException e) {
            throw new TargetHostsLoadException("IEException when reading  "
                    + sourcePath, e);
        }

        return targetHosts;

    }
556994
public static boolean isAddressReachable(String hostname, int port) {
    try (Socket socket = new Socket(hostname, port)) {
      return true;
    } catch (IOException e) {
      return false;
    }
  }
1367022
public void setActive(HostPort hostPort)
        throws IOException, ServerException {
        Command cmd = new Command((controlChannel.isIPv6()) ? "EPRT" : "PORT",
                                  hostPort.toFtpCmdArgument());
        try {
            controlChannel.execute(cmd);
        } catch (UnexpectedReplyCodeException urce) {
            throw ServerException.embedUnexpectedReplyCodeException(urce);
        } catch (FTPReplyParseException rpe) {
            throw ServerException.embedFTPReplyParseException(rpe);
        }

        this.session.serverMode = Session.SERVER_ACTIVE;
    }
220037
protected void doOneWay(SofaRequest request, InvokeContext invokeContext, int timeoutMillis)
        throws RemotingException, InterruptedException {
        RPC_CLIENT.oneway(url, request, invokeContext);
    }
865324
protected synchronized void doStop()
        throws InterruptedException
    {
        for (int l=0;l<_listeners.size();l++)
        {
            HttpListener listener =(HttpListener)_listeners.get(l); 
            if (listener.isStarted())
            {
                try{listener.stop();}
                catch(Exception e)
                {
                    if (log.isDebugEnabled())
                        log.warn(LogSupport.EXCEPTION,e);
                    else
                        log.warn(e.toString());
                }
            }
        }
        
        HttpContext[] contexts = getContexts();
        for (int i=0;i<contexts.length;i++)
        {
            HttpContext context=contexts[i];
            context.stop(_gracefulStop);
        }

        if (_notFoundContext!=null)
        {
            _notFoundContext.stop();
            removeComponent(_notFoundContext);
        }
        _notFoundContext=null;
        
        if (_requestLog!=null && _requestLog.isStarted())
            _requestLog.stop();
    }
242536
public void connect(String hosts) throws IOException, InterruptedException {
        internalHost = hosts;
        zk = new ZooKeeper(internalHost, SESSION_TIMEOUT, this);

        // 连接有超时哦
        connectedSignal.await(CONNECT_TIMEOUT, TimeUnit.MILLISECONDS);

        LOGGER.info("zookeeper: " + hosts + " , connected.");
    }
167757
public void updateEntry(String sitePath) {

        CmsClientSitemapEntry entry = getEntry(sitePath);
        if ((entry != null) && (CmsSitemapTreeItem.getItemById(entry.getId()) != null)) {
            getChildren(entry.getId(), CmsSitemapTreeItem.getItemById(entry.getId()).isOpen(), null);
        }
    }
927368
public void setConnectTimeout(int timeout) {
		Assert.isTrue(timeout >= 0, "Timeout must be a non-negative value");
		getHttpClient().getParams().setIntParameter(CoreConnectionPNames.CONNECTION_TIMEOUT, timeout);
	}
583524
protected IOException newTimeoutException(IOException cause) {
    InterruptedIOException e = new InterruptedIOException("timeout");
    if (cause != null) {
      e.initCause(cause);
    }
    return e;
  }
942372
private void updateOtherClientDisconnected() throws IOException
    {
        final byte cid = in.readByte();
        final String cname = readString();
        for (final ConnectionListener listener : listeners)
        {
            listener.notifyClientDisconnected(Byte.valueOf(cid), cname);
        }
    }
563976
public static void reportHostStatus(HostSpec hostSpec, HostStatus hostStatus) {
    long now = currentTimeMillis();
    synchronized (hostStatusMap) {
      HostSpecStatus hostSpecStatus = hostStatusMap.get(hostSpec);
      if (hostSpecStatus == null) {
        hostSpecStatus = new HostSpecStatus(hostSpec);
        hostStatusMap.put(hostSpec, hostSpecStatus);
      }
      hostSpecStatus.status = hostStatus;
      hostSpecStatus.lastUpdated = now;
    }
  }
416796
static <V extends VersionedProtocol> V waitForProxy(Class<V> protocol, InetSocketAddress addr,
			long timeout) throws IOException {
		long startTime = System.currentTimeMillis();
		IOException ioe;
		while (true) {
			try {
				return getProxy(protocol, addr);
			} catch (ConnectException se) { // namenode has not been started
				LOG.info("Server at " + addr + " not available yet, Zzzzz...");
				ioe = se;
			} catch (SocketTimeoutException te) { // namenode is busy
				LOG.info("Problem connecting to server: " + addr);
				ioe = te;
			}
			// check if timed out
			if (System.currentTimeMillis() - timeout >= startTime) {
				throw ioe;
			}

			// wait for retry
			try {
				Thread.sleep(1000);
			} catch (InterruptedException ie) {
				// IGNORE
			}
		}
	}