com.netflix.hystrix.strategy.HystrixPlugins Java Examples
The following examples show how to use
com.netflix.hystrix.strategy.HystrixPlugins.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: MicrometerMetricsPublisherCommandTest.java From micrometer with Apache License 2.0 | 7 votes |
@Test void openCircuit() { HystrixMetricsPublisher metricsPublisher = HystrixPlugins.getInstance().getMetricsPublisher(); HystrixPlugins.reset(); HystrixPlugins.getInstance().registerMetricsPublisher(new MicrometerMetricsPublisher(registry, metricsPublisher)); HystrixCommandKey key = HystrixCommandKey.Factory.asKey("MicrometerCOMMAND-B"); propertiesSetter.withCircuitBreakerForceOpen(true); new SuccessCommand(key).execute(); new SuccessCommand(key).execute(); new TimeoutCommand(key).execute(); new FailureCommand(key).execute(); new FailureCommand(key).execute(); new SuccessCommand(key).execute(); Iterable<Tag> tags = Tags.of("group", groupKey.name(), "key", key.name()); assertExecutionMetric(tags, HystrixEventType.SHORT_CIRCUITED, 6.0); assertExecutionMetric(tags, HystrixEventType.SUCCESS, 0.0); assertExecutionMetric(tags, HystrixEventType.TIMEOUT, 0.0); assertExecutionMetric(tags, HystrixEventType.FAILURE, 0.0); assertThat(registry.get("hystrix.circuit.breaker.open").tags(tags).gauge().value()).isEqualTo(1.0); }
Example #2
Source File: RouterHystrixConcurrencyStrategy.java From spring-cloud-huawei with Apache License 2.0 | 6 votes |
public RouterHystrixConcurrencyStrategy() { HystrixConcurrencyStrategy strategy = HystrixPlugins.getInstance().getConcurrencyStrategy(); if (strategy instanceof RouterHystrixConcurrencyStrategy) { return; } HystrixCommandExecutionHook commandExecutionHook = HystrixPlugins.getInstance() .getCommandExecutionHook(); HystrixEventNotifier eventNotifier = HystrixPlugins.getInstance().getEventNotifier(); HystrixMetricsPublisher metricsPublisher = HystrixPlugins.getInstance().getMetricsPublisher(); HystrixPropertiesStrategy propertiesStrategy = HystrixPlugins.getInstance() .getPropertiesStrategy(); HystrixPlugins.reset(); HystrixPlugins.getInstance().registerConcurrencyStrategy(this); HystrixPlugins.getInstance().registerCommandExecutionHook(commandExecutionHook); HystrixPlugins.getInstance().registerEventNotifier(eventNotifier); HystrixPlugins.getInstance().registerMetricsPublisher(metricsPublisher); HystrixPlugins.getInstance().registerPropertiesStrategy(propertiesStrategy); }
Example #3
Source File: MetricsPublisherRegistrationTest.java From prometheus-hystrix with Apache License 2.0 | 6 votes |
@Test public void shouldReRegisterCustomHystrixPlugins() { // given // ... a plugin is already registered HystrixCommandExecutionHook plugin = new HystrixCommandExecutionHook() { }; HystrixPlugins.getInstance().registerCommandExecutionHook(plugin); // when // ... we register HystrixPrometheusMetricsPublisher.builder().shouldRegisterDefaultPlugins(false).buildAndRegister(); // then // ... the other plugin is still registered. assertThat(HystrixPlugins.getInstance().getCommandExecutionHook()).isEqualTo(plugin); }
Example #4
Source File: GrayHystrixContextConcurrencyStrategy.java From spring-cloud-gray with Apache License 2.0 | 6 votes |
public GrayHystrixContextConcurrencyStrategy() { this.delegate = HystrixPlugins.getInstance().getConcurrencyStrategy(); if (this.delegate instanceof GrayHystrixContextConcurrencyStrategy) { return; } // Keeps references of existing Hystrix plugins. HystrixCommandExecutionHook commandExecutionHook = HystrixPlugins.getInstance().getCommandExecutionHook(); HystrixEventNotifier eventNotifier = HystrixPlugins.getInstance().getEventNotifier(); HystrixMetricsPublisher metricsPublisher = HystrixPlugins.getInstance().getMetricsPublisher(); HystrixPropertiesStrategy propertiesStrategy = HystrixPlugins.getInstance().getPropertiesStrategy(); HystrixPlugins.reset(); // Registers existing plugins excepts the Concurrent Strategy plugin. HystrixPlugins.getInstance().registerConcurrencyStrategy(this); HystrixPlugins.getInstance().registerCommandExecutionHook(commandExecutionHook); HystrixPlugins.getInstance().registerEventNotifier(eventNotifier); HystrixPlugins.getInstance().registerMetricsPublisher(metricsPublisher); HystrixPlugins.getInstance().registerPropertiesStrategy(propertiesStrategy); }
Example #5
Source File: SofaTracerHystrixConcurrencyStrategy.java From sofa-tracer with Apache License 2.0 | 6 votes |
public SofaTracerHystrixConcurrencyStrategy() { try { this.delegate = HystrixPlugins.getInstance().getConcurrencyStrategy(); if (this.delegate instanceof SofaTracerHystrixConcurrencyStrategy) { // Welcome to singleton hell... return; } HystrixCommandExecutionHook commandExecutionHook = HystrixPlugins.getInstance() .getCommandExecutionHook(); HystrixEventNotifier eventNotifier = HystrixPlugins.getInstance().getEventNotifier(); HystrixMetricsPublisher metricsPublisher = HystrixPlugins.getInstance() .getMetricsPublisher(); HystrixPropertiesStrategy propertiesStrategy = HystrixPlugins.getInstance() .getPropertiesStrategy(); HystrixPlugins.reset(); HystrixPlugins.getInstance().registerConcurrencyStrategy(this); HystrixPlugins.getInstance().registerCommandExecutionHook(commandExecutionHook); HystrixPlugins.getInstance().registerEventNotifier(eventNotifier); HystrixPlugins.getInstance().registerMetricsPublisher(metricsPublisher); HystrixPlugins.getInstance().registerPropertiesStrategy(propertiesStrategy); } catch (Exception ex) { SelfLog.error("Failed to register Sleuth Hystrix Concurrency Strategy", ex); } }
Example #6
Source File: ThreadLocalConfiguration.java From spring-microservices-in-action with Apache License 2.0 | 6 votes |
@PostConstruct public void init() { // Keeps references of existing Hystrix plugins. HystrixEventNotifier eventNotifier = HystrixPlugins.getInstance().getEventNotifier(); HystrixMetricsPublisher metricsPublisher = HystrixPlugins.getInstance().getMetricsPublisher(); HystrixPropertiesStrategy propertiesStrategy = HystrixPlugins.getInstance().getPropertiesStrategy(); HystrixCommandExecutionHook commandExecutionHook = HystrixPlugins.getInstance().getCommandExecutionHook(); HystrixPlugins.reset(); HystrixPlugins.getInstance().registerConcurrencyStrategy(new ThreadLocalAwareStrategy(existingConcurrencyStrategy)); // Register your customized strategy ({@code ThreadLocalAwareStrategy}) HystrixPlugins.getInstance().registerEventNotifier(eventNotifier); HystrixPlugins.getInstance().registerMetricsPublisher(metricsPublisher); HystrixPlugins.getInstance().registerPropertiesStrategy(propertiesStrategy); HystrixPlugins.getInstance().registerCommandExecutionHook(commandExecutionHook); }
Example #7
Source File: ThreadLocalProcessHystrixConcurrencyStrategy.java From Aooms with Apache License 2.0 | 6 votes |
public ThreadLocalProcessHystrixConcurrencyStrategy() { try { this.delegate = HystrixPlugins.getInstance().getConcurrencyStrategy(); if (this.delegate instanceof ThreadLocalProcessHystrixConcurrencyStrategy) { // Welcome to singleton hell... return; } HystrixCommandExecutionHook commandExecutionHook = HystrixPlugins.getInstance().getCommandExecutionHook(); HystrixEventNotifier eventNotifier = HystrixPlugins.getInstance().getEventNotifier(); HystrixMetricsPublisher metricsPublisher = HystrixPlugins.getInstance().getMetricsPublisher(); HystrixPropertiesStrategy propertiesStrategy = HystrixPlugins.getInstance().getPropertiesStrategy(); this.logCurrentStateOfHystrixPlugins(eventNotifier, metricsPublisher, propertiesStrategy); HystrixPlugins.reset(); HystrixPlugins.getInstance().registerConcurrencyStrategy(this); HystrixPlugins.getInstance().registerCommandExecutionHook(commandExecutionHook); HystrixPlugins.getInstance().registerEventNotifier(eventNotifier); HystrixPlugins.getInstance().registerMetricsPublisher(metricsPublisher); HystrixPlugins.getInstance().registerPropertiesStrategy(propertiesStrategy); } catch (Exception e) { log.error("Failed to register Sleuth Hystrix Concurrency Strategy", e); } }
Example #8
Source File: RequestAttributeHystrixAutoConfiguration.java From summerframework with Apache License 2.0 | 6 votes |
@PostConstruct public void init() { HystrixEventNotifier eventNotifier = HystrixPlugins.getInstance().getEventNotifier(); HystrixMetricsPublisher metricsPublisher = HystrixPlugins.getInstance().getMetricsPublisher(); HystrixPropertiesStrategy propertiesStrategy = HystrixPlugins.getInstance().getPropertiesStrategy(); HystrixCommandExecutionHook commandExecutionHook = HystrixPlugins.getInstance().getCommandExecutionHook(); HystrixPlugins.reset(); HystrixPlugins.getInstance() .registerConcurrencyStrategy(new RequestAttributeHystrixConcurrencyStrategy(existingConcurrencyStrategy)); HystrixPlugins.getInstance().registerEventNotifier(eventNotifier); HystrixPlugins.getInstance().registerMetricsPublisher(metricsPublisher); HystrixPlugins.getInstance().registerPropertiesStrategy(propertiesStrategy); HystrixPlugins.getInstance().registerCommandExecutionHook(commandExecutionHook); }
Example #9
Source File: ExceptionLoggingCommandHookIntegrationTest.java From tenacity with Apache License 2.0 | 6 votes |
@Test public void shouldNotLogWhenShortCircuited() { final DefaultExceptionLogger defaultExceptionLogger = spy(new DefaultExceptionLogger()); HystrixPlugins.getInstance().registerCommandExecutionHook(new ExceptionLoggingCommandHook(defaultExceptionLogger)); try { new AlwaysShortCircuit().execute(); } catch (HystrixRuntimeException err) { assertThat(Throwables.getCausalChain(err) .stream() .filter(AuthenticationException.class::isInstance) .findAny()) .isNotEmpty(); } verifyZeroInteractions(defaultExceptionLogger); }
Example #10
Source File: RegisterCommandExcutionHook.java From jframework with Apache License 2.0 | 6 votes |
public RegisterCommandExcutionHook() { HystrixEventNotifier eventNotifier = HystrixPlugins.getInstance().getEventNotifier(); HystrixPropertiesStrategy propertiesStrategy = HystrixPlugins.getInstance().getPropertiesStrategy(); HystrixConcurrencyStrategy concurrencyStrategy = HystrixPlugins.getInstance().getConcurrencyStrategy(); HystrixMetricsPublisher hystrixMetricsPublisher = HystrixPlugins.getInstance().getMetricsPublisher(); HystrixPlugins.reset(); HystrixPlugins.getInstance().registerMetricsPublisher(hystrixMetricsPublisher); HystrixPlugins.getInstance().registerConcurrencyStrategy(concurrencyStrategy); HystrixPlugins.getInstance().registerEventNotifier(eventNotifier); HystrixPlugins.getInstance().registerPropertiesStrategy(propertiesStrategy); HystrixPlugins.getInstance().registerCommandExecutionHook(new HystrixCommandExecutionHook() { @Override public <T> void onFallbackStart(HystrixInvokable<T> commandInstance) { HystrixCommand hystrixCommand = (HystrixCommand) commandInstance; String commandKey = hystrixCommand.getCommandKey().toString(); log.error("Hystrix: {} 接口开始降级", commandKey); super.onFallbackStart(commandInstance); } }); }
Example #11
Source File: CustomFeignHystrixConcurrencyStrategy.java From spring-microservice-exam with MIT License | 6 votes |
public CustomFeignHystrixConcurrencyStrategy() { try { this.hystrixConcurrencyStrategy = HystrixPlugins.getInstance().getConcurrencyStrategy(); if (this.hystrixConcurrencyStrategy instanceof CustomFeignHystrixConcurrencyStrategy) { // Welcome to singleton hell... return; } HystrixCommandExecutionHook commandExecutionHook = HystrixPlugins.getInstance().getCommandExecutionHook(); HystrixEventNotifier eventNotifier = HystrixPlugins.getInstance().getEventNotifier(); HystrixMetricsPublisher metricsPublisher = HystrixPlugins.getInstance().getMetricsPublisher(); HystrixPropertiesStrategy propertiesStrategy = HystrixPlugins.getInstance().getPropertiesStrategy(); this.logCurrentStateOfHystrixPlugins(eventNotifier, metricsPublisher, propertiesStrategy); HystrixPlugins.reset(); HystrixPlugins.getInstance().registerConcurrencyStrategy(this); HystrixPlugins.getInstance().registerCommandExecutionHook(commandExecutionHook); HystrixPlugins.getInstance().registerEventNotifier(eventNotifier); HystrixPlugins.getInstance().registerMetricsPublisher(metricsPublisher); HystrixPlugins.getInstance().registerPropertiesStrategy(propertiesStrategy); } catch (Exception e) { log.error("Failed to register Sleuth Hystrix Concurrency Strategy", e); } }
Example #12
Source File: TenacityAuthenticatorTest.java From tenacity with Apache License 2.0 | 6 votes |
@Test public void shouldLogWhenExceptionIsThrown() throws AuthenticationException { final DefaultExceptionLogger defaultExceptionLogger = spy(new DefaultExceptionLogger()); HystrixPlugins.getInstance().registerCommandExecutionHook(new ExceptionLoggingCommandHook(defaultExceptionLogger)); when(mockAuthenticator.authenticate(any(BasicCredentials.class))).thenThrow(new AuthenticationException("test")); doCallRealMethod().when(defaultExceptionLogger).log(any(Exception.class), any(HystrixCommand.class)); try { tenacityAuthenticator.authenticate(new BasicCredentials("foo", "foo")); } catch (HystrixRuntimeException err) { assertThat(Throwables.getCausalChain(err) .stream() .filter(AuthenticationException.class::isInstance) .findAny()) .isNotEmpty(); } verify(mockAuthenticator, times(1)).authenticate(any(BasicCredentials.class)); verify(defaultExceptionLogger, times(1)).log(any(Exception.class), any(HystrixCommand.class)); }
Example #13
Source File: MetricsPublisherRegistrationTest.java From prometheus-hystrix with Apache License 2.0 | 6 votes |
@Test public void shouldRegisterDespitePreviouslyRegisteredHystrixMetricsPlugins() { // given // ... a provider is already registered HystrixPlugins.getInstance().registerMetricsPublisher(HystrixMetricsPublisherDefault.getInstance()); // when // ... we register (without throwing a "Another strategy was already registered" exception) HystrixPrometheusMetricsPublisher.register("exampleapp"); // then // ... we'll be able to collect metrics for commands TestHystrixCommand command = new TestHystrixCommand("any"); command.execute(); assertThat(CollectorRegistry.defaultRegistry .getSampleValue("exampleapp_hystrix_command_event_total", new String[]{"command_group", "command_name", "event", "terminal"}, new String[]{"group_any", "command_any", "success", "true"})) .describedAs("counter is present") .isGreaterThan(0); }
Example #14
Source File: ThreadLocalConfiguration.java From spring-microservices-in-action with Apache License 2.0 | 6 votes |
@PostConstruct public void init() { // Keeps references of existing Hystrix plugins. HystrixEventNotifier eventNotifier = HystrixPlugins.getInstance().getEventNotifier(); HystrixMetricsPublisher metricsPublisher = HystrixPlugins.getInstance().getMetricsPublisher(); HystrixPropertiesStrategy propertiesStrategy = HystrixPlugins.getInstance().getPropertiesStrategy(); HystrixCommandExecutionHook commandExecutionHook = HystrixPlugins.getInstance().getCommandExecutionHook(); HystrixPlugins.reset(); HystrixPlugins.getInstance().registerConcurrencyStrategy(new ThreadLocalAwareStrategy(existingConcurrencyStrategy)); // Register your customized strategy ({@code ThreadLocalAwareStrategy}) HystrixPlugins.getInstance().registerEventNotifier(eventNotifier); HystrixPlugins.getInstance().registerMetricsPublisher(metricsPublisher); HystrixPlugins.getInstance().registerPropertiesStrategy(propertiesStrategy); HystrixPlugins.getInstance().registerCommandExecutionHook(commandExecutionHook); }
Example #15
Source File: ThreadLocalConfiguration.java From spring-microservices-in-action with Apache License 2.0 | 6 votes |
@PostConstruct public void init() { // Keeps references of existing Hystrix plugins. HystrixEventNotifier eventNotifier = HystrixPlugins.getInstance().getEventNotifier(); HystrixMetricsPublisher metricsPublisher = HystrixPlugins.getInstance().getMetricsPublisher(); HystrixPropertiesStrategy propertiesStrategy = HystrixPlugins.getInstance().getPropertiesStrategy(); HystrixCommandExecutionHook commandExecutionHook = HystrixPlugins.getInstance().getCommandExecutionHook(); HystrixPlugins.reset(); HystrixPlugins.getInstance().registerConcurrencyStrategy(new ThreadLocalAwareStrategy(existingConcurrencyStrategy)); // Register your customized strategy ({@code ThreadLocalAwareStrategy}) HystrixPlugins.getInstance().registerEventNotifier(eventNotifier); HystrixPlugins.getInstance().registerMetricsPublisher(metricsPublisher); HystrixPlugins.getInstance().registerPropertiesStrategy(propertiesStrategy); HystrixPlugins.getInstance().registerCommandExecutionHook(commandExecutionHook); }
Example #16
Source File: ThreadLocalConfiguration.java From spring-microservices-in-action with Apache License 2.0 | 6 votes |
@PostConstruct public void init() { // Keeps references of existing Hystrix plugins. HystrixEventNotifier eventNotifier = HystrixPlugins.getInstance().getEventNotifier(); HystrixMetricsPublisher metricsPublisher = HystrixPlugins.getInstance().getMetricsPublisher(); HystrixPropertiesStrategy propertiesStrategy = HystrixPlugins.getInstance().getPropertiesStrategy(); HystrixCommandExecutionHook commandExecutionHook = HystrixPlugins.getInstance().getCommandExecutionHook(); HystrixPlugins.reset(); HystrixPlugins.getInstance().registerConcurrencyStrategy(new ThreadLocalAwareStrategy(existingConcurrencyStrategy)); // Register your customized strategy ({@code ThreadLocalAwareStrategy}) HystrixPlugins.getInstance().registerEventNotifier(eventNotifier); HystrixPlugins.getInstance().registerMetricsPublisher(metricsPublisher); HystrixPlugins.getInstance().registerPropertiesStrategy(propertiesStrategy); HystrixPlugins.getInstance().registerCommandExecutionHook(commandExecutionHook); }
Example #17
Source File: PreservesExecutionContextHystrixStrategy.java From spring-cloud-ribbon-extensions with Apache License 2.0 | 6 votes |
/** * registers the {@link ExecutionContextAwareHystrixStrategy} */ public static void init() { // keeps references of existing Hystrix plugins. HystrixConcurrencyStrategy existingConcurrencyStrategy = HystrixPlugins.getInstance().getConcurrencyStrategy(); HystrixEventNotifier eventNotifier = HystrixPlugins.getInstance().getEventNotifier(); HystrixMetricsPublisher metricsPublisher = HystrixPlugins.getInstance().getMetricsPublisher(); HystrixPropertiesStrategy propertiesStrategy = HystrixPlugins.getInstance().getPropertiesStrategy(); HystrixCommandExecutionHook commandExecutionHook = HystrixPlugins.getInstance().getCommandExecutionHook(); // reset the Hystrix plugin HystrixPlugins.reset(); // configure the plugin HystrixPlugins.getInstance().registerConcurrencyStrategy(new ExecutionContextAwareHystrixStrategy(existingConcurrencyStrategy)); HystrixPlugins.getInstance().registerEventNotifier(eventNotifier); HystrixPlugins.getInstance().registerMetricsPublisher(metricsPublisher); HystrixPlugins.getInstance().registerPropertiesStrategy(propertiesStrategy); HystrixPlugins.getInstance().registerCommandExecutionHook(commandExecutionHook); log.info("Context propagation enabled for Hystrix."); }
Example #18
Source File: HystrixPluginsInterceptorTest.java From skywalking with Apache License 2.0 | 6 votes |
@Test public void testInterceptorWithCustomHystrixCommandExecutionHook() throws Throwable { Object wrapperResult = getCommandExecutionHookByInterceptor(); assertTrue(wrapperResult instanceof SWExecutionHookWrapper); assertSame(HystrixPlugins.getInstance().getCommandExecutionHook(), wrapperResult); // register custom HystrixCommandExecutionHook HystrixCommandExecutionHook delegate = getCommandExecutionHookByInterceptor(); HystrixCommandExecutionHook customCommandExecutionHook = new CustomHystrixCommandExecutionHook(delegate); HystrixPlugins.reset(); HystrixPlugins.getInstance().registerCommandExecutionHook(customCommandExecutionHook); // custom HystrixCommandExecutionHook can be consumed wrapperResult = getCommandExecutionHookByInterceptor(); assertSame(customCommandExecutionHook, wrapperResult); assertSame(HystrixPlugins.getInstance().getCommandExecutionHook(), wrapperResult); }
Example #19
Source File: HystrixPluginsInterceptorTest.java From skywalking with Apache License 2.0 | 6 votes |
@Before public void setUp() { hystrixPluginsInterceptor = new HystrixPluginsInterceptor(); enhancedInstance = new EnhancedInstance() { private SWHystrixPluginsWrapperCache cache; @Override public Object getSkyWalkingDynamicField() { return cache; } @Override public void setSkyWalkingDynamicField(Object cache) { this.cache = (SWHystrixPluginsWrapperCache) cache; } }; HystrixPlugins.reset(); }
Example #20
Source File: SeataHystrixConcurrencyStrategy.java From spring-cloud-alibaba with Apache License 2.0 | 6 votes |
public SeataHystrixConcurrencyStrategy() { try { this.delegate = HystrixPlugins.getInstance().getConcurrencyStrategy(); if (this.delegate instanceof SeataHystrixConcurrencyStrategy) { return; } HystrixCommandExecutionHook commandExecutionHook = HystrixPlugins.getInstance().getCommandExecutionHook(); HystrixEventNotifier eventNotifier = HystrixPlugins.getInstance().getEventNotifier(); HystrixMetricsPublisher metricsPublisher = HystrixPlugins.getInstance().getMetricsPublisher(); HystrixPropertiesStrategy propertiesStrategy = HystrixPlugins.getInstance().getPropertiesStrategy(); logCurrentStateOfHystrixPlugins(eventNotifier, metricsPublisher, propertiesStrategy); HystrixPlugins.reset(); HystrixPlugins.getInstance().registerConcurrencyStrategy(this); HystrixPlugins.getInstance().registerCommandExecutionHook(commandExecutionHook); HystrixPlugins.getInstance().registerEventNotifier(eventNotifier); HystrixPlugins.getInstance().registerMetricsPublisher(metricsPublisher); HystrixPlugins.getInstance().registerPropertiesStrategy(propertiesStrategy); } catch (Exception ex) { logger.error("Failed to register Seata Hystrix Concurrency Strategy", ex); } }
Example #21
Source File: HystrixMetricsBinder.java From micrometer with Apache License 2.0 | 6 votes |
@Override public void bindTo(MeterRegistry registry) { // Keeps references of existing Hystrix plugins. HystrixEventNotifier eventNotifier = HystrixPlugins.getInstance().getEventNotifier(); HystrixPropertiesStrategy propertiesStrategy = HystrixPlugins.getInstance().getPropertiesStrategy(); HystrixCommandExecutionHook commandExecutionHook = HystrixPlugins.getInstance().getCommandExecutionHook(); HystrixConcurrencyStrategy concurrencyStrategy = HystrixPlugins.getInstance().getConcurrencyStrategy(); HystrixMetricsPublisher metricsPublisher = HystrixPlugins.getInstance().getMetricsPublisher(); HystrixPlugins.reset(); // Registers existing plugins except the new MicroMeter Strategy plugin. HystrixPlugins.getInstance().registerMetricsPublisher(new MicrometerMetricsPublisher(registry, metricsPublisher)); HystrixPlugins.getInstance().registerConcurrencyStrategy(concurrencyStrategy); HystrixPlugins.getInstance().registerEventNotifier(eventNotifier); HystrixPlugins.getInstance().registerPropertiesStrategy(propertiesStrategy); HystrixPlugins.getInstance().registerCommandExecutionHook(commandExecutionHook); }
Example #22
Source File: HystrixConcurrencyStrategyInterceptorTest.java From skywalking with Apache License 2.0 | 6 votes |
@Test public void testInterceptorWithCustomHystrixConcurrencyStrategy() throws Throwable { Object wrapperResult = getConcurrencyStrategyByInterceptor(); assertTrue(wrapperResult instanceof SWHystrixConcurrencyStrategyWrapper); assertSame(HystrixPlugins.getInstance().getConcurrencyStrategy(), wrapperResult); // register custom HystrixConcurrencyStrategy final HystrixConcurrencyStrategy delegate = getConcurrencyStrategyByInterceptor(); HystrixConcurrencyStrategy customConcurrencyStrategy = new CustomConcurrencyStrategy(delegate); HystrixPlugins.reset(); HystrixPlugins.getInstance().registerConcurrencyStrategy(customConcurrencyStrategy); // custom HystrixConcurrencyStrategy can be consumed wrapperResult = getConcurrencyStrategyByInterceptor(); assertSame(customConcurrencyStrategy, wrapperResult); assertSame(HystrixPlugins.getInstance().getConcurrencyStrategy(), wrapperResult); }
Example #23
Source File: HystrixConcurrencyStrategyInterceptorTest.java From skywalking with Apache License 2.0 | 6 votes |
@Before public void setUp() { hystrixConcurrencyStrategyInterceptor = new HystrixConcurrencyStrategyInterceptor(); enhancedInstance = new EnhancedInstance() { private SWHystrixPluginsWrapperCache cache; @Override public Object getSkyWalkingDynamicField() { return cache; } @Override public void setSkyWalkingDynamicField(Object cache) { this.cache = (SWHystrixPluginsWrapperCache) cache; } }; HystrixPlugins.reset(); }
Example #24
Source File: HystrixPluginsInterceptor.java From skywalking with Apache License 2.0 | 6 votes |
private static void registerSWExecutionHookWrapper(SWExecutionHookWrapper wrapper) { HystrixConcurrencyStrategy concurrencyStrategy = HystrixPlugins.getInstance().getConcurrencyStrategy(); HystrixEventNotifier eventNotifier = HystrixPlugins.getInstance().getEventNotifier(); HystrixMetricsPublisher metricsPublisher = HystrixPlugins.getInstance().getMetricsPublisher(); HystrixPropertiesStrategy propertiesStrategy = HystrixPlugins.getInstance().getPropertiesStrategy(); HystrixPlugins.reset(); HystrixPlugins.getInstance().registerConcurrencyStrategy(concurrencyStrategy); HystrixPlugins.getInstance().registerCommandExecutionHook(wrapper); HystrixPlugins.getInstance().registerEventNotifier(eventNotifier); HystrixPlugins.getInstance().registerMetricsPublisher(metricsPublisher); HystrixPlugins.getInstance().registerPropertiesStrategy(propertiesStrategy); }
Example #25
Source File: MultiConfigs.java From astrix with Apache License 2.0 | 6 votes |
private static void registerWithHystrix() { final HystrixEventNotifier eventNotifier = HystrixPlugins.getInstance().getEventNotifier(); final HystrixConcurrencyStrategy concurrencyStrategy = HystrixPlugins.getInstance().getConcurrencyStrategy(); final HystrixMetricsPublisher metricsPublisher = HystrixPlugins.getInstance().getMetricsPublisher(); final HystrixPropertiesStrategy propertiesStrategy = HystrixPlugins.getInstance().getPropertiesStrategy(); final HystrixCommandExecutionHook commandExecutionHook = HystrixPlugins.getInstance().getCommandExecutionHook(); HystrixPlugins.reset(); reRegister(eventNotifier, multiEventNotifierDispatcher, notifier -> HystrixPlugins.getInstance().registerEventNotifier(notifier)); reRegister(concurrencyStrategy, multiConcurrencyStrategyDispatcher, strategy -> HystrixPlugins.getInstance().registerConcurrencyStrategy(strategy)); HystrixPlugins.getInstance().registerMetricsPublisher(metricsPublisher); reRegister(propertiesStrategy, multiPropertiesStrategyDispatcher, strategy -> HystrixPlugins.getInstance().registerPropertiesStrategy(strategy)); HystrixPlugins.getInstance().registerCommandExecutionHook(commandExecutionHook); LOGGER.info(MultiPropertiesStrategyDispatcher.class.getName() + " registered with Hystrix!"); }
Example #26
Source File: AbstractContextConcurrencyStrategy.java From onetwo with Apache License 2.0 | 6 votes |
public AbstractContextConcurrencyStrategy(HystrixConcurrencyStrategy existingConcurrencyStrategy) { if (getClass().isInstance(existingConcurrencyStrategy)) { System.out.println("Welcome to singleton hell..."); return; } this.existingConcurrencyStrategy = existingConcurrencyStrategy; HystrixEventNotifier eventNotifier = HystrixPlugins.getInstance() .getEventNotifier(); HystrixMetricsPublisher metricsPublisher = HystrixPlugins.getInstance() .getMetricsPublisher(); HystrixPropertiesStrategy propertiesStrategy = HystrixPlugins.getInstance() .getPropertiesStrategy(); HystrixCommandExecutionHook commandExecutionHook = HystrixPlugins.getInstance() .getCommandExecutionHook(); HystrixPlugins.reset(); // Registers existing plugins excepts the Concurrent Strategy plugin. HystrixPlugins.getInstance().registerConcurrencyStrategy(this); HystrixPlugins.getInstance().registerEventNotifier(eventNotifier); HystrixPlugins.getInstance().registerMetricsPublisher(metricsPublisher); HystrixPlugins.getInstance().registerPropertiesStrategy(propertiesStrategy); HystrixPlugins.getInstance().registerCommandExecutionHook(commandExecutionHook); }
Example #27
Source File: BladeHystrixAutoConfiguration.java From blade-tool with GNU Lesser General Public License v3.0 | 6 votes |
@PostConstruct public void init() { // Keeps references of existing Hystrix plugins. HystrixEventNotifier eventNotifier = HystrixPlugins.getInstance().getEventNotifier(); HystrixMetricsPublisher metricsPublisher = HystrixPlugins.getInstance().getMetricsPublisher(); HystrixPropertiesStrategy propertiesStrategy = HystrixPlugins.getInstance().getPropertiesStrategy(); HystrixCommandExecutionHook commandExecutionHook = HystrixPlugins.getInstance().getCommandExecutionHook(); HystrixPlugins.reset(); // Registers existing plugins excepts the Concurrent Strategy plugin. HystrixConcurrencyStrategy strategy = new BladeHystrixConcurrencyStrategy(existingConcurrencyStrategy, accountGetter, properties); HystrixPlugins.getInstance().registerConcurrencyStrategy(strategy); HystrixPlugins.getInstance().registerEventNotifier(eventNotifier); HystrixPlugins.getInstance().registerMetricsPublisher(metricsPublisher); HystrixPlugins.getInstance().registerPropertiesStrategy(propertiesStrategy); HystrixPlugins.getInstance().registerCommandExecutionHook(commandExecutionHook); }
Example #28
Source File: TracingConcurrencyStrategy.java From feign-opentracing with Apache License 2.0 | 5 votes |
private TracingConcurrencyStrategy(Tracer tracer) { this.tracer = tracer; try { this.delegateStrategy = HystrixPlugins.getInstance().getConcurrencyStrategy(); if (this.delegateStrategy instanceof TracingConcurrencyStrategy) { return; } HystrixCommandExecutionHook commandExecutionHook = HystrixPlugins.getInstance().getCommandExecutionHook(); HystrixEventNotifier eventNotifier = HystrixPlugins.getInstance().getEventNotifier(); HystrixMetricsPublisher metricsPublisher = HystrixPlugins.getInstance().getMetricsPublisher(); HystrixPropertiesStrategy propertiesStrategy = HystrixPlugins.getInstance().getPropertiesStrategy(); HystrixPlugins.reset(); HystrixPlugins.getInstance().registerConcurrencyStrategy(this); HystrixPlugins.getInstance().registerCommandExecutionHook(commandExecutionHook); HystrixPlugins.getInstance().registerEventNotifier(eventNotifier); HystrixPlugins.getInstance().registerMetricsPublisher(metricsPublisher); HystrixPlugins.getInstance().registerPropertiesStrategy(propertiesStrategy); } catch (Exception ex) { log.log(Level.SEVERE, "Failed to register " + TracingConcurrencyStrategy.class + ", to HystrixPlugins", ex); } }
Example #29
Source File: HystrixConcurrencyStrategyTests.java From servicecomb-pack with Apache License 2.0 | 5 votes |
@Test public void testConcurrencyStrategyInstalled() { HystrixConcurrencyStrategy concurrencyStrategy = HystrixPlugins.getInstance() .getConcurrencyStrategy(); assertThat(concurrencyStrategy) .isInstanceOf(ServiceCombConcurrencyStrategy.class); }
Example #30
Source File: BootstrapListener.java From Poseidon with Apache License 2.0 | 5 votes |
private void registerHystrixPlugins() { // Register hystrix codahale metrics publisher plugin STARTUP_LOGGER.info("Registering hystrix jmx metrics plugin"); HystrixCodaHaleMetricsPublisher publisher = new HystrixCodaHaleMetricsPublisher(Metrics.getRegistry()); HystrixPlugins.getInstance().registerMetricsPublisher(publisher); STARTUP_LOGGER.info("Registered hystrix jmx metrics plugin"); }