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

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

Introduction

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

Prototype

public FixedBackOff() 

Source Link

Document

Create an instance with an interval of #DEFAULT_INTERVAL ms and an unlimited number of attempts.

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.");
    }//from ww  w  . j  a v  a 2 s . c o  m

    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();
        }
    }
}