类com.google.common.util.concurrent.Atomics源码实例Demo

下面列出了怎么用com.google.common.util.concurrent.Atomics的API类实例代码及写法,或者点击链接到github查看源代码。

源代码1 项目: javaide   文件: Device.java
@Nullable
private String queryMountPoint(@NonNull final String name)
        throws TimeoutException, AdbCommandRejectedException, ShellCommandUnresponsiveException,
        IOException {

    final AtomicReference<String> ref = Atomics.newReference();
    executeShellCommand("echo $" + name, new MultiLineReceiver() { //$NON-NLS-1$
        @Override
        public boolean isCancelled() {
            return false;
        }

        @Override
        public void processNewLines(String[] lines) {
            for (String line : lines) {
                if (!line.isEmpty()) {
                    // this should be the only one.
                    ref.set(line);
                }
            }
        }
    });
    return ref.get();
}
 
@Provides
@Singleton
protected Supplier<CacheLoader<RegionAndName, Image>> provideRegionAndNameToImageSupplierCacheLoader(
         final RegionAndIdToImage delegate) {
   return Suppliers.<CacheLoader<RegionAndName, Image>>ofInstance(new CacheLoader<RegionAndName, Image>() {
      private final AtomicReference<AuthorizationException> authException = Atomics.newReference();

      @Override
      public Image load(final RegionAndName key) throws Exception {
         // raw lookup of an image
         Supplier<Image> rawSupplier = new Supplier<Image>() {
            @Override public Image get() {
               try {
                  return delegate.load(key);
               } catch (ExecutionException e) {
                  throw Throwables.propagate(e);
               }
            }
         };
         return new SetAndThrowAuthorizationExceptionSupplier<Image>(rawSupplier, authException).get();
      }

   });
}
 
源代码3 项目: attic-stratos   文件: GCEIaas.java
private Operation waitGCEOperationDone(Operation operation) {
    IaasProvider iaasInfo = getIaasProvider();
    Injector injector = ContextBuilder.newBuilder(iaasInfo.getProvider())
            .credentials(iaasInfo.getIdentity(), iaasInfo.getCredential())
            .buildInjector();
    Predicate<AtomicReference<Operation>> zoneOperationDonePredicate =
            injector.getInstance(Key.get(new TypeLiteral<Predicate<AtomicReference<Operation>>>() {
            }, Names.named("zone")));
    AtomicReference<Operation> operationReference = Atomics.newReference(operation);
    retry(zoneOperationDonePredicate, MAX_WAIT_TIME, 1, SECONDS).apply(operationReference);

    return operationReference.get();
}
 
源代码4 项目: attic-aurora   文件: Recovery.java
@Inject
RecoveryImpl(
    File backupDir,
    Function<Snapshot, TemporaryStorage> tempStorageFactory,
    Storage primaryStorage,
    SnapshotStore snapshotStore,
    Command shutDownNow) {

  this.backupDir = requireNonNull(backupDir);
  this.tempStorageFactory = requireNonNull(tempStorageFactory);
  this.recovery = Atomics.newReference();
  this.primaryStorage = requireNonNull(primaryStorage);
  this.snapshotStore = requireNonNull(snapshotStore);
  this.shutDownNow = requireNonNull(shutDownNow);
}
 
源代码5 项目: besu   文件: FlatTraceGenerator.java
private static FlatTrace.Context handleSelfDestruct(
    final TraceFrame traceFrame,
    final Deque<FlatTrace.Context> tracesContexts,
    final FlatTrace.Context currentContext,
    final List<FlatTrace.Builder> flatTraces) {

  final Action.Builder actionBuilder = currentContext.getBuilder().getActionBuilder();
  final Gas gasUsed =
      Gas.fromHexString(actionBuilder.getGas())
          .minus(traceFrame.getGasRemaining())
          .plus(traceFrame.getGasCost().orElse(Gas.ZERO));

  currentContext.setGasUsed(gasUsed.toLong());

  final Bytes32[] stack = traceFrame.getStack().orElseThrow();
  final Address refundAddress = toAddress(stack[stack.length - 1]);
  final FlatTrace.Builder subTraceBuilder =
      FlatTrace.builder()
          .type("suicide")
          .traceAddress(calculateSelfDescructAddress(tracesContexts));

  final AtomicReference<Wei> weiBalance = Atomics.newReference(Wei.ZERO);
  traceFrame
      .getMaybeRefunds()
      .ifPresent(refunds -> weiBalance.set(refunds.getOrDefault(refundAddress, Wei.ZERO)));

  final Action.Builder callingAction = tracesContexts.peekLast().getBuilder().getActionBuilder();
  final String actionAddress =
      getActionAddress(callingAction, traceFrame.getRecipient().toHexString());
  final Action.Builder subTraceActionBuilder =
      Action.builder()
          .address(actionAddress)
          .refundAddress(refundAddress.toString())
          .balance(TracingUtils.weiAsHex(weiBalance.get()));

  flatTraces.add(
      new FlatTrace.Context(subTraceBuilder.actionBuilder(subTraceActionBuilder)).getBuilder());
  final FlatTrace.Context lastContext = tracesContexts.removeLast();
  lastContext.getBuilder().incSubTraces();
  final FlatTrace.Context nextContext = tracesContexts.peekLast();
  if (nextContext != null) {
    nextContext.getBuilder().incSubTraces();
  }
  return nextContext;
}
 
 类方法
 同包方法