コード例 #1
0
 private synchronized Duration elapsedErrorDuration() {
   if (errorStopwatch.isRunning()) {
     errorStopwatch.stop();
   }
   long nanos = errorStopwatch.elapsed(TimeUnit.NANOSECONDS);
   return new Duration(nanos, TimeUnit.NANOSECONDS).convertTo(TimeUnit.SECONDS);
 }
コード例 #2
0
 public void start() {
   if (watch.isRunning()) {
     watch.reset().start();
   } else {
     watch.start();
   }
 }
コード例 #3
0
 @Override
 public void failed(Throwable t) {
   if (stopwatch.isRunning()) {
     long latencyNanos = stopwatch.elapsed(NANOSECONDS);
     recorder.recordFailure(t, latencyNanos);
   } else {
     recorder.recordSkip(t);
   }
 }
コード例 #4
0
ファイル: ServiceManager.java プロジェクト: chums122/Spigot
    void transitionService(Service service, Service.State from, Service.State to) {
      Preconditions.checkNotNull(service);
      Preconditions.checkArgument(from != to);
      this.monitor.enter();
      try {
        this.transitioned = true;
        if (!this.ready) {
          return;
        }
        Preconditions.checkState(
            this.servicesByState.remove(from, service),
            "Service %s not at the expected location in the state map %s",
            new Object[] {service, from});

        Preconditions.checkState(
            this.servicesByState.put(to, service),
            "Service %s in the state map unexpectedly at %s",
            new Object[] {service, to});

        Stopwatch stopwatch = (Stopwatch) this.startupTimers.get(service);
        if (from == Service.State.NEW) {
          stopwatch.start();
        }
        if ((to.compareTo(Service.State.RUNNING) >= 0) && (stopwatch.isRunning())) {
          stopwatch.stop();
          if (!(service instanceof ServiceManager.NoOpService)) {
            ServiceManager.logger.log(
                Level.FINE, "Started {0} in {1}.", new Object[] {service, stopwatch});
          }
        }
        if (to == Service.State.FAILED) {
          fireFailedListeners(service);
        }
        if (this.states.count(Service.State.RUNNING) == this.numberOfServices) {
          fireHealthyListeners();
        } else if (this.states.count(Service.State.TERMINATED)
                + this.states.count(Service.State.FAILED)
            == this.numberOfServices) {
          fireStoppedListeners();
        }
      } finally {
        this.monitor.leave();

        executeListeners();
      }
    }
コード例 #5
0
ファイル: ServiceManager.java プロジェクト: chums122/Spigot
 ImmutableMap<Service, Long> startupTimes() {
   this.monitor.enter();
   List<Map.Entry<Service, Long>> loadTimes;
   try {
     loadTimes =
         Lists.newArrayListWithCapacity(
             this.states.size()
                 - this.states.count(Service.State.NEW)
                 + this.states.count(Service.State.STARTING));
     for (Map.Entry<Service, Stopwatch> entry : this.startupTimers.entrySet()) {
       Service service = (Service) entry.getKey();
       Stopwatch stopWatch = (Stopwatch) entry.getValue();
       if ((!stopWatch.isRunning())
           && (!this.servicesByState.containsEntry(Service.State.NEW, service))
           && (!(service instanceof ServiceManager.NoOpService))) {
         loadTimes.add(
             Maps.immutableEntry(
                 service, Long.valueOf(stopWatch.elapsed(TimeUnit.MILLISECONDS))));
       }
     }
   } finally {
     this.monitor.leave();
   }
   Collections.sort(
       loadTimes,
       Ordering.natural()
           .onResultOf(
               new Function() {
                 public Long apply(Map.Entry<Service, Long> input) {
                   return (Long) input.getValue();
                 }
               }));
   ImmutableMap.Builder<Service, Long> builder = ImmutableMap.builder();
   for (Map.Entry<Service, Long> entry : loadTimes) {
     builder.put(entry);
   }
   return builder.build();
 }
コード例 #6
0
 /**
  * false if started or paused, true otherwise (ie the timer is counting down, even if it is
  * expired)
  */
 public boolean isNotPaused() {
   return stopwatch.isRunning();
 }
コード例 #7
0
 /** pauses the timer, if running; no-op if not running */
 public synchronized CountdownTimer pause() {
   if (stopwatch.isRunning()) stopwatch.stop();
   return this;
 }
コード例 #8
0
 /** starts the timer, either initially or if {@link #pause()}d; no-op if already running */
 public synchronized CountdownTimer start() {
   if (!stopwatch.isRunning()) stopwatch.start();
   return this;
 }