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

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

Introduction

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

Prototype

public void setInterval(long interval) 

Source Link

Document

Set the interval between two attempts in milliseconds.

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