/**
  * Returns +1 (last connection attempt was a success), 0 (no connection attempts), or -1 (last
  * connection attempt was a failure).
  */
 private int connectScore() {
   if (connectSuccesses.isEmpty() && connectFailures.isEmpty()) return 0; // no attempts
   else if (connectSuccesses.isEmpty()) return -1; // only failures
   else if (connectFailures.isEmpty()) return 1; // only successes
   else {
     long success = ((Long) connectSuccesses.last()).longValue();
     long failure = ((Long) connectFailures.last()).longValue();
     // Can't use success-failure because of overflow/underflow.
     if (success > failure) return 1;
     else if (success < failure) return -1;
     else return 0;
   }
 }
 private void recordConnectionAttempt(Buffer buf, long now) {
   if (buf.isEmpty()) {
     // a) No attempts; just add it.
     buf.addFirst(new Long(now));
   } else if (now - ((Long) buf.first()).longValue() >= WINDOW_TIME) {
     // b) Attempt more than WINDOW_TIME milliseconds ago.  Add.
     buf.addFirst(new Long(now));
   } else {
     // c) Attempt within WINDOW_TIME.  Coalesce.
     buf.removeFirst();
     buf.addFirst(new Long(now));
   }
 }
 /**
  * Returns the last few times we successfully connected to this.
  *
  * @return an Iterator of system times in milliseconds, each as a Long, in descending order.
  */
 public Iterator /* Long */ getConnectionFailures() {
   return connectFailures.iterator();
 }
 /**
  * Returns the last few times we successfully connected to this.
  *
  * @return an Iterator of system times in milliseconds, each as a Long, in descending order.
  */
 public Iterator /* Long */ getConnectionSuccesses() {
   return connectSuccesses.iterator();
 }