当前位置: 首页>>代码示例>>Java>>正文


Java RetryCallback类代码示例

本文整理汇总了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;
        }
    });
}
 
开发者ID:orange-cloudfoundry,项目名称:elpaaso-core,代码行数:25,代码来源:ErrorCatchingTest.java

示例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);
}
 
开发者ID:vmware,项目名称:ward,代码行数:17,代码来源:ReferenceBean.java

示例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;
	}
}
 
开发者ID:RBGKew,项目名称:powop,代码行数:22,代码来源:GetResourceClient.java

示例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);
	}
}
 
开发者ID:orange-cloudfoundry,项目名称:elpaaso-core,代码行数:27,代码来源:EnvironmentStoriesSteps.java

示例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;
		}
	});

}
 
开发者ID:orange-cloudfoundry,项目名称:elpaaso-core,代码行数:23,代码来源:EnvironmentStoriesSteps.java

示例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;
		}
	});
}
 
开发者ID:orange-cloudfoundry,项目名称:elpaaso-core,代码行数:20,代码来源:CleanupStoriesSteps.java

示例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();
    }
}
 
开发者ID:orange-cloudfoundry,项目名称:elpaaso-core,代码行数:24,代码来源:CfAdapterImpl.java

示例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();
	}

}
 
开发者ID:szaqal,项目名称:KitchenSink,代码行数:17,代码来源:App.java

示例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);
	}
}
 
开发者ID:spring-io,项目名称:initializr,代码行数:27,代码来源:ProjectGenerationStatPublisher.java

示例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());
}
 
开发者ID:molgenis,项目名称:molgenis,代码行数:25,代码来源:ConnectionRetryConfigTest.java

示例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;
}
 
开发者ID:debop,项目名称:spring-batch-experiments,代码行数:21,代码来源:DiscountsWithRetryTemplateTasklet.java

示例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;
}
 
开发者ID:srarcbrsent,项目名称:tc,代码行数:9,代码来源:TcRetryLogListener.java

示例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);
    }
}
 
开发者ID:srarcbrsent,项目名称:tc,代码行数:10,代码来源:TcRetryLogListener.java

示例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);
}
 
开发者ID:srarcbrsent,项目名称:tc,代码行数:8,代码来源:TcRetryLogListener.java

示例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);
	}
}
 
开发者ID:spring-projects,项目名称:spring-analytics,代码行数:29,代码来源:RedisRetryTemplate.java


注:本文中的org.springframework.retry.RetryCallback类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。