use of org.springframework.util.backoff.BackOffExecution in project pinpoint by naver.
the class OneByteFuzzyRowKeyFactory method allocateSlot.
private long[] allocateSlot() {
ExponentialBackOff exponentialBackOff = new ExponentialBackOff(100, 2);
exponentialBackOff.setMaxInterval(TimeUnit.MINUTES.toMillis(MAX_SLOT_TIME * 2));
BackOffExecution backOffExecution = exponentialBackOff.start();
final List<Long> backOffTimeList = new ArrayList<>();
for (int i = 0; i < MAX_SLOT; i++) {
final long nextBackOff = backOffExecution.nextBackOff();
backOffTimeList.add(nextBackOff);
if (MAX_SLOT_TIME <= nextBackOff) {
break;
}
}
return toLongArray(backOffTimeList);
}
use of org.springframework.util.backoff.BackOffExecution in project spring-framework by spring-projects.
the class DefaultMessageListenerContainer method refreshConnectionUntilSuccessful.
/**
* Refresh the underlying Connection, not returning before an attempt has been
* successful. Called in case of a shared Connection as well as without shared
* Connection, so either needs to operate on the shared Connection or on a
* temporary Connection that just gets established for validation purposes.
* <p>The default implementation retries until it successfully established a
* Connection, for as long as this message listener container is running.
* Applies the specified recovery interval between retries.
* @see #setRecoveryInterval
* @see #start()
* @see #stop()
*/
protected void refreshConnectionUntilSuccessful() {
BackOffExecution execution = this.backOff.start();
while (isRunning()) {
try {
if (sharedConnectionEnabled()) {
refreshSharedConnection();
} else {
Connection con = createConnection();
JmsUtils.closeConnection(con);
}
logger.debug("Successfully refreshed JMS Connection");
break;
} catch (Exception ex) {
if (ex instanceof JMSException) {
invokeExceptionListener((JMSException) ex);
}
StringBuilder msg = new StringBuilder();
msg.append("Could not refresh JMS Connection for destination '");
msg.append(getDestinationDescription()).append("' - retrying using ");
msg.append(execution).append(". Cause: ");
msg.append(ex instanceof JMSException ? JmsUtils.buildExceptionMessage((JMSException) ex) : ex.getMessage());
if (logger.isDebugEnabled()) {
logger.error(msg, ex);
} else {
logger.error(msg);
}
}
if (!applyBackOffTime(execution)) {
logger.error("Stopping container for destination '" + getDestinationDescription() + "': back-off policy does not allow for further attempts.");
stop();
}
}
}
use of org.springframework.util.backoff.BackOffExecution in project spring-framework by spring-projects.
the class ExponentialBackOffTests method maxAttemptsReached.
@Test
void maxAttemptsReached() {
ExponentialBackOff backOff = new ExponentialBackOff(2000L, 2.0);
backOff.setMaxElapsedTime(4000L);
BackOffExecution execution = backOff.start();
assertThat(execution.nextBackOff()).isEqualTo(2000L);
assertThat(execution.nextBackOff()).isEqualTo(4000L);
// > 4 sec wait in total
assertThat(execution.nextBackOff()).isEqualTo(BackOffExecution.STOP);
}
use of org.springframework.util.backoff.BackOffExecution in project spring-framework by spring-projects.
the class ExponentialBackOffTests method defaultInstance.
@Test
void defaultInstance() {
ExponentialBackOff backOff = new ExponentialBackOff();
BackOffExecution execution = backOff.start();
assertThat(execution.nextBackOff()).isEqualTo(2000L);
assertThat(execution.nextBackOff()).isEqualTo(3000L);
assertThat(execution.nextBackOff()).isEqualTo(4500L);
}
use of org.springframework.util.backoff.BackOffExecution in project spring-framework by spring-projects.
the class ExponentialBackOffTests method maxIntervalReached.
@Test
void maxIntervalReached() {
ExponentialBackOff backOff = new ExponentialBackOff(2000L, 2.0);
backOff.setMaxInterval(4000L);
BackOffExecution execution = backOff.start();
assertThat(execution.nextBackOff()).isEqualTo(2000L);
assertThat(execution.nextBackOff()).isEqualTo(4000L);
// max reached
assertThat(execution.nextBackOff()).isEqualTo(4000L);
assertThat(execution.nextBackOff()).isEqualTo(4000L);
}
Aggregations