public boolean queueAt(Alarm alarm,long wakeTime){
  boolean isEarliest=false;
  long prevNextAlarmTime;
  do {
    prevNextAlarmTime=_nextAlarmTime.get();
  }
 while (wakeTime > 0 && wakeTime < prevNextAlarmTime && !_nextAlarmTime.compareAndSet(prevNextAlarmTime,wakeTime));
  if (wakeTime < prevNextAlarmTime) {
    isEarliest=true;
  }
  long oldWakeTime=alarm.getAndSetWakeTime(wakeTime);
  if (oldWakeTime == wakeTime) {
    return false;
  }
  if (oldWakeTime > 0) {
    if (!dequeueImpl(alarm)) {
    }
  }
  if (wakeTime <= 0) {
    return false;
  }
  long now=_now.get();
  if (wakeTime <= now) {
    queueCurrent(alarm);
    return true;
  }
synchronized (_lock) {
    if (alarm.getBucket() >= 0) {
      return false;
    }
    int bucket=getBucket(wakeTime);
    alarm.setBucket(bucket);
    Alarm top=_clockArray[bucket];
    alarm.setNext(top);
    _clockArray[bucket]=alarm;
  }
  now=_now.get();
  long nextWakeTime=alarm.getWakeTime();
  if (nextWakeTime != wakeTime || wakeTime < now) {
    dequeueImpl(alarm);
    queueCurrent(alarm);
  }
  return isEarliest;
}

public boolean queueAt ( Alarm alarm , long wakeTime ) { boolean isEarliest = false ; long prevNextAlarmTime ; do { prevNextAlarmTime = _nextAlarmTime . get ( ) ; } while ( wakeTime > 0 && wakeTime < prevNextAlarmTime && ! _nextAlarmTime . compareAndSet ( prevNextAlarmTime , wakeTime ) ) ; if ( wakeTime < prevNextAlarmTime ) { isEarliest = true ; } long oldWakeTime = alarm . getAndSetWakeTime ( wakeTime ) ; if ( oldWakeTime == wakeTime ) { return false ; } if ( oldWakeTime > 0 ) { if ( ! dequeueImpl ( alarm ) ) { } } if ( wakeTime <= 0 ) { return false ; } long now = _now . get ( ) ; if ( wakeTime <= now ) { queueCurrent ( alarm ) ; return true ; } synchronized ( _lock ) { if ( alarm . getBucket ( ) >= 0 ) { return false ; } int bucket = getBucket ( wakeTime ) ; alarm . setBucket ( bucket ) ; Alarm top = _clockArray [ bucket ] ; alarm . setNext ( top ) ; _clockArray [ bucket ] = alarm ; } now = _now . get ( ) ; long nextWakeTime = alarm . getWakeTime ( ) ; if ( nextWakeTime != wakeTime || wakeTime < now ) { dequeueImpl ( alarm ) ; queueCurrent ( alarm ) ; } return isEarliest ; }
queue the alarm for wakeup .
