Example usage for org.springframework.util.backoff FixedBackOff start

List of usage examples for org.springframework.util.backoff FixedBackOff start

Introduction

In this page you can find the example usage for org.springframework.util.backoff FixedBackOff start.

Prototype

@Override
    public BackOffExecution start() 

Source Link

Usage

From source file:com.netflix.spinnaker.fiat.roles.UserRolesSyncer.java

public long syncAndReturn() {
    FixedBackOff backoff = new FixedBackOff();
    backoff.setInterval(retryIntervalMs);
    BackOffExecution backOffExec = backoff.start();

    if (!isServerHealthy()) {
        log.warn("Server is currently UNHEALTHY. User permission role synchronization and "
                + "resolution may not complete until this server becomes healthy again.");
    }/*ww w .ja v  a2 s . c om*/

    while (true) {
        try {
            Map<String, UserPermission> combo = new HashMap<>();
            Map<String, UserPermission> temp;
            if (!(temp = getUserPermissions()).isEmpty()) {
                combo.putAll(temp);
            }
            if (!(temp = getServiceAccountsAsMap()).isEmpty()) {
                combo.putAll(temp);
            }

            return updateUserPermissions(combo);
        } catch (ProviderException | PermissionResolutionException ex) {
            Status status = healthIndicator.health().getStatus();
            long waitTime = backOffExec.nextBackOff();
            if (waitTime == BackOffExecution.STOP) {
                log.error("Unable to resolve service account permissions.", ex);
                return 0;
            }
            String message = new StringBuilder("User permission sync failed. ").append("Server status is ")
                    .append(status).append(". Trying again in ").append(waitTime).append(" ms. Cause:")
                    .append(ex.getMessage()).toString();
            if (log.isDebugEnabled()) {
                log.debug(message, ex);
            } else {
                log.warn(message);
            }

            try {
                Thread.sleep(waitTime);
            } catch (InterruptedException ignored) {
            }
        } finally {
            isServerHealthy();
        }
    }
}