Java 类org.apache.commons.lang3.concurrent.LazyInitializer 实例源码

项目:cassandra-reaper    文件:SegmentRunner.java   
private void handlePotentialStuckRepairs(LazyInitializer<Set<String>> busyHosts, String hostName)
    throws ConcurrentException {

  if (!busyHosts.get().contains(hostName) && context.storage instanceof IDistributedStorage) {
    try (JmxProxy hostProxy
        = context.jmxConnectionFactory.connect(hostName, context.config.getJmxConnectionTimeoutInSeconds())) {
      // We double check that repair is still running there before actually canceling repairs
      if (hostProxy.isRepairRunning()) {
        LOG.warn(
            "A host ({}) reported that it is involved in a repair, but there is no record "
                + "of any ongoing repair involving the host. Sending command to abort all repairs "
                + "on the host.",
            hostName);
        hostProxy.cancelAllRepairs();
        hostProxy.close();
      }
    } catch (ReaperException | RuntimeException | InterruptedException | JMException e) {
      LOG.debug("failed to cancel repairs on host {}", hostName, e);
    }
  }
}
项目:otj-data-structures    文件:Java8Util.java   
/**
 * Use a supplier to perform lazy instantiation of a value. Wraps the given
 * supplier in a new Supplier that has the lazy loading logic.
 */
public static <T> Supplier<T> lazy(Supplier<T> source) {
    return new Supplier<T>() {
        final LazyInitializer<T> init = new LazyInitializer<T>() {
            @Override
            protected T initialize() throws ConcurrentException {
                return source.get();
            }
        };

        @Override
        public T get() {
            try {
                return init.get();
            } catch (ConcurrentException e) {
                throw new IllegalStateException(e);
            }
        }
    };
}
项目:AndroidTestingBox    文件:Sum.java   
public Sum(int a, int b) {
    this.a = a;
    this.b = b;
    mSum = new LazyInitializer<Integer>() {
        @Override
        protected Integer initialize() throws ConcurrentException {
            return Sum.this.a + Sum.this.b;
        }
    };
}