void free(ClientSocket stream){
  success();
  _activeCount.decrementAndGet();
synchronized (this) {
    int size=(_idleHead - _idleTail + _idle.length) % _idle.length;
    if (_state != State.CLOSED && size < _idleSize) {
      _idleHead=(_idleHead + 1) % _idle.length;
      _idle[_idleHead]=stream;
      stream=null;
    }
    long now=CurrentTime.currentTime();
    long prevSuccessTime=_prevSuccessTime;
    if (prevSuccessTime > 0) {
      _latencyFactor=(0.95 * _latencyFactor + 0.05 * (now - prevSuccessTime));
    }
    if (_activeCount.get() > 0)     _prevSuccessTime=now;
 else     _prevSuccessTime=0;
    _lastSuccessTime=now;
    if (log.isLoggable(Level.FINEST)) {
      logFinest(L.l("free: _lastSuccessTime={0}, _failTime={1}",now,_failTime));
    }
  }
  updateWarmup();
  long now=CurrentTime.currentTime();
  long maxIdleTime=_loadBalanceIdleTime;
  ClientSocket oldStream=null;
  do {
    oldStream=null;
synchronized (this) {
      if (_idleHead != _idleTail) {
        int nextTail=(_idleTail + 1) % _idle.length;
        oldStream=_idle[nextTail];
        if (oldStream != null && oldStream.getIdleStartTime() + maxIdleTime < now) {
          _idle[nextTail]=null;
          _idleTail=nextTail;
        }
 else         oldStream=null;
      }
    }
    if (oldStream != null)     oldStream.closeImpl();
  }
 while (oldStream != null);
  if (stream != null) {
    stream.closeImpl();
  }
}

void free ( ClientSocket stream ) { success ( ) ; _activeCount . decrementAndGet ( ) ; synchronized ( this ) { int size = ( _idleHead - _idleTail + _idle . length ) % _idle . length ; if ( _state != State . CLOSED && size < _idleSize ) { _idleHead = ( _idleHead + 1 ) % _idle . length ; _idle [ _idleHead ] = stream ; stream = null ; } long now = CurrentTime . currentTime ( ) ; long prevSuccessTime = _prevSuccessTime ; if ( prevSuccessTime > 0 ) { _latencyFactor = ( 0.95 * _latencyFactor + 0.05 * ( now - prevSuccessTime ) ) ; } if ( _activeCount . get ( ) > 0 ) _prevSuccessTime = now ; else _prevSuccessTime = 0 ; _lastSuccessTime = now ; if ( log . isLoggable ( Level . FINEST ) ) { logFinest ( L . l ( "free: _lastSuccessTime={0}, _failTime={1}" , now , _failTime ) ) ; } } updateWarmup ( ) ; long now = CurrentTime . currentTime ( ) ; long maxIdleTime = _loadBalanceIdleTime ; ClientSocket oldStream = null ; do { oldStream = null ; synchronized ( this ) { if ( _idleHead != _idleTail ) { int nextTail = ( _idleTail + 1 ) % _idle . length ; oldStream = _idle [ nextTail ] ; if ( oldStream != null && oldStream . getIdleStartTime ( ) + maxIdleTime < now ) { _idle [ nextTail ] = null ; _idleTail = nextTail ; } else oldStream = null ; } } if ( oldStream != null ) oldStream . closeImpl ( ) ; } while ( oldStream != null ) ; if ( stream != null ) { stream . closeImpl ( ) ; } }
free the read / write pair for reuse . called only from clusterstream . free ( ) .
