Example usage for org.springframework.util.backoff BackOffExecution STOP

List of usage examples for org.springframework.util.backoff BackOffExecution STOP

Introduction

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

Prototype

long STOP

To view the source code for org.springframework.util.backoff BackOffExecution STOP.

Click Source Link

Document

Return value of #nextBackOff() that indicates that the operation should not be retried.

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.");
    }/* w  w w.  j  a  v a 2s .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();
        }
    }
}

From source file:org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainer.java

/**
 * Wait for a period determined by the {@link #setRecoveryInterval(long) recoveryInterval}
 * or {@link #setRecoveryBackOff(BackOff)} to give the container a
 * chance to recover from consumer startup failure, e.g. if the broker is down.
 * @param backOffExecution the BackOffExecution to get the {@code recoveryInterval}
 * @throws Exception if the shared connection still can't be established
 *//*from w w  w. j  ava  2 s .co  m*/
protected void handleStartupFailure(BackOffExecution backOffExecution) throws Exception {
    long recoveryInterval = backOffExecution.nextBackOff();
    if (BackOffExecution.STOP == recoveryInterval) {
        synchronized (this) {
            if (isActive()) {
                logger.warn("stopping container - restart recovery attempts exhausted");
                stop();
            }
        }
        return;
    }
    try {
        if (logger.isDebugEnabled() && isActive()) {
            logger.debug("Recovering consumer in " + recoveryInterval + " ms.");
        }
        long timeout = System.currentTimeMillis() + recoveryInterval;
        while (isActive() && System.currentTimeMillis() < timeout) {
            Thread.sleep(200);
        }
    } catch (InterruptedException e) {
        Thread.currentThread().interrupt();
        throw new IllegalStateException("Unrecoverable interruption on consumer restart");
    }
}