Merge pull request #14 from rbkmoney/ft/BJ-718/move-backoff-to-lib

Move backOff to lib
This commit is contained in:
Kostya 2019-12-25 15:08:18 +03:00 committed by GitHub
commit 56d8dc81d6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 3 additions and 52 deletions

View File

@ -6,7 +6,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>com.rbkmoney</groupId>
<artifactId>adapter-bank-spring-boot-starter</artifactId>
<version>0.0.10</version>
<version>0.0.11</version>
<packaging>jar</packaging>
<properties>
@ -17,6 +17,7 @@
<damsel.version>1.363-3074af1</damsel.version>
<serializer.version>0.6.7</serializer.version>
<hellgate-adapter-client.version>2.1.10</hellgate-adapter-client.version>
<adapter-common-lib.version>0.0.14</adapter-common-lib.version>
</properties>
<dependencies>
@ -102,7 +103,7 @@
<dependency>
<groupId>com.rbkmoney</groupId>
<artifactId>adapter-common-lib</artifactId>
<version>0.0.13</version>
<version>${adapter-common-lib.version}</version>
</dependency>
<!-- test -->

View File

@ -1,50 +0,0 @@
package com.rbkmoney.adapter.bank.spring.boot.starter.backoff;
import com.rbkmoney.adapter.common.model.AdapterContext;
import com.rbkmoney.adapter.common.state.backoff.BackOffExecution;
import com.rbkmoney.adapter.common.state.backoff.ExponentialBackOff;
import com.rbkmoney.adapter.common.state.backoff.TimeOptionsExtractors;
import java.time.Instant;
import java.util.Map;
import static com.rbkmoney.adapter.common.state.backoff.ExponentialBackOff.*;
public class BackOffUtils {
public static BackOffExecution prepareBackOffExecution(
AdapterContext adapterContext,
Map<String, String> options) {
return exponentialBackOff(adapterContext, options)
.start();
}
public static int prepareNextPollingInterval(
AdapterContext adapterContext,
Map<String, String> options) {
return exponentialBackOff(adapterContext, options)
.start()
.nextBackOff()
.intValue();
}
private static ExponentialBackOff exponentialBackOff(
AdapterContext adapterContext,
Map<String, String> options) {
final Long currentLocalTime = Instant.now().toEpochMilli();
Long startTime = adapterContext.getStartDateTimePolling() != null
? adapterContext.getStartDateTimePolling().toEpochMilli()
: currentLocalTime;
Integer exponential = TimeOptionsExtractors.extractExponent(options, DEFAULT_EXPONENTIAL);
Integer defaultInitialExponential = TimeOptionsExtractors.extractDefaultInitialExponential(options, DEFAULT_INITIAL_EXPONENTIAL);
Integer maxTimeBackOff = TimeOptionsExtractors.extractMaxTimeBackOff(options, DEFAULT_MAX_TIME_BACK_OFF);
return new ExponentialBackOff(
startTime,
currentLocalTime,
exponential,
defaultInitialExponential,
maxTimeBackOff);
}
}