Example usage for com.google.common.util.concurrent Atomics newReference

List of usage examples for com.google.common.util.concurrent Atomics newReference

Introduction

In this page you can find the example usage for com.google.common.util.concurrent Atomics newReference.

Prototype

public static <V> AtomicReference<V> newReference() 

Source Link

Document

Creates an AtomicReference instance with no initial value.

Usage

From source file:org.jclouds.scriptbuilder.functions.CredentialsFromAdminAccess.java

@Override
public Credentials apply(@Nullable Statement input) {
    if (input == null)
        return null;
    if (input instanceof AcceptsStatementVisitor) {
        final AtomicReference<Credentials> credsHolder = Atomics.newReference();
        AcceptsStatementVisitor.class.cast(input).accept(new StatementVisitor() {

            @Override/*from   www. jav a 2s  .  c  o  m*/
            public void visit(Statement in) {
                if (credsHolder.get() == null) {
                    Credentials creds = apply(in);
                    if (creds != null)
                        credsHolder.set(creds);
                }
            }

        });
        return credsHolder.get();
    } else if (input instanceof AdminAccess) {
        return AdminAccess.class.cast(input).getAdminCredentials();
    } else {
        return null;
    }
}

From source file:com.android.tools.idea.debug.AnnotationsRenderer.java

@NotNull
private static Result renderIntDefAnnotation(@NotNull final PsiAnnotation annotation, final int value) {
    final AtomicReference<AndroidResolveHelper.IntDefResolution> valuesRef = Atomics.newReference();

    ApplicationManager.getApplication().runReadAction(new Runnable() {
        @Override/*from  w w w. ja  v  a2s.  c o m*/
        public void run() {
            valuesRef.set(AndroidResolveHelper.resolveIntDef(annotation));
        }
    });

    AndroidResolveHelper.IntDefResolution intDef = valuesRef.get();
    if (intDef.valuesMap == null) {
        renderUnknown("IntDef", value);
    }

    return new Result(String.format(Locale.US, "0x%1$08x {%2$s}", value, renderIntDef(value, intDef)), null);
}

From source file:com.google.gerrit.sshd.AliasCommand.java

AliasCommand(@CommandName(Commands.ROOT) DispatchCommandProvider root, Provider<CurrentUser> currentUser,
        CommandName command) {//from  www  .j a  v a2s. c o m
    this.root = root;
    this.currentUser = currentUser;
    this.command = command;
    this.atomicCmd = Atomics.newReference();
}

From source file:com.googlesource.gerrit.plugins.replication.OnStartStop.java

@Inject
protected OnStartStop(ServerInformation srvInfo, PushAll.Factory pushAll, ReplicationQueue queue,
        ReplicationConfig config, DynamicItem<EventDispatcher> eventDispatcher) {
    this.srvInfo = srvInfo;
    this.pushAll = pushAll;
    this.queue = queue;
    this.config = config;
    this.eventDispatcher = eventDispatcher;
    this.pushAllFuture = Atomics.newReference();
}

From source file:com.google.gerrit.sshd.DispatchCommand.java

@Inject
DispatchCommand(final Provider<CurrentUser> cu, @Assisted final Map<String, CommandProvider> all) {
    currentUser = cu;/*from w ww . ja v  a2  s.com*/
    commands = all;
    atomicCmd = Atomics.newReference();
}

From source file:org.jclouds.http.functions.ParseFirstJsonValueNamed.java

@Override
public T apply(HttpResponse arg0) {
    if (arg0.getPayload() == null)
        return nothing();
    JsonReader reader = null;/*from  ww w. ja  v a 2 s  .com*/
    try {
        reader = new JsonReader(new InputStreamReader(arg0.getPayload().getInput()));
        // in case keys are not in quotes
        reader.setLenient(true);
        AtomicReference<String> name = Atomics.newReference();
        JsonToken token = reader.peek();
        for (; token != JsonToken.END_DOCUMENT
                && nnn(reader, token, name); token = skipAndPeek(token, reader)) {
        }
        if (name.get() == null) {
            logger.trace("did not object named %s in json from response %s", nameChoices, arg0);
            return nothing();
        } else if (nameChoices.contains(name.get())) {
            return json.delegate().<T>fromJson(reader, type.getType());
        } else {
            return nothing();
        }
    } catch (IOException e) {
        throw new RuntimeException(
                String.format("error reading from stream, parsing object named %s from http response %s",
                        nameChoices, arg0),
                e);
    } finally {
        Closeables.closeQuietly(reader);
        arg0.getPayload().release();
    }
}

From source file:com.google.gerrit.sshd.SuExec.java

@Inject
SuExec(final SshScope sshScope, @CommandName(Commands.ROOT) final DispatchCommandProvider dispatcher,
        final Provider<CurrentUser> caller, final Provider<SshSession> session,
        final IdentifiedUser.GenericFactory userFactory, final SshScope.Context callingContext) {
    this.sshScope = sshScope;
    this.dispatcher = dispatcher;
    this.caller = caller;
    this.session = session;
    this.userFactory = userFactory;
    this.callingContext = callingContext;
    atomicCmd = Atomics.newReference();
}

From source file:com.gitblit.transport.ssh.commands.BaseCommand.java

public BaseCommand() {
     task = Atomics.newReference();
 }

From source file:org.jclouds.ec2.compute.functions.PasswordCredentialsFromWindowsInstance.java

@Override
public LoginCredentials apply(final RunningInstance instance) {
    Optional<? extends WindowsApi> windowsOption = ec2Api.getWindowsApiForRegion(instance.getRegion());
    checkState(windowsOption.isPresent(), "windows feature not present in region %s", instance.getRegion());

    final WindowsApi windowsApi = windowsOption.get();

    LoginCredentials credentials = LoginCredentials.builder().user("Administrator").noPrivateKey().build();
    String privateKey = getPrivateKeyOrNull(instance);
    if (privateKey == null) {
        return credentials;
    }/*from  ww  w . j a  v a2s .  c  o  m*/
    // The Administrator password will take some time before it is ready - Amazon says
    // sometimes
    // 15 minutes.
    // So we create a predicate that tests if the password is ready, and wrap it in a retryable
    // predicate.
    final AtomicReference<PasswordData> data = Atomics.newReference();
    Predicate<String> passwordReady = new Predicate<String>() {
        @Override
        public boolean apply(@Nullable String s) {
            if (Strings.isNullOrEmpty(s))
                return false;
            data.set(windowsApi.getPasswordDataForInstance(instance.getId()));
            if (data.get() == null)
                return false;
            return !Strings.isNullOrEmpty(data.get().getPasswordData());
        }
    };

    // TODO: parameterize
    Predicate<String> passwordReadyRetryable = retry(passwordReady, 600, 10, SECONDS);

    logger.debug(">> awaiting password data for instance(%s/%s)", instance.getRegion(), instance.getId());
    if (passwordReadyRetryable.apply(instance.getId())) {
        credentials = pwDataToLoginCredentials.apply(new PasswordDataAndPrivateKey(data.get(), privateKey));
        logger.debug("<< obtained password data for instance(%s/%s)", instance.getRegion(), instance.getId());
    } else {
        logger.debug("<< unable to get password data for instance(%s/%s)", instance.getRegion(),
                instance.getId());
    }
    return credentials;
}

From source file:com.google.gerrit.sshd.BaseCommand.java

public BaseCommand() {
    task = Atomics.newReference();
}