本文整理汇总了Java中com.github.rholder.retry.RetryException类的典型用法代码示例。如果您正苦于以下问题:Java RetryException类的具体用法?Java RetryException怎么用?Java RetryException使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
RetryException类属于com.github.rholder.retry包,在下文中一共展示了RetryException类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: restore
import com.github.rholder.retry.RetryException; //导入依赖的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: run
import com.github.rholder.retry.RetryException; //导入依赖的package包/类
@Override
protected List<QueryResponse> run() throws GraknClientException {
List<Query<?>> queryList = queries.stream().map(QueryRequest::getQuery)
.collect(Collectors.toList());
try {
return retryer.call(() -> {
try (Context c = graqlExecuteTimer.time()) {
return graknClient.graqlExecute(queryList, keyspace);
}
});
} catch (RetryException | ExecutionException e) {
Throwable cause = e.getCause();
if (cause instanceof GraknClientException) {
throw (GraknClientException) cause;
} else {
throw new RuntimeException("Unexpected exception while retrying, " + queryList.size() + " queries failed.", e);
}
} finally {
queries.forEach(QueryRequest::releasePermit);
}
}
示例3: executeFunctionWithRetrying
import com.github.rholder.retry.RetryException; //导入依赖的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;
}
}
}
示例4: whenSending10Tasks_AllTaskStatesRetrievable
import com.github.rholder.retry.RetryException; //导入依赖的package包/类
@Test
public void whenSending10Tasks_AllTaskStatesRetrievable()
throws ExecutionException, RetryException, StateFutureInitializationException, InterruptedException {
Map<TaskId, Future<Void>> states = new HashMap<>();
for(int i = 0; i < 10; i++) {
TaskId generate = TaskId.generate();
TaskState state = TaskState.of(ShortExecutionMockTask.class, RedisTaskManagerTest.class.getName());
TaskId id = state.getId();
states.put(id, taskManager.subscribeToTask(id));
taskManager.addTask(state, testConfig(generate));
}
states.forEach((id, state) -> {
try {
System.out.println("Waiting for " + id);
state.get();
} catch (Exception e) {
fail("Failed to retrieve task in time");
}
assertTrue("Task retrieved but with unexpected state " + taskManager.storage().getState(id).status(), ImmutableSet.of(COMPLETED, RUNNING).contains(taskManager.storage().getState(id).status()));
});
}
示例5: invokeWithRetry
import com.github.rholder.retry.RetryException; //导入依赖的package包/类
private Response invokeWithRetry(Invocation request)
{
Retryer<Response> retryer = RetryerBuilder.<Response>newBuilder()
.retryIfException(not(DigdagClient::isDeterministicError))
.withWaitStrategy(exponentialWait())
.withStopStrategy(stopAfterAttempt(10))
.build();
try {
return retryer.call(() -> {
Response res = request.invoke();
if (res.getStatusInfo().getFamily() != SUCCESSFUL) {
res.close();
return handleErrorStatus(res);
}
return res;
});
}
catch (ExecutionException | RetryException e) {
Throwable cause = e.getCause() != null ? e.getCause() : e;
throw Throwables.propagate(cause);
}
}
示例6: createRemoteConnection
import com.github.rholder.retry.RetryException; //导入依赖的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);
}
}
示例7: list
import com.github.rholder.retry.RetryException; //导入依赖的package包/类
/**
* Return the ObjectListing starting at the given marker. The number of
* ObjectSummaries is bounded to be 1000 (this is the Amazon S3 default,
* which we're also setting here explicitly to minimize future SDK update
* implications).
*
* @param marker the last marker from a previous call or null
* @param limit return no more than this many
*/
public ObjectListing list(final String marker, final int limit) throws ExecutionException, RetryException {
return (ObjectListing) RetryUtils.AWS_RETRYER.call(new Callable<Object>() {
public ObjectListing call() throws Exception {
ListObjectsRequest lor = new ListObjectsRequest()
.withBucketName(bucket)
.withMarker(marker)
.withDelimiter("/")
.withMaxKeys(limit);
if (prefix != null) {
lor.withPrefix(prefix);
}
return amazonS3Client.listObjects(lor);
}
});
}
示例8: retry404
import com.github.rholder.retry.RetryException; //导入依赖的package包/类
@Test
public void retry404() throws ExecutionException, RetryException {
AWS_RETRYER.call(new Callable<Object>() {
@Override
public Object call() throws Exception {
if(tryCount < 2) {
tryCount++;
throw newExceptionWithCode(404);
} else {
return null;
}
}
});
Assert.assertEquals(2, tryCount);
}
示例9: retry501
import com.github.rholder.retry.RetryException; //导入依赖的package包/类
@Test
public void retry501() throws ExecutionException, RetryException {
AWS_RETRYER.call(new Callable<Object>() {
@Override
public Object call() throws Exception {
if(tryCount < 2) {
tryCount++;
throw newExceptionWithCode(501);
} else {
return null;
}
}
});
Assert.assertEquals(2, tryCount);
}
示例10: retryIOException
import com.github.rholder.retry.RetryException; //导入依赖的package包/类
@Test
public void retryIOException() throws ExecutionException, RetryException {
AWS_RETRYER.call(new Callable<Object>() {
@Override
public Object call() throws Exception {
if(tryCount < 2) {
tryCount++;
throw new IOException("disk on fire");
} else {
return null;
}
}
});
Assert.assertEquals(2, tryCount);
}
示例11: retryUnhandled
import com.github.rholder.retry.RetryException; //导入依赖的package包/类
@Test
public void retryUnhandled() throws ExecutionException, RetryException {
try {
AWS_RETRYER.call(new Callable<Object>() {
@Override
public Object call() throws Exception {
if (tryCount < 2) {
tryCount++;
throw new RuntimeException("wormhole opened up");
} else {
return null;
}
}
});
Assert.fail("Expected RuntimeException");
} catch (ExecutionException e) {
Assert.assertTrue(e.getMessage().contains("wormhole"));
}
Assert.assertEquals(1, tryCount);
}
示例12: invokeResponseCallable
import com.github.rholder.retry.RetryException; //导入依赖的package包/类
private Response invokeResponseCallable(final Callable<Response> responseCallable) {
final Retryer<Response> retryer = buildResponseRetryer();
try {
return retryer.call(responseCallable);
} catch (ExecutionException | RetryException e) {
throw new EbayException(RETRY_FAILED_MESSAGE, e);
}
}
示例13: uploadBatch
import com.github.rholder.retry.RetryException; //导入依赖的package包/类
private void uploadBatch(List<Path> toUpload) {
final long start = System.currentTimeMillis();
LOG.info("{} Uploading {} item(s)", logIdentifier, toUpload.size());
int success = 0;
for (int i = 0; i < toUpload.size(); i++) {
final Context context = metrics.getUploadTimer().time();
final Path file = toUpload.get(i);
if (!configuration.isCheckForOpenFiles() || !fileOpen(file)) {
try {
uploadSingle(i, file);
metrics.upload();
success++;
Files.delete(file);
} catch (S3ServiceException se) {
metrics.error();
LOG.warn("{} Couldn't upload {} due to {} ({}) - {}", logIdentifier, file, se.getErrorCode(), se.getResponseCode(), se.getErrorMessage(), se);
exceptionNotifier.notify(se, ImmutableMap.of("logIdentifier", logIdentifier, "file", file.toString(), "errorCode", se.getErrorCode(), "responseCode", Integer.toString(se.getResponseCode()), "errorMessage", se.getErrorMessage()));
} catch (RetryException re) {
metrics.error();
LOG.warn("{} Couldn't upload or delete {}", logIdentifier, file, re);
exceptionNotifier.notify(re.getCause(), ImmutableMap.of("logIdentifier", logIdentifier, "file", file.toString(), "failedAttempts", Integer.toString(re.getNumberOfFailedAttempts())));
} catch (Exception e) {
metrics.error();
LOG.warn("{} Couldn't upload or delete {}", logIdentifier, file, e);
exceptionNotifier.notify(e, ImmutableMap.of("logIdentifier", logIdentifier, "file", file.toString()));
} finally {
context.stop();
}
} else {
LOG.info("{} is in use by another process, will retry upload later", file);
}
}
LOG.info("{} Uploaded {} out of {} item(s) in {}", logIdentifier, success, toUpload.size(), JavaUtils.duration(start));
}
示例14: explainGraql
import com.github.rholder.retry.RetryException; //导入依赖的package包/类
@GET
@Path("/kb/{keyspace}/explain")
private String explainGraql(Request request, Response response) throws RetryException, ExecutionException {
Keyspace keyspace = Keyspace.of(mandatoryPathParameter(request, KEYSPACE_PARAM));
String queryString = mandatoryQueryParameter(request, QUERY);
response.status(SC_OK);
return executeFunctionWithRetrying(() -> {
try (GraknTx tx = factory.tx(keyspace, GraknTxType.WRITE); Timer.Context context = executeExplanation.time()) {
Answer answer = tx.graql().infer(true).parser().<GetQuery>parseQuery(queryString).execute().stream().findFirst().orElse(new QueryAnswer());
return mapper.writeValueAsString(ExplanationBuilder.buildExplanation(answer));
}
});
}
示例15: Fix
import com.github.rholder.retry.RetryException; //导入依赖的package包/类
@Ignore // TODO: Fix (Bug #16193)
@Test
public void whenAddingTask_TaskStateIsRetrievable() throws ExecutionException, RetryException {
TaskId generate = TaskId.generate();
TaskState state = TaskState.of(ShortExecutionMockTask.class, RedisTaskManagerTest.class.getName());
taskManager.addTask(state, testConfig(generate));
RETRY_STRATEGY.call(() -> taskManager.storage().getState(state.getId()) != null);
assertEquals(COMPLETED, taskManager.storage().getState(state.getId()).status());
}