• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Java RetryListener类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Java中org.springframework.retry.RetryListener的典型用法代码示例。如果您正苦于以下问题:Java RetryListener类的具体用法?Java RetryListener怎么用?Java RetryListener使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



RetryListener类属于org.springframework.retry包,在下文中一共展示了RetryListener类的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。

示例1: restCommand

import org.springframework.retry.RetryListener; //导入依赖的package包/类
/**
 * Utility method for building new {@link ApiCommand}s with most
 * of the boiler plate already setup. This method <em>MAY</em> do
 * command caching, but only if both cacheKey and commandCache
 * are not null.
 * @param uriProvider Provider getting service URIs.
 * @param callback The callback to execute.
 * @param listener Optional spring retry listener to intercept retries.
 * @param cacheKey Optional key to use for the CommandCache.
 * @param commandCache Optional CommandCache to use if desired.
 * @param commandName Name to use for the hystrix command.
 * @return Result of remote method call.
 */
public <T> ApiCommand.Builder<T> restCommand(
      UriProvider<T> uriProvider,
      RemoteServiceCallback<T> callback,
      RetryListener listener,
      Object cacheKey,
      CommandCache<?,?,?> commandCache,
      String commandName
)
{
   if (callback instanceof RestTemplateAware)
   {
      ((RestTemplateAware)callback).setRestTemplate(getRestTemplate(commandName));
   }
   return ApiCommand.<T>builder()
         .withHystrixCommandProperties(getConfiguration().getHystrixCommandProperties(commandName))
         .withHystrixThreadProperties(getConfiguration().getHystrixThreadPoolProperties(commandName))
         .withNumberOfRetries(getConfiguration().getNumRetries(commandName))
         .withUriProvider(uriProvider)
         .withCommandGroup(capitalizeName(getServiceName()) + "." + commandName)
         .withRetryListener(listener)
         .withRemoteServiceCallback(callback)
         .withCommandCache(commandCache, cacheKey);
}
 
开发者ID:HomeAdvisor,项目名称:Robusto,代码行数:37,代码来源:SpringRestClient.java


示例2: testGetDocumentAnyOtherStatus

import org.springframework.retry.RetryListener; //导入依赖的package包/类
/**
 *
    @throws IOException
 *             if a temporary file cannot be created or if there is a http
 *             protocol error.
 */
@Test
@Ignore
public final void testGetDocumentAnyOtherStatus() throws IOException {
	AttemptCountingRetryListener retryListener = new AttemptCountingRetryListener();
	File tempFile = File.createTempFile("test", "zip");
	tempFile.deleteOnExit();
	getResourceClient.setRetryListeners(new RetryListener[] { retryListener });

	ExitStatus exitStatus = getResourceClient.getResource("http://not.a.domain.invalid/test.zip",
					tempFile.getAbsolutePath(),
					Long.toString(new Date().getTime()));

	assertNotNull("ExitStatus should not be null.", exitStatus);
	assertEquals("ExitStatus should be FAILED.", ExitStatus.FAILED, exitStatus);
	assertEquals("There should be three retry attempts.", 3, retryListener.getErrors());
}
 
开发者ID:RBGKew,项目名称:powop,代码行数:23,代码来源:GetResourceClientIntegrationTest.java


示例3: createRetryOperations

import org.springframework.retry.RetryListener; //导入依赖的package包/类
protected RetryOperations createRetryOperations(RetryListener listener, int maxAttempts, List<Class<? extends Throwable>> retryableErrors) {
    Map<Class<? extends Throwable>, Boolean> retryableExceptions = new HashMap<>(retryableErrors.size());
    retryableErrors.forEach(error -> retryableExceptions.put(error, true));
    SimpleRetryPolicy retryPolicy = new SimpleRetryPolicy(maxAttempts, retryableExceptions);
    RetryTemplate retryTemplate = new RetryTemplate();
    retryTemplate.setRetryPolicy(retryPolicy);
    retryTemplate.registerListener(listener);
    return retryTemplate;
}
 
开发者ID:mkopylec,项目名称:charon-spring-boot-starter,代码行数:10,代码来源:CharonConfiguration.java


示例4: withRetryListener

import org.springframework.retry.RetryListener; //导入依赖的package包/类
/**
 * <i>Optional.</i> Adds the given {@link RetryListener} to the Spring
 * retry template. This allows you to intercept failures to do things
 * like custom logging, persistence, etc. By default no listeners are
 * registered. Can be called as many times as needed. The order of
 * execution of listeners is up to Spring.
 * @param listener
 * @return
 */
public Builder<T> withRetryListener(RetryListener listener)
{
   if(listener != null)
   {
      retryTemplate.registerListener(listener);
   }

   return this;
}
 
开发者ID:HomeAdvisor,项目名称:Robusto,代码行数:19,代码来源:ApiCommand.java


示例5: executeWithRetry

import org.springframework.retry.RetryListener; //导入依赖的package包/类
private OkHttpRibbonResponse executeWithRetry(OkHttpRibbonRequest request, LoadBalancedRetryPolicy retryPolicy,
											  RetryCallback<OkHttpRibbonResponse, Exception> callback) throws Exception {
	RetryTemplate retryTemplate = new RetryTemplate();
	BackOffPolicy backOffPolicy = loadBalancedBackOffPolicyFactory.createBackOffPolicy(this.getClientName());
	retryTemplate.setBackOffPolicy(backOffPolicy == null ? new NoBackOffPolicy() : backOffPolicy);
	RetryListener[] retryListeners = this.loadBalancedRetryListenerFactory.createRetryListeners(this.getClientName());
	if (retryListeners != null && retryListeners.length != 0) {
		retryTemplate.setListeners(retryListeners);
	}
	boolean retryable = request.getContext() == null ? true :
			BooleanUtils.toBooleanDefaultIfNull(request.getContext().getRetryable(), true);
	retryTemplate.setRetryPolicy(retryPolicy == null || !retryable ? new NeverRetryPolicy()
			: new RetryPolicy(request, retryPolicy, this, this.getClientName()));
	return retryTemplate.execute(callback);
}
 
开发者ID:spring-cloud,项目名称:spring-cloud-netflix,代码行数:16,代码来源:RetryableOkHttpLoadBalancingClient.java


示例6: executeWithRetry

import org.springframework.retry.RetryListener; //导入依赖的package包/类
private RibbonApacheHttpResponse executeWithRetry(RibbonApacheHttpRequest request, LoadBalancedRetryPolicy retryPolicy, RetryCallback<RibbonApacheHttpResponse, IOException> callback) throws Exception {
	RetryTemplate retryTemplate = new RetryTemplate();
	boolean retryable = request.getContext() == null ? true :
			BooleanUtils.toBooleanDefaultIfNull(request.getContext().getRetryable(), true);
	retryTemplate.setRetryPolicy(retryPolicy == null || !retryable ? new NeverRetryPolicy()
			: new RetryPolicy(request, retryPolicy, this, this.getClientName()));
	BackOffPolicy backOffPolicy = loadBalancedBackOffPolicyFactory.createBackOffPolicy(this.getClientName());
	retryTemplate.setBackOffPolicy(backOffPolicy == null ? new NoBackOffPolicy() : backOffPolicy);
	RetryListener[] retryListeners = this.loadBalancedRetryListenerFactory.createRetryListeners(this.getClientName());
	if (retryListeners != null && retryListeners.length != 0) {
		retryTemplate.setListeners(retryListeners);
	}
	return retryTemplate.execute(callback);
}
 
开发者ID:spring-cloud,项目名称:spring-cloud-netflix,代码行数:15,代码来源:RetryableRibbonLoadBalancingHttpClient.java


示例7: charonRetryOperations

import org.springframework.retry.RetryListener; //导入依赖的package包/类
@Bean
@ConditionalOnMissingBean(name = "charonRetryOperations")
public RetryOperations charonRetryOperations(@Qualifier("charonRetryListener") RetryListener listener) {
    return createRetryOperations(listener, charon.getRetrying().getMaxAttempts(), charon.getRetrying().getRetryOn().getExceptions());
}
 
开发者ID:mkopylec,项目名称:charon-spring-boot-starter,代码行数:6,代码来源:CharonConfiguration.java


示例8: charonDefaultRetryOperations

import org.springframework.retry.RetryListener; //导入依赖的package包/类
@Bean
@ConditionalOnMissingBean(name = "charonDefaultRetryOperations")
public RetryOperations charonDefaultRetryOperations(@Qualifier("charonRetryListener") RetryListener listener) {
    return createRetryOperations(listener, 1, emptyList());
}
 
开发者ID:mkopylec,项目名称:charon-spring-boot-starter,代码行数:6,代码来源:CharonConfiguration.java


示例9: charonRetryListener

import org.springframework.retry.RetryListener; //导入依赖的package包/类
@Bean
@ConditionalOnMissingBean
public RetryListener charonRetryListener() {
    return new LoggingListener(charon);
}
 
开发者ID:mkopylec,项目名称:charon-spring-boot-starter,代码行数:6,代码来源:CharonConfiguration.java


示例10: setRetryListeners

import org.springframework.retry.RetryListener; //导入依赖的package包/类
public void setRetryListeners(RetryListener[] retryListeners) {
	this.retryListeners = retryListeners;
}
 
开发者ID:RBGKew,项目名称:powop,代码行数:4,代码来源:GetResourceClient.java


示例11: createRetryListeners

import org.springframework.retry.RetryListener; //导入依赖的package包/类
@Override
public RetryListener[] createRetryListeners(String service) {
    return new RetryListener[0];
}
 
开发者ID:spring-cloud,项目名称:spring-cloud-commons,代码行数:5,代码来源:LoadBalancedRetryListenerFactory.java


示例12: execute

import org.springframework.retry.RetryListener; //导入依赖的package包/类
@Override
public RibbonResponse execute(final RibbonRequest request, IClientConfig configOverride)
		throws IOException {
	final Request.Options options;
	if (configOverride != null) {
		RibbonProperties ribbon = RibbonProperties.from(configOverride);
		options = new Request.Options(
				ribbon.connectTimeout(this.connectTimeout),
				ribbon.readTimeout(this.readTimeout));
	}
	else {
		options = new Request.Options(this.connectTimeout, this.readTimeout);
	}
	final LoadBalancedRetryPolicy retryPolicy = loadBalancedRetryPolicyFactory.create(this.getClientName(), this);
	RetryTemplate retryTemplate = new RetryTemplate();
	BackOffPolicy backOffPolicy = loadBalancedBackOffPolicyFactory.createBackOffPolicy(this.getClientName());
	retryTemplate.setBackOffPolicy(backOffPolicy == null ? new NoBackOffPolicy() : backOffPolicy);
	RetryListener[] retryListeners = this.loadBalancedRetryListenerFactory.createRetryListeners(this.getClientName());
	if (retryListeners != null && retryListeners.length != 0) {
		retryTemplate.setListeners(retryListeners);
	}
	retryTemplate.setRetryPolicy(retryPolicy == null ? new NeverRetryPolicy()
			: new FeignRetryPolicy(request.toHttpRequest(), retryPolicy, this, this.getClientName()));
	return retryTemplate.execute(new RetryCallback<RibbonResponse, IOException>() {
		@Override
		public RibbonResponse doWithRetry(RetryContext retryContext) throws IOException {
			Request feignRequest = null;
			//on retries the policy will choose the server and set it in the context
			//extract the server and update the request being made
			if(retryContext instanceof LoadBalancedRetryContext) {
				ServiceInstance service = ((LoadBalancedRetryContext)retryContext).getServiceInstance();
				if(service != null) {
					feignRequest = ((RibbonRequest)request.replaceUri(reconstructURIWithServer(new Server(service.getHost(), service.getPort()), request.getUri()))).toRequest();
				}
			}
			if(feignRequest == null) {
				feignRequest = request.toRequest();
			}
			Response response = request.client().execute(feignRequest, options);
			if(retryPolicy.retryableStatusCode(response.status())) {
				response.close();
				throw new RetryableStatusCodeException(RetryableFeignLoadBalancer.this.getClientName(), response.status());
			}
			return new RibbonResponse(request.getUri(), response);
		}
	});
}
 
开发者ID:spring-cloud,项目名称:spring-cloud-netflix,代码行数:48,代码来源:RetryableFeignLoadBalancer.java


示例13: mockRetryListener

import org.springframework.retry.RetryListener; //导入依赖的package包/类
@Bean
public RetryListener mockRetryListener() {
	return Mockito.mock(RetryListener.class);
}
 
开发者ID:debop,项目名称:spring-batch-experiments,代码行数:5,代码来源:RetryBehaviorConfiguration.java



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java Grammar类代码示例发布时间:2022-05-22
下一篇:
Java Metric类代码示例发布时间:2022-05-22
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap