当前位置: 首页>>代码示例>>Java>>正文


Java Stopwatch.isRunning方法代码示例

本文整理汇总了Java中com.google.common.base.Stopwatch.isRunning方法的典型用法代码示例。如果您正苦于以下问题:Java Stopwatch.isRunning方法的具体用法?Java Stopwatch.isRunning怎么用?Java Stopwatch.isRunning使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.google.common.base.Stopwatch的用法示例。


在下文中一共展示了Stopwatch.isRunning方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: call

import com.google.common.base.Stopwatch; //导入方法依赖的package包/类
/**
 * Connects to the Adserver.
 * 
 * @return Optional of {@link AdProviderReader}
 * @throws BidProcessingException
 */
public Optional<AdProviderReader> call() throws BidProcessingException {
	final Stopwatch stopwatch = Stopwatch.createStarted();
	try {

		final String result = jsonGetConnector.connect(uriBuilder);
		final AdProviderReader adProvider = gson.fromJson(result, AdservingCampaignProvider.class);
		stopwatch.stop();
		return Optional.ofNullable(adProvider);
	} catch (final BidProcessingException e) {
		throw e;
	} finally {
		if (stopwatch.isRunning()) {
			stopwatch.stop();
		}
	}
}
 
开发者ID:ad-tech-group,项目名称:openssp,代码行数:23,代码来源:AdserverBroker.java

示例2: pushConfigWithConflictingVersionRetries

import com.google.common.base.Stopwatch; //导入方法依赖的package包/类
private synchronized boolean pushConfigWithConflictingVersionRetries(final ConfigSnapshotHolder configSnapshotHolder) throws ConfigSnapshotFailureException {
    ConflictingVersionException lastException;
    Stopwatch stopwatch = Stopwatch.createUnstarted();
    do {
        //TODO wait untill all expected modules are in yangStoreService, do we even need to with yangStoreService instead on netconfOperationService?
        String idForReporting = configSnapshotHolder.toString();
        SortedSet<String> expectedCapabilities = checkNotNull(configSnapshotHolder.getCapabilities(),
                "Expected capabilities must not be null - %s, check %s", idForReporting,
                configSnapshotHolder.getClass().getName());

        // wait max time for required capabilities to appear
        waitForCapabilities(expectedCapabilities, idForReporting);
        try {
            if(!stopwatch.isRunning()) {
                stopwatch.start();
            }
            return pushConfig(configSnapshotHolder);
        } catch (final ConflictingVersionException e) {
            lastException = e;
            LOG.info("Conflicting version detected, will retry after timeout");
            sleep();
        }
    } while (stopwatch.elapsed(TimeUnit.MILLISECONDS) < conflictingVersionTimeoutMillis);
    throw new IllegalStateException("Max wait for conflicting version stabilization timeout after " + stopwatch.elapsed(TimeUnit.MILLISECONDS) + " ms",
            lastException);
}
 
开发者ID:hashsdn,项目名称:hashsdn-controller,代码行数:27,代码来源:ConfigPusherImpl.java

示例3: startupTimes

import com.google.common.base.Stopwatch; //导入方法依赖的package包/类
ImmutableMap<Service, Long> startupTimes() {
  List<Entry<Service, Long>> loadTimes;
  monitor.enter();
  try {
    loadTimes = Lists.newArrayListWithCapacity(startupTimers.size());
    // N.B. There will only be an entry in the map if the service has started
    for (Entry<Service, Stopwatch> entry : startupTimers.entrySet()) {
      Service service = entry.getKey();
      Stopwatch stopWatch = entry.getValue();
      if (!stopWatch.isRunning() && !(service instanceof NoOpService)) {
        loadTimes.add(Maps.immutableEntry(service, stopWatch.elapsed(MILLISECONDS)));
      }
    }
  } finally {
    monitor.leave();
  }
  Collections.sort(
      loadTimes,
      Ordering.natural()
          .onResultOf(
              new Function<Entry<Service, Long>, Long>() {
                @Override
                public Long apply(Map.Entry<Service, Long> input) {
                  return input.getValue();
                }
              }));
  return ImmutableMap.copyOf(loadTimes);
}
 
开发者ID:zugzug90,项目名称:guava-mock,代码行数:29,代码来源:ServiceManager.java

示例4: getShareStopwatch

import com.google.common.base.Stopwatch; //导入方法依赖的package包/类
private static Stopwatch getShareStopwatch() {
  Stopwatch share = CacheUtil.cache(TimingUtil.class, Thread.currentThread(), () -> Stopwatch.createUnstarted());
  return share.isRunning() ? Stopwatch.createUnstarted() : share;
}
 
开发者ID:XDean,项目名称:Java-EX,代码行数:5,代码来源:TimingUtil.java

示例5: transitionService

import com.google.common.base.Stopwatch; //导入方法依赖的package包/类
/**
 * Updates the state with the given service transition.
 *
 * <p>This method performs the main logic of ServiceManager in the following steps.
 * <ol>
 * <li>Update the {@link #servicesByState()}
 * <li>Update the {@link #startupTimers}
 * <li>Based on the new state queue listeners to run
 * <li>Run the listeners (outside of the lock)
 * </ol>
 */
void transitionService(final Service service, State from, State to) {
  checkNotNull(service);
  checkArgument(from != to);
  monitor.enter();
  try {
    transitioned = true;
    if (!ready) {
      return;
    }
    // Update state.
    checkState(
        servicesByState.remove(from, service),
        "Service %s not at the expected location in the state map %s",
        service,
        from);
    checkState(
        servicesByState.put(to, service),
        "Service %s in the state map unexpectedly at %s",
        service,
        to);
    // Update the timer
    Stopwatch stopwatch = startupTimers.get(service);
    if (stopwatch == null) {
      // This means the service was started by some means other than ServiceManager.startAsync
      stopwatch = Stopwatch.createStarted();
      startupTimers.put(service, stopwatch);
    }
    if (to.compareTo(RUNNING) >= 0 && stopwatch.isRunning()) {
      // N.B. if we miss the STARTING event then we may never record a startup time.
      stopwatch.stop();
      if (!(service instanceof NoOpService)) {
        logger.log(Level.FINE, "Started {0} in {1}.", new Object[] {service, stopwatch});
      }
    }
    // Queue our listeners

    // Did a service fail?
    if (to == FAILED) {
      enqueueFailedEvent(service);
    }

    if (states.count(RUNNING) == numberOfServices) {
      // This means that the manager is currently healthy. N.B. If other threads call isHealthy
      // they are not guaranteed to get 'true', because any service could fail right now.
      enqueueHealthyEvent();
    } else if (states.count(TERMINATED) + states.count(FAILED) == numberOfServices) {
      enqueueStoppedEvent();
    }
  } finally {
    monitor.leave();
    // Run our executors outside of the lock
    dispatchListenerEvents();
  }
}
 
开发者ID:zugzug90,项目名称:guava-mock,代码行数:66,代码来源:ServiceManager.java

示例6: transitionService

import com.google.common.base.Stopwatch; //导入方法依赖的package包/类
/**
 * Updates the state with the given service transition.
 *
 * <p>This method performs the main logic of ServiceManager in the following steps.
 * <ol>
 * <li>Update the {@link #servicesByState()}
 * <li>Update the {@link #startupTimers}
 * <li>Based on the new state queue listeners to run
 * <li>Run the listeners (outside of the lock)
 * </ol>
 */
void transitionService(final Service service, State from, State to) {
  checkNotNull(service);
  checkArgument(from != to);
  monitor.enter();
  try {
    transitioned = true;
    if (!ready) {
      return;
    }
    // Update state.
    checkState(
        servicesByState.remove(from, service),
        "Service %s not at the expected location in the state map %s",
        service,
        from);
    checkState(
        servicesByState.put(to, service),
        "Service %s in the state map unexpectedly at %s",
        service,
        to);
    // Update the timer
    Stopwatch stopwatch = startupTimers.get(service);
    if (stopwatch == null) {
      // This means the service was started by some means other than ServiceManager.startAsync
      stopwatch = Stopwatch.createStarted();
      startupTimers.put(service, stopwatch);
    }
    if (to.compareTo(RUNNING) >= 0 && stopwatch.isRunning()) {
      // N.B. if we miss the STARTING event then we may never record a startup time.
      stopwatch.stop();
      if (!(service instanceof NoOpService)) {
        logger.log(Level.FINE, "Started {0} in {1}.", new Object[] {service, stopwatch});
      }
    }
    // Queue our listeners

    // Did a service fail?
    if (to == FAILED) {
      fireFailedListeners(service);
    }

    if (states.count(RUNNING) == numberOfServices) {
      // This means that the manager is currently healthy. N.B. If other threads call isHealthy
      // they are not guaranteed to get 'true', because any service could fail right now.
      fireHealthyListeners();
    } else if (states.count(TERMINATED) + states.count(FAILED) == numberOfServices) {
      fireStoppedListeners();
    }
  } finally {
    monitor.leave();
    // Run our executors outside of the lock
    executeListeners();
  }
}
 
开发者ID:paul-hammant,项目名称:googles-monorepo-demo,代码行数:66,代码来源:ServiceManager.java


注:本文中的com.google.common.base.Stopwatch.isRunning方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。