예제 #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.throwAsUncheckedException(e);
    } finally {
      lock.unlock();
    }
  }
 private void log(LogLevel logLevel, Throwable throwable, String message) {
   LogEvent logEvent =
       new LogEvent(timeProvider.getCurrentTime(), name, logLevel, message, throwable);
   OutputEventListener outputEventListener = context.getOutputEventListener();
   try {
     outputEventListener.onOutput(logEvent);
   } catch (Throwable e) {
     // fall back to standard out
     e.printStackTrace(System.out);
   }
 }
예제 #3
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();
   }
 }
예제 #4
0
파일: Clock.java 프로젝트: GUIpsp/gradle
 public void reset() {
   start = timeProvider.getCurrentTime();
 }
예제 #5
0
파일: Clock.java 프로젝트: GUIpsp/gradle
 public long getTimeInMs() {
   return timeProvider.getCurrentTime() - start;
 }