Java Code Examples for org.springframework.util.backoff.FixedBackOff#setInterval()
The following examples show how to use
org.springframework.util.backoff.FixedBackOff#setInterval() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: FixedBackOffTests.java From spring-analysis-note with MIT License | 5 votes |
@Test public void liveUpdate() { FixedBackOff backOff = new FixedBackOff(100L, 1); BackOffExecution execution = backOff.start(); assertEquals(100L, execution.nextBackOff()); backOff.setInterval(200L); backOff.setMaxAttempts(2); assertEquals(200L, execution.nextBackOff()); assertEquals(BackOffExecution.STOP, execution.nextBackOff()); }
Example 2
Source File: FixedBackOffTests.java From java-technology-stack with MIT License | 5 votes |
@Test public void liveUpdate() { FixedBackOff backOff = new FixedBackOff(100L, 1); BackOffExecution execution = backOff.start(); assertEquals(100L, execution.nextBackOff()); backOff.setInterval(200L); backOff.setMaxAttempts(2); assertEquals(200L, execution.nextBackOff()); assertEquals(BackOffExecution.STOP, execution.nextBackOff()); }
Example 3
Source File: FixedBackOffTests.java From spring4-understanding with Apache License 2.0 | 5 votes |
@Test public void liveUpdate() { FixedBackOff backOff = new FixedBackOff(100L, 1); BackOffExecution execution = backOff.start(); assertEquals(100l, execution.nextBackOff()); backOff.setInterval(200l); backOff.setMaxAttempts(2); assertEquals(200l, execution.nextBackOff()); assertEquals(BackOffExecution.STOP, execution.nextBackOff()); }
Example 4
Source File: UserRolesSyncer.java From fiat with Apache License 2.0 | 4 votes |
public long syncAndReturn(List<String> roles) { FixedBackOff backoff = new FixedBackOff(); backoff.setInterval(retryIntervalMs); backoff.setMaxAttempts(Math.floorDiv(syncDelayTimeoutMs, retryIntervalMs) + 1); BackOffExecution backOffExec = backoff.start(); // after this point the execution will get rescheduled final long timeout = System.currentTimeMillis() + syncDelayTimeoutMs; if (!isServerHealthy()) { log.warn( "Server is currently UNHEALTHY. User permission role synchronization and " + "resolution may not complete until this server becomes healthy again."); } // Ensure we're going to reload app and service account definitions permissionsResolver.clearCache(); while (true) { try { Map<String, UserPermission> combo = new HashMap<>(); // force a refresh of the unrestricted user in case the backing repository is empty: combo.put(UnrestrictedResourceConfig.UNRESTRICTED_USERNAME, new UserPermission()); Map<String, UserPermission> temp; if (!(temp = getUserPermissions(roles)).isEmpty()) { combo.putAll(temp); } if (!(temp = getServiceAccountsAsMap(roles)).isEmpty()) { combo.putAll(temp); } return updateUserPermissions(combo); } catch (ProviderException | PermissionResolutionException ex) { registry .counter(metricName("syncFailure"), "cause", ex.getClass().getSimpleName()) .increment(); Status status = healthIndicator.health().getStatus(); long waitTime = backOffExec.nextBackOff(); if (waitTime == BackOffExecution.STOP || System.currentTimeMillis() > timeout) { String cause = (waitTime == BackOffExecution.STOP) ? "backoff-exhausted" : "timeout"; registry.counter("syncAborted", "cause", cause).increment(); 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(); } } }