private ClientSocket connect(){
  if (_maxConnections <= _activeCount.get() + _startingCount.get()) {
    if (log.isLoggable(Level.WARNING)) {
      log.warning(this + " connect exceeded max-connections" + "\n  max-connections="+ _maxConnections+ "\n  activeCount="+ _activeCount.get()+ "\n  startingCount="+ _startingCount.get());
    }
    return null;
  }
  _startingCount.incrementAndGet();
  State state=_state;
  if (!state.isInit()) {
    _startingCount.decrementAndGet();
    IllegalStateException e=new IllegalStateException(L.l("'{0}' connection cannot be opened because the server pool has not been started.",this));
    log.log(Level.WARNING,e.toString(),e);
    throw e;
  }
  if (getPort() <= 0) {
    return null;
  }
  long connectionStartTime=CurrentTime.currentTime();
  try {
    ReadWritePair pair=openTCPPair();
    ReadStreamOld rs=pair.getReadStream();
    rs.setEnableReadTime(true);
    _activeCount.incrementAndGet();
    _connectCountTotal.incrementAndGet();
    ClientSocket stream=new ClientSocket(this,_streamCount++,rs,pair.getWriteStream());
    if (log.isLoggable(Level.FINER))     log.finer("connect " + stream);
    if (_firstSuccessTime <= 0) {
      if (_state.isStarting()) {
        if (_loadBalanceWarmupTime > 0)         _state=State.WARMUP;
 else         _state=State.ACTIVE;
        _firstSuccessTime=CurrentTime.currentTime();
      }
      if (_warmupState < 0)       _warmupState=0;
    }
    return stream;
  }
 catch (  IOException e) {
    if (log.isLoggable(Level.FINEST))     log.log(Level.FINEST,this + " " + e.toString(),e);
 else     log.finer(this + " " + e.toString());
    failConnect(connectionStartTime);
    return null;
  }
 finally {
    _startingCount.decrementAndGet();
  }
}

private ClientSocket connect ( ) { if ( _maxConnections <= _activeCount . get ( ) + _startingCount . get ( ) ) { if ( log . isLoggable ( Level . WARNING ) ) { log . warning ( this + " connect exceeded max-connections" + "\n  max-connections=" + _maxConnections + "\n  activeCount=" + _activeCount . get ( ) + "\n  startingCount=" + _startingCount . get ( ) ) ; } return null ; } _startingCount . incrementAndGet ( ) ; State state = _state ; if ( ! state . isInit ( ) ) { _startingCount . decrementAndGet ( ) ; IllegalStateException e = new IllegalStateException ( L . l ( "'{0}' connection cannot be opened because the server pool has not been started." , this ) ) ; log . log ( Level . WARNING , e . toString ( ) , e ) ; throw e ; } if ( getPort ( ) <= 0 ) { return null ; } long connectionStartTime = CurrentTime . currentTime ( ) ; try { ReadWritePair pair = openTCPPair ( ) ; ReadStreamOld rs = pair . getReadStream ( ) ; rs . setEnableReadTime ( true ) ; _activeCount . incrementAndGet ( ) ; _connectCountTotal . incrementAndGet ( ) ; ClientSocket stream = new ClientSocket ( this , _streamCount ++ , rs , pair . getWriteStream ( ) ) ; if ( log . isLoggable ( Level . FINER ) ) log . finer ( "connect " + stream ) ; if ( _firstSuccessTime <= 0 ) { if ( _state . isStarting ( ) ) { if ( _loadBalanceWarmupTime > 0 ) _state = State . WARMUP ; else _state = State . ACTIVE ; _firstSuccessTime = CurrentTime . currentTime ( ) ; } if ( _warmupState < 0 ) _warmupState = 0 ; } return stream ; } catch ( IOException e ) { if ( log . isLoggable ( Level . FINEST ) ) log . log ( Level . FINEST , this + " " + e . toString ( ) , e ) ; else log . finer ( this + " " + e . toString ( ) ) ; failConnect ( connectionStartTime ) ; return null ; } finally { _startingCount . decrementAndGet ( ) ; } }
connect to the backend server .
