本文整理汇总了Java中com.github.rholder.retry.StopStrategies类的典型用法代码示例。如果您正苦于以下问题:Java StopStrategies类的具体用法?Java StopStrategies怎么用?Java StopStrategies使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
StopStrategies类属于com.github.rholder.retry包,在下文中一共展示了StopStrategies类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: restore
import com.github.rholder.retry.StopStrategies; //导入依赖的package包/类
@Override
public void restore() {
// Failing here means restarting the styx scheduler and replaying all events again. This is quite time consuming
// and distressing when deploying, so try hard.
final Retryer<Object> retryer = RetryerBuilder.newBuilder()
.retryIfException()
.withWaitStrategy(WaitStrategies.exponentialWait(10, TimeUnit.SECONDS))
.withStopStrategy(StopStrategies.stopAfterAttempt(10))
.withRetryListener(this::onRestorePollPodsAttempt)
.build();
try {
retryer.call(Executors.callable(this::tryPollPods));
} catch (ExecutionException | RetryException e) {
throw new RuntimeException(e);
}
}
示例2: executeFunctionWithRetrying
import com.github.rholder.retry.StopStrategies; //导入依赖的package包/类
private String executeFunctionWithRetrying(Callable<String> callable) throws RetryException, ExecutionException {
try {
Retryer<String> retryer = RetryerBuilder.<String>newBuilder()
.retryIfExceptionOfType(TemporaryWriteException.class)
.withRetryListener(retryLogger)
.withWaitStrategy(WaitStrategies.exponentialWait(100, 5, TimeUnit.MINUTES))
.withStopStrategy(StopStrategies.stopAfterAttempt(MAX_RETRY))
.build();
return retryer.call(callable);
} catch (ExecutionException e) {
Throwable cause = e.getCause();
if (cause instanceof RuntimeException) {
throw (RuntimeException) cause;
} else {
throw e;
}
}
}
示例3: execute
import com.github.rholder.retry.StopStrategies; //导入依赖的package包/类
@Override
public <T> Future<T> execute(final PowerBiOperation<T> val) {
// use a retryer to keep attempting to send data to powerBI if we receive a rate limit exception.
// use exponential backoff to create a window of time for the request to come through.
// TODO : the time to wait is actually in the response header, come back and add that value.
final Retryer<T> retryer = RetryerBuilder.<T>newBuilder()
// we are retrying on these exceptions because they are able to be handled by just retrying this callable
// again (assuming that the maximum retries value is greater than 1 and this isn't the last retry attempt
// before giving up.
.retryIfExceptionOfType(RateLimitExceededException.class)
.retryIfExceptionOfType(RequestAuthenticationException.class)
.withAttemptTimeLimiter(AttemptTimeLimiters.<T>fixedTimeLimit(maximumWaitTime, TimeUnit.MILLISECONDS))
.withStopStrategy(StopStrategies.stopAfterAttempt(maximumRetries))
.build();
return executor.submit(new Callable<T>() {
@Override
public T call() throws Exception {
return retryer.call(new PowerBiCallable<>(val, clientBuilder));
}
});
}
示例4: ensureRebuiltRetryer
import com.github.rholder.retry.StopStrategies; //导入依赖的package包/类
private Retryer<NoteDbChangeState> ensureRebuiltRetryer(Stopwatch sw) {
if (testEnsureRebuiltRetryer != null) {
return testEnsureRebuiltRetryer;
}
// Retry the ensureRebuilt step with backoff until half the timeout has
// expired, leaving the remaining half for the rest of the steps.
long remainingNanos = (MILLISECONDS.toNanos(timeoutMs) / 2) - sw.elapsed(NANOSECONDS);
remainingNanos = Math.max(remainingNanos, 0);
return RetryerBuilder.<NoteDbChangeState>newBuilder()
.retryIfException(e -> (e instanceof IOException) || (e instanceof OrmException))
.withWaitStrategy(
WaitStrategies.join(
WaitStrategies.exponentialWait(250, MILLISECONDS),
WaitStrategies.randomWait(50, MILLISECONDS)))
.withStopStrategy(StopStrategies.stopAfterDelay(remainingNanos, NANOSECONDS))
.build();
}
示例5: migrateToNoteDbFailsRebuildingOnceAndRetries
import com.github.rholder.retry.StopStrategies; //导入依赖的package包/类
@Test
public void migrateToNoteDbFailsRebuildingOnceAndRetries() throws Exception {
Change.Id id = createChange().getChange().getId();
Change c = db.changes().get(id);
c.setNoteDbState("deadbeefdeadbeefdeadbeefdeadbeefdeadbeef");
db.changes().update(Collections.singleton(c));
rebuilderWrapper.failNextUpdate();
migrator =
newMigrator(
RetryerBuilder.<NoteDbChangeState>newBuilder()
.retryIfException()
.withStopStrategy(StopStrategies.neverStop())
.build());
migrator.migrateToNoteDbPrimary(id);
assertNoteDbPrimary(id);
}
示例6: migrateToNoteDbFailsRebuildingAndStops
import com.github.rholder.retry.StopStrategies; //导入依赖的package包/类
@Test
public void migrateToNoteDbFailsRebuildingAndStops() throws Exception {
Change.Id id = createChange().getChange().getId();
Change c = db.changes().get(id);
c.setNoteDbState("deadbeefdeadbeefdeadbeefdeadbeefdeadbeef");
db.changes().update(Collections.singleton(c));
rebuilderWrapper.failNextUpdate();
migrator =
newMigrator(
RetryerBuilder.<NoteDbChangeState>newBuilder()
.retryIfException()
.withStopStrategy(StopStrategies.stopAfterAttempt(1))
.build());
exception.expect(OrmException.class);
exception.expectMessage("Retrying failed");
migrator.migrateToNoteDbPrimary(id);
}
示例7: failAfterRetryerGivesUp
import com.github.rholder.retry.StopStrategies; //导入依赖的package包/类
@Test
public void failAfterRetryerGivesUp() throws Exception {
AtomicInteger bgCounter = new AtomicInteger(1234);
RepoSequence s =
newSequence(
"id",
1,
10,
() -> writeBlob("id", Integer.toString(bgCounter.getAndAdd(1000))),
RetryerBuilder.<RefUpdate.Result>newBuilder()
.withStopStrategy(StopStrategies.stopAfterAttempt(3))
.build());
exception.expect(OrmException.class);
exception.expectMessage("failed to update refs/sequences/id: LOCK_FAILURE");
s.next();
}
示例8: increaseToFailAfterRetryerGivesUp
import com.github.rholder.retry.StopStrategies; //导入依赖的package包/类
@Test
public void increaseToFailAfterRetryerGivesUp() throws Exception {
AtomicInteger bgCounter = new AtomicInteger(1234);
RepoSequence s =
newSequence(
"id",
1,
10,
() -> writeBlob("id", Integer.toString(bgCounter.getAndAdd(1000))),
RetryerBuilder.<RefUpdate.Result>newBuilder()
.withStopStrategy(StopStrategies.stopAfterAttempt(3))
.build());
exception.expect(OrmException.class);
exception.expectMessage("failed to update refs/sequences/id: LOCK_FAILURE");
s.increaseTo(2);
}
示例9: createRemoteConnection
import com.github.rholder.retry.StopStrategies; //导入依赖的package包/类
@Override
public RemoteConnection createRemoteConnection(String remoteAddress, RemoteType remoteType,
LoginCredential loginCredential, int port) {
Callable<RemoteConnection> callable = () -> remoteConnectionFactory
.createRemoteConnection(remoteAddress, remoteType, loginCredential, port);
Retryer<RemoteConnection> remoteConnectionRetryer =
RetryerBuilder.<RemoteConnection>newBuilder().retryIfRuntimeException()
.retryIfException(throwable -> throwable instanceof RemoteException)
.withStopStrategy(StopStrategies.stopAfterAttempt(connectionRetries))
.withWaitStrategy(WaitStrategies
.exponentialWait(exponentialMultiplier, exponentialMaxTime, TimeUnit.SECONDS))
.build();
try {
return remoteConnectionRetryer.call(callable);
} catch (ExecutionException | RetryException e) {
throw new RuntimeException(e);
}
}
示例10: BaseJdbcBufferedInserter
import com.github.rholder.retry.StopStrategies; //导入依赖的package包/类
public BaseJdbcBufferedInserter(State state, Connection conn) {
this.conn = conn;
this.batchSize = state.getPropAsInt(WRITER_JDBC_INSERT_BATCH_SIZE, DEFAULT_WRITER_JDBC_INSERT_BATCH_SIZE);
if (this.batchSize < 1) {
throw new IllegalArgumentException(WRITER_JDBC_INSERT_BATCH_SIZE + " should be a positive number");
}
int maxWait = state.getPropAsInt(WRITER_JDBC_INSERT_RETRY_TIMEOUT, DEFAULT_WRITER_JDBC_INSERT_RETRY_TIMEOUT);
int maxAttempts =
state.getPropAsInt(WRITER_JDBC_INSERT_RETRY_MAX_ATTEMPT, DEFAULT_WRITER_JDBC_INSERT_RETRY_MAX_ATTEMPT);
//retry after 2, 4, 8, 16... sec, allow at most maxWait sec delay
this.retryer = RetryerBuilder.<Boolean> newBuilder().retryIfException()
.withWaitStrategy(WaitStrategies.exponentialWait(1000, maxWait, TimeUnit.SECONDS))
.withStopStrategy(StopStrategies.stopAfterAttempt(maxAttempts)).build();
}
示例11: createRetryBuilder
import com.github.rholder.retry.StopStrategies; //导入依赖的package包/类
/**
* @return RetryerBuilder that retries on all exceptions except NonTransientException with exponential back off
*/
public static RetryerBuilder<Void> createRetryBuilder(State state) {
Predicate<Throwable> transients = new Predicate<Throwable>() {
@Override
public boolean apply(Throwable t) {
return !(t instanceof NonTransientException);
}
};
long multiplier = state.getPropAsLong(RETRY_MULTIPLIER, 500L);
long maxWaitMsPerInterval = state.getPropAsLong(RETRY_MAX_WAIT_MS_PER_INTERVAL, 10000);
int maxAttempts = state.getPropAsInt(RETRY_MAX_ATTEMPTS, 5);
return RetryerBuilder.<Void> newBuilder()
.retryIfException(transients)
.withWaitStrategy(WaitStrategies.exponentialWait(multiplier, maxWaitMsPerInterval, TimeUnit.MILLISECONDS)) //1, 2, 4, 8, 16 seconds delay
.withStopStrategy(StopStrategies.stopAfterAttempt(maxAttempts)); //Total 5 attempts and fail.
}
示例12: mock
import com.github.rholder.retry.StopStrategies; //导入依赖的package包/类
public static void mock() {
Waits.setInstance(new Wait() {
@Override
public void time(Duration waitTime) {
// don't wait
}
@Override
@SuppressWarnings("unchecked")
protected <T> Retryer<T> getRetryer(Predicate<? super T> predicate, Duration timeout, Duration interval) {
int numRetries = (int) (timeout.getTime() / interval.getTime());
// we emulate the number of retries
return RetryerBuilder.<T> newBuilder()
.retryIfResult(Predicates.not((Predicate<T>) predicate))
.retryIfRuntimeException()
.withWaitStrategy(WaitStrategies.noWait())
.withStopStrategy(StopStrategies.stopAfterAttempt(numRetries))
.build();
}
});
}
示例13: SingularityClient
import com.github.rholder.retry.StopStrategies; //导入依赖的package包/类
public SingularityClient(String contextPath, HttpClient httpClient, Provider<List<String>> hostsProvider, Optional<SingularityClientCredentials> credentials, boolean ssl, int retryAttempts, Predicate<HttpResponse> retryStrategy) {
this.httpClient = httpClient;
this.contextPath = contextPath;
this.hostsProvider = hostsProvider;
this.random = new Random();
this.credentials = credentials;
this.ssl = ssl;
this.httpResponseRetryer = RetryerBuilder.<HttpResponse>newBuilder()
.withStopStrategy(StopStrategies.stopAfterAttempt(retryAttempts))
.withWaitStrategy(WaitStrategies.exponentialWait())
.retryIfResult(retryStrategy::test)
.retryIfException()
.build();
}
示例14: notifyService
import com.github.rholder.retry.StopStrategies; //导入依赖的package包/类
public void notifyService(String action) throws Exception {
long start = System.currentTimeMillis();
Retryer<AgentCheckInResponse> retryer = RetryerBuilder.<AgentCheckInResponse>newBuilder()
.retryIfException()
.withStopStrategy(StopStrategies.stopAfterAttempt(configuration.getMaxNotifyServiceAttempts()))
.withWaitStrategy(WaitStrategies.exponentialWait(1, TimeUnit.SECONDS))
.build();
AgentCheckInResponse agentCheckInResponse = retryer.call(checkInCallable(action, false));
while ((agentCheckInResponse.getState() != TrafficSourceState.DONE
&& System.currentTimeMillis() - start < configuration.getAgentCheckInTimeoutMs())) {
try {
Thread.sleep(agentCheckInResponse.getWaitTime());
} catch (InterruptedException ie) {
LOG.error("Interrupted waiting for check in with service, shutting down early");
break;
}
agentCheckInResponse = retryer.call(checkInCallable(action, true));
}
LOG.info("Finished agent check in");
}
示例15: getGlobalStateWithRetry
import com.github.rholder.retry.StopStrategies; //导入依赖的package包/类
private Collection<BaragonServiceState> getGlobalStateWithRetry() throws AgentServiceNotifyException {
Callable<Collection<BaragonServiceState>> callable = new Callable<Collection<BaragonServiceState>>() {
public Collection<BaragonServiceState> call() throws Exception {
return getGlobalState();
}
};
Retryer<Collection<BaragonServiceState>> retryer = RetryerBuilder.<Collection<BaragonServiceState>>newBuilder()
.retryIfException()
.withStopStrategy(StopStrategies.stopAfterAttempt(configuration.getMaxGetGloablStateAttempts()))
.withWaitStrategy(WaitStrategies.exponentialWait(1, TimeUnit.SECONDS))
.build();
try {
return retryer.call(callable);
} catch (Exception e) {
LOG.error("Could not get global state from Baragon Service");
throw Throwables.propagate(e);
}
}