/** * Construct an implementation of {@link HystrixMetricsPublisherCommand} for {@link HystrixCommand} instances having key {@link HystrixCommandKey}. * <p> * This will be invoked once per {@link HystrixCommandKey} instance. * <p> * <b>Default Implementation</b> * <p> * Return instance of {@link HystrixMetricsPublisherCommandDefault} * * @param commandKey * {@link HystrixCommandKey} representing the name or type of {@link HystrixCommand} * @param commandGroupKey * {@link HystrixCommandGroupKey} of {@link HystrixCommand} * @param metrics * {@link HystrixCommandMetrics} instance tracking metrics for {@link HystrixCommand} instances having the key as defined by {@link HystrixCommandKey} * @param circuitBreaker * {@link HystrixCircuitBreaker} instance for {@link HystrixCommand} instances having the key as defined by {@link HystrixCommandKey} * @param properties * {@link HystrixCommandProperties} instance for {@link HystrixCommand} instances having the key as defined by {@link HystrixCommandKey} * @return instance of {@link HystrixMetricsPublisherCommand} that will have its <code>initialize</code> method invoked once. */ public HystrixMetricsPublisherCommand getMetricsPublisherForCommand(HystrixCommandKey commandKey, HystrixCommandGroupKey commandGroupKey, HystrixCommandMetrics metrics, HystrixCircuitBreaker circuitBreaker, HystrixCommandProperties properties) { return new HystrixMetricsPublisherCommandDefault(commandKey, commandGroupKey, metrics, circuitBreaker, properties); }
@Test public void testMetricsPublisherReset() { // precondition: HystrixMetricsPublisherFactory class is not loaded. Calling HystrixPlugins.reset() here should be good enough to run this with other tests. // set first custom publisher HystrixCommandKey key = HystrixCommandKey.Factory.asKey("key"); HystrixMetricsPublisherCommand firstCommand = new HystrixMetricsPublisherCommandDefault(key, null, null, null, null); HystrixMetricsPublisher firstPublisher = new CustomPublisher(firstCommand); HystrixPlugins.getInstance().registerMetricsPublisher(firstPublisher); // ensure that first custom publisher is used HystrixMetricsPublisherCommand cmd = HystrixMetricsPublisherFactory.createOrRetrievePublisherForCommand(key, null, null, null, null); assertSame(firstCommand, cmd); // reset, then change to second custom publisher HystrixPlugins.reset(); HystrixMetricsPublisherCommand secondCommand = new HystrixMetricsPublisherCommandDefault(key, null, null, null, null); HystrixMetricsPublisher secondPublisher = new CustomPublisher(secondCommand); HystrixPlugins.getInstance().registerMetricsPublisher(secondPublisher); // ensure that second custom publisher is used cmd = HystrixMetricsPublisherFactory.createOrRetrievePublisherForCommand(key, null, null, null, null); assertNotSame(firstCommand, cmd); assertSame(secondCommand, cmd); }
/** * Construct an implementation of {@link HystrixMetricsPublisherCommand} for {@link HystrixCommand} instances having key {@link HystrixCommandKey}. * <p> * This will be invoked once per {@link HystrixCommandKey} instance. * <p> * <b>Default Implementation</b> * <p> * Return instance of {@link HystrixMetricsPublisherCommandDefault} * * @param commandKey * {@link HystrixCommandKey} representing the name or type of {@link HystrixCommand} * @param commandGroupKey * {@link HystrixCommandGroupKey} of {@link HystrixCommand} * @param metrics * {@link HystrixCommandMetrics} instance tracking metrics for {@link HystrixCommand} instances having the key as defined by {@link HystrixCommandKey} * @param circuitBreaker * {@link HystrixCircuitBreaker} instance for {@link HystrixCommand} instances having the key as defined by {@link HystrixCommandKey} * @param properties * {@link HystrixCommandProperties} instance for {@link HystrixCommand} instances having the key as defined by {@link HystrixCommandKey} * @return instance of {@link HystrixMetricsPublisherCommand} that will have its <code>initialize</code> method invoked once. */ public HystrixMetricsPublisherCommand getMetricsPublisherForCommand(HystrixCommandKey commandKey, HystrixCommandGroupKey commandGroupKey, HystrixCommandMetrics metrics, HystrixCircuitBreaker circuitBreaker, HystrixCommandProperties properties) { return new HystrixMetricsPublisherCommandDefault(commandKey, commandGroupKey, metrics, circuitBreaker, properties); }