本文整理汇总了Java中org.springframework.retry.RetryCallback类的典型用法代码示例。如果您正苦于以下问题:Java RetryCallback类的具体用法?Java RetryCallback怎么用?Java RetryCallback使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
RetryCallback类属于org.springframework.retry包,在下文中一共展示了RetryCallback类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: assertProcessEnded
import org.springframework.retry.RetryCallback; //导入依赖的package包/类
private void assertProcessEnded(final ProcessInstance pi) {
// fetch active executions
RetryTemplate retryTemplate = new RetryTemplate();
final SimpleRetryPolicy retryPolicy = new SimpleRetryPolicy();
retryPolicy.setMaxAttempts(5);
retryTemplate.setRetryPolicy(retryPolicy);
FixedBackOffPolicy backOffPolicy = new FixedBackOffPolicy();
retryTemplate.setBackOffPolicy(backOffPolicy);
retryTemplate.execute(new RetryCallback<Void, RuntimeException>() {
@Override
public Void doWithRetry(RetryContext retryContext) throws RuntimeException {
List<ProcessInstance> processInstances = runtimeService.createProcessInstanceQuery().list();
int processCount = processInstances.size();
LOGGER.info("waiting for process to end (Still {} process running).", processCount);
if (processCount > 0) {
for (ProcessInstance processInstance : processInstances) {
LOGGER.info("Process info: {} ", dumpprocessInstance(processInstance));
}
throw new IllegalStateException("Some process still running. Left :" + processCount);
}
return null;
}
});
}
示例2: invoke
import org.springframework.retry.RetryCallback; //导入依赖的package包/类
@Override
public Object invoke(Object proxy, final Method method,
final Object[] args) throws Throwable {
if (ReferenceBean.this.timeout > 0) {
return ReferenceBean.this.template
.execute(new RetryCallback<Object>() {
@Override
public Object doWithRetry(RetryContext context)
throws Exception {
return invokeService(method, args);
}
});
}
return invokeService(method, args);
}
示例3: getWithRetry
import org.springframework.retry.RetryCallback; //导入依赖的package包/类
public ExitStatus getWithRetry(RetryCallback<ExitStatus, Exception> callback) {
RetryTemplate retryTemplate = new RetryTemplate();
FixedBackOffPolicy backOffPolicy = new FixedBackOffPolicy();
Map<Class<? extends Throwable>,Boolean> retryableExceptions = new HashMap<Class<? extends Throwable>,Boolean>();
retryableExceptions.put(ClientProtocolException.class, Boolean.TRUE);
retryableExceptions.put(IOException.class, Boolean.TRUE);
SimpleRetryPolicy retryPolicy = new SimpleRetryPolicy(retryAttempts, retryableExceptions);
backOffPolicy.setBackOffPeriod(backoffPeriod);
retryTemplate.setListeners(retryListeners);
retryTemplate.setBackOffPolicy(backOffPolicy);
retryTemplate.setRetryPolicy(retryPolicy);
try {
return retryTemplate.execute(callback);
} catch (Exception e) {
logger.error("Retry processing failed " + e.getMessage());
return ExitStatus.FAILED;
}
}
示例4: within
import org.springframework.retry.RetryCallback; //导入依赖的package包/类
@Then("^the environment should be operational within (\\d+) minutes$")
public void thenTheEnvironmentShouldBeOperationalWithin(int timeout) {
TimeoutRetryPolicy retryPolicy = new TimeoutRetryPolicy();
// timeout in ms
retryPolicy.setTimeout(timeout * 1000 * 60);
retryTemplate.setRetryPolicy(retryPolicy);
// Then environment should be in a operational state
// we need to retry because environment creation is asynchronous
try {
retryTemplate.execute(new RetryCallback<Object, Exception>() {
@Override
public Object doWithRetry(RetryContext context) throws Exception {
logger.debug("asserts that environment is running....");
environmentDetailsPage.refresh();
assertTrue("environment status is still CREATING", !environmentDetailsPage.isCreating());
return null;
}
});
assertTrue("environment is not operational yet : " + environmentDetailsPage.statusMessage(), environmentDetailsPage.isOperational());
} catch (Exception e) {
throw new RuntimeException(e);
}
}
示例5: of
import org.springframework.retry.RetryCallback; //导入依赖的package包/类
@Then("^that environment should be running within a delay of (\\d+) minutes$")
public void thenTheEnvironmentShouldBeRunningWithinADelayOf(Integer timeoutInSec) throws Exception {
Assert.assertTrue(throwable == null);
// environment should be running before timeout
// we need to retry because environment creation is asynchronous
getRetryTemplate(timeoutInSec).execute(new RetryCallback<EnvironmentStatus, Exception>() {
@Override
public EnvironmentStatus doWithRetry(RetryContext context) throws Exception {
EnvironmentStatus status = getEnvironmentStatus(environmentUID);
logger.debug("environment status is " + status.getType());
logger.debug("environment status progress is " + status.getProgress());
logger.debug("environment status message is " + status.getMessage());
if (!isRunning(status) && (!isFailed(status))) {
throw new AssertionError("environment is not in required state; expected status was " + EnvironmentStatusEnum.RUNNING
+ "; actual status is " + status.getType() + " - status message is " + status.getMessage());
}
return status;
}
});
}
示例6: environmentShouldBeRemovedWithinADelayOf
import org.springframework.retry.RetryCallback; //导入依赖的package包/类
public void environmentShouldBeRemovedWithinADelayOf(Integer timeoutInSec, final String environmentUID) throws Exception {
// environment should be removed before timeout
// we need to retry because environment removal is asynchronous
getRetryTemplate(timeoutInSec).execute(new RetryCallback<EnvironmentStatus, Exception>() {
@Override
public EnvironmentStatus doWithRetry(RetryContext context) throws Exception {
EnvironmentStatus status = getEnvironmentStatus(environmentUID);
logger.debug("environment status is " + status.getType());
logger.debug("environment status progress is " + status.getProgress());
logger.debug("environment status message is " + status.getMessage());
if (!isRemoved(status) && (!isFailed(status))) {
throw new AssertionError("environment is not in required state; expected status was " + EnvironmentStatusEnum.REMOVED
+ "; actual status is " + status.getType() + " - status message is " + status.getMessage());
}
return status;
}
});
}
示例7: createRoute
import org.springframework.retry.RetryCallback; //导入依赖的package包/类
@Override
public RouteUri createRoute(final Route route, String spaceName) {
final CloudFoundryOperations cfClient = login(spaceName);
try {
return getRetryTemplate(MAX_RETRY).execute(new RetryCallback<RouteUri, CloudFoundryException>() {
@Override
public RouteUri doWithRetry(RetryContext context) throws CloudFoundryException {
if (context.getRetryCount() == 0) {
logger.info("creating cloud foundry route with uri <" + route.getUri() + ">");
cfClient.addRoute(route.getHost(), route.getDomain());
return new RouteUri(route.getUri());
} else {
RouteUri candidateRouteUri = route.candidateRouteUri();
logger.info("creating cloud foundry route with uri <" + candidateRouteUri + ">");
cfClient.addRoute(candidateRouteUri.getHost(), candidateRouteUri.getDomain());
return candidateRouteUri;
}
}
});
} finally {
cfClient.logout();
}
}
示例8: invokeWithRetrySupport
import org.springframework.retry.RetryCallback; //导入依赖的package包/类
public void invokeWithRetrySupport() {
LOG.info("Running WITH RETRY");
try {
retryTemplate.execute(new RetryCallback<Double>() {
public Double doWithRetry( RetryContext arg0 ) throws Exception {
LOG.info("\tRetry count -> {} ", arg0.getRetryCount());
return retryMethods.doRetrySupported();
}
});
} catch ( Exception e ) {
e.printStackTrace();
}
}
示例9: handleEvent
import org.springframework.retry.RetryCallback; //导入依赖的package包/类
@EventListener
@Async
public void handleEvent(ProjectRequestEvent event) {
String json = null;
try {
ProjectRequestDocument document = documentFactory.createDocument(event);
if (log.isDebugEnabled()) {
log.debug("Publishing " + document);
}
json = toJson(document);
RequestEntity<String> request = RequestEntity
.post(this.statsProperties.getElastic().getEntityUrl())
.contentType(MediaType.APPLICATION_JSON).body(json);
this.retryTemplate.execute((RetryCallback<Void, RuntimeException>) context -> {
restTemplate.exchange(request, String.class);
return null;
});
}
catch (Exception ex) {
log.warn(String.format(
"Failed to publish stat to index, document follows %n%n%s%n", json),
ex);
}
}
示例10: testInterruptFailingTries
import org.springframework.retry.RetryCallback; //导入依赖的package包/类
@Test
public void testInterruptFailingTries() throws Exception
{
Future<Client> result = executorService.submit(() ->
{
RetryCallback<Client, RuntimeException> fail = c ->
{
throw new MolgenisDataException();
};
return retryTemplate.execute(fail);
});
result.cancel(true);
try
{
result.get(100, TimeUnit.MILLISECONDS);
fail("Should throw cancellation exception!");
}
catch (CancellationException ignore)
{
}
assertTrue(result.isDone());
assertTrue(result.isCancelled());
}
示例11: execute
import org.springframework.retry.RetryCallback; //导入依赖的package包/类
@Override
public RepeatStatus execute(StepContribution contribution, ChunkContext chunkContext) throws Exception {
RetryTemplate retryTemplate = new RetryTemplate();
SimpleRetryPolicy retryPolicy = new SimpleRetryPolicy();
retryPolicy.setMaxAttempts(3);
retryTemplate.setRetryPolicy(retryPolicy);
// HINT: 재시도 정책을 지정해서 3번까지 재시도를 수행합니다.
//
List<Discount> discounts = retryTemplate.execute(new RetryCallback<List<Discount>>() {
@Override
public List<Discount> doWithRetry(RetryContext context) throws Exception {
return discountService.getDiscounts();
}
});
discountsHolder.setDiscounts(discounts);
return RepeatStatus.FINISHED;
}
示例12: open
import org.springframework.retry.RetryCallback; //导入依赖的package包/类
@Override
public <T, E extends Throwable> boolean open(RetryContext context,
RetryCallback<T, E> callback) {
if (log.isDebugEnabled()) {
log.debug("start call retryable function [{}]", callback);
}
return true;
}
示例13: close
import org.springframework.retry.RetryCallback; //导入依赖的package包/类
@Override
public <T, E extends Throwable> void close(RetryContext context,
RetryCallback<T, E> callback,
Throwable throwable) {
if (log.isDebugEnabled()) {
log.debug("finish call retryable function [{}], total retry times [{}]", callback,
context.getRetryCount() + 1);
}
}
示例14: onError
import org.springframework.retry.RetryCallback; //导入依赖的package包/类
@Override
public <T, E extends Throwable> void onError(RetryContext context,
RetryCallback<T, E> callback,
Throwable throwable) {
log.error("call retryable function [{}] failed after [{}] times call", callback, context.getRetryCount() + 1,
throwable);
}
示例15: execute
import org.springframework.retry.RetryCallback; //导入依赖的package包/类
@Override
@SuppressWarnings("unchecked")
public <T> T execute(final RedisCallback<T> action, final boolean exposeConnection, final boolean pipeline) {
if (this.retryOperations != null) {
try {
return this.retryOperations.execute(new RetryCallback<T, Exception>() {
@Override
public T doWithRetry(RetryContext context) throws Exception {
if (context.getRetryCount() > 0) {
logger.warn("Retry of Redis Operation. Retry Count = " + context.getRetryCount());
}
return RedisRetryTemplate.super.execute(action, exposeConnection, pipeline);
}
}, (RecoveryCallback<T>) this.recoveryCallback);
}
catch (Exception e) {
if (e instanceof RuntimeException) {
throw (RuntimeException) e;
}
throw new RedisSystemException("Unknown checked exception translated", e);
}
}
else {
return super.execute(action, exposeConnection, pipeline);
}
}