com.google.common.util.concurrent.Atomics Java Examples

The following examples show how to use com.google.common.util.concurrent.Atomics. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: Device.java    From javaide with GNU General Public License v3.0 6 votes vote down vote up
@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();
}
 
Example #2
Source File: AWSEC2ComputeServiceContextModule.java    From attic-stratos with Apache License 2.0 6 votes vote down vote up
@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();
      }

   });
}
 
Example #3
Source File: GCEIaas.java    From attic-stratos with Apache License 2.0 5 votes vote down vote up
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();
}
 
Example #4
Source File: Recovery.java    From attic-aurora with Apache License 2.0 5 votes vote down vote up
@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);
}
 
Example #5
Source File: FlatTraceGenerator.java    From besu with Apache License 2.0 4 votes vote down vote up
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;
}