Exemplo n.º 1
0
  public T receive() {
    lock.lock();
    try {
      while (true) {
        DelayedMessage message = queue.peek();
        if (message == null && stopping) {
          return null;
        }
        if (message == null) {
          condition.await();
          continue;
        }

        long now = timeProvider.getCurrentTime();
        if (message.dispatchTime > now) {
          condition.awaitUntil(new Date(message.dispatchTime));
        } else {
          queue.poll();
          if (queue.isEmpty()) {
            condition.signalAll();
          }
          return message.message;
        }
      }
    } catch (InterruptedException e) {
      throw UncheckedException.asUncheckedException(e);
    } finally {
      lock.unlock();
    }
  }
Exemplo n.º 2
0
 /** Dispatches the given message after the given delay. */
 public void dispatchLater(T message, int delayValue, TimeUnit delayUnits) {
   long dispatchTime = timeProvider.getCurrentTime() + delayUnits.toMillis(delayValue);
   lock.lock();
   try {
     if (stopping) {
       throw new IllegalStateException("This dispatch has been stopped.");
     }
     queue.add(new DelayedMessage(dispatchTime, message));
     condition.signalAll();
   } finally {
     lock.unlock();
   }
 }
 ModuleResolutionCacheEntry(ModuleRevisionId revisionId, TimeProvider timeProvider) {
   this.encodedRevisionId = revisionId == null ? null : revisionId.encodeToString();
   this.createTimestamp = timeProvider.getCurrentTime();
 }