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


Java FallbackFactory类代码示例

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


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

示例1: targetWithFallbackFactory

import feign.hystrix.FallbackFactory; //导入依赖的package包/类
private <T> T targetWithFallbackFactory(String feignClientName, FeignContext context,
										Target.HardCodedTarget<T> target,
										HystrixFeign.Builder builder,
										Class<?> fallbackFactoryClass) {
	FallbackFactory<? extends T> fallbackFactory = (FallbackFactory<? extends T>)
		getFromContext("fallbackFactory", feignClientName, context, fallbackFactoryClass, FallbackFactory.class);
	/* We take a sample fallback from the fallback factory to check if it returns a fallback
	that is compatible with the annotated feign interface. */
	Object exampleFallback = fallbackFactory.create(new RuntimeException());
	Assert.notNull(exampleFallback,
		String.format(
		"Incompatible fallbackFactory instance for feign client %s. Factory may not produce null!",
			feignClientName));
	/*if (!target.type().isAssignableFrom(exampleFallback.getClass())) {
		throw new IllegalStateException(
			String.format(
				"Incompatible fallbackFactory instance for feign client %s. Factory produces instances of '%s', but should produce instances of '%s'",
				feignClientName, exampleFallback.getClass(), target.type()));
	}*/
	return builder.target(target, fallbackFactory);
}
 
开发者ID:wayshall,项目名称:onetwo,代码行数:22,代码来源:EnhanceHystrixTargeter.java

示例2: targetWithFallbackFactory

import feign.hystrix.FallbackFactory; //导入依赖的package包/类
private <T> T targetWithFallbackFactory(String feignClientName, FeignContext context,
										Target.HardCodedTarget<T> target,
										HystrixFeign.Builder builder,
										Class<?> fallbackFactoryClass) {
	FallbackFactory<? extends T> fallbackFactory = (FallbackFactory<? extends T>)
		getFromContext("fallbackFactory", feignClientName, context, fallbackFactoryClass, FallbackFactory.class);
	/* We take a sample fallback from the fallback factory to check if it returns a fallback
	that is compatible with the annotated feign interface. */
	Object exampleFallback = fallbackFactory.create(new RuntimeException());
	Assert.notNull(exampleFallback,
		String.format(
		"Incompatible fallbackFactory instance for feign client %s. Factory may not produce null!",
			feignClientName));
	if (!target.type().isAssignableFrom(exampleFallback.getClass())) {
		throw new IllegalStateException(
			String.format(
				"Incompatible fallbackFactory instance for feign client %s. Factory produces instances of '%s', but should produce instances of '%s'",
				feignClientName, exampleFallback.getClass(), target.type()));
	}
	return builder.target(target, fallbackFactory);
}
 
开发者ID:spring-cloud,项目名称:spring-cloud-netflix,代码行数:22,代码来源:HystrixTargeter.java

示例3: build

import feign.hystrix.FallbackFactory; //导入依赖的package包/类
/** Configures components needed for hystrix integration. */
Feign build(final FallbackFactory<?> nullableFallbackFactory) {
  super.invocationHandlerFactory(new InvocationHandlerFactory() {
    @Override public InvocationHandler create(Target target,
        Map<Method, MethodHandler> dispatch) {
      return new EnhanceInvocationHandler(target, dispatch, setterFactory, nullableFallbackFactory);
    }
  });
  super.contract(new HystrixDelegatingContract(contract));
  return super.build();
}
 
开发者ID:wayshall,项目名称:onetwo,代码行数:12,代码来源:HystrixFeignBuilder.java

示例4: EnhanceInvocationHandler

import feign.hystrix.FallbackFactory; //导入依赖的package包/类
public EnhanceInvocationHandler(Target<?> target, Map<Method, MethodHandler> dispatch,
                         SetterFactory setterFactory, FallbackFactory<?> fallbackFactory) {
  this.target = checkNotNull(target, "target");
  this.dispatch = checkNotNull(dispatch, "dispatch");
  this.fallbackFactory = fallbackFactory;
  this.fallbackMethodMap = toFallbackMethod(dispatch);
  this.setterMethodMap = toSetters(setterFactory, target, dispatch.keySet());
}
 
开发者ID:wayshall,项目名称:onetwo,代码行数:9,代码来源:EnhanceInvocationHandler.java

示例5: target

import feign.hystrix.FallbackFactory; //导入依赖的package包/类
/**
 * Same as {@link #target(Class, String, T)}, except you can inspect a source exception before
 * creating a fallback object.
 */
public <T> T target(Class<T> apiType, String url, FallbackFactory<? extends T> fallbackFactory) {
  return target(new Target.HardCodedTarget<T>(apiType, url), fallbackFactory);
}
 
开发者ID:wayshall,项目名称:onetwo,代码行数:8,代码来源:HystrixFeignBuilder.java


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