Java Code Examples for com.netflix.hystrix.strategy.HystrixPlugins#registerConcurrencyStrategy()

The following examples show how to use com.netflix.hystrix.strategy.HystrixPlugins#registerConcurrencyStrategy() . 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: FeignHystrixConcurrencyStrategy.java    From sophia_scaffolding with Apache License 2.0 5 votes vote down vote up
public FeignHystrixConcurrencyStrategy() {
    try {
        this.delegate = HystrixPlugins.getInstance().getConcurrencyStrategy();
        if (this.delegate instanceof FeignHystrixConcurrencyStrategy) {
            // 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 instance = HystrixPlugins.getInstance();
        instance.registerConcurrencyStrategy(this);
        instance.registerCommandExecutionHook(commandExecutionHook);
        instance.registerEventNotifier(eventNotifier);
        instance.registerMetricsPublisher(metricsPublisher);
        instance.registerPropertiesStrategy(propertiesStrategy);
    } catch (Exception e) {
        log.error("Failed to register Sleuth Hystrix Concurrency Strategy", e);
    }
}
 
Example 2
Source File: FeignHystrixConcurrencyStrategy.java    From sophia_scaffolding with Apache License 2.0 5 votes vote down vote up
public FeignHystrixConcurrencyStrategy() {
    try {
        this.delegate = HystrixPlugins.getInstance().getConcurrencyStrategy();
        if (this.delegate instanceof FeignHystrixConcurrencyStrategy) {
            // 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 instance = HystrixPlugins.getInstance();
        instance.registerConcurrencyStrategy(this);
        instance.registerCommandExecutionHook(commandExecutionHook);
        instance.registerEventNotifier(eventNotifier);
        instance.registerMetricsPublisher(metricsPublisher);
        instance.registerPropertiesStrategy(propertiesStrategy);
    } catch (Exception e) {
        log.error("Failed to register Sleuth Hystrix Concurrency Strategy", e);
    }
}
 
Example 3
Source File: FeignHystrixConcurrencyStrategy.java    From sophia_scaffolding with Apache License 2.0 5 votes vote down vote up
public FeignHystrixConcurrencyStrategy() {
    try {
        this.delegate = HystrixPlugins.getInstance().getConcurrencyStrategy();
        if (this.delegate instanceof FeignHystrixConcurrencyStrategy) {
            // 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 instance = HystrixPlugins.getInstance();
        instance.registerConcurrencyStrategy(this);
        instance.registerCommandExecutionHook(commandExecutionHook);
        instance.registerEventNotifier(eventNotifier);
        instance.registerMetricsPublisher(metricsPublisher);
        instance.registerPropertiesStrategy(propertiesStrategy);
    } catch (Exception e) {
        log.error("Failed to register Sleuth Hystrix Concurrency Strategy", e);
    }
}
 
Example 4
Source File: HystrixPrometheusMetricsPublisher.java    From prometheus-hystrix with Apache License 2.0 4 votes vote down vote up
public void buildAndRegister() {
    HystrixPlugins plugins = HystrixPlugins.getInstance();

    // memorize the registered plugins
    HystrixCommandExecutionHook commandExecutionHook = plugins.getCommandExecutionHook();
    HystrixEventNotifier eventNotifier = plugins.getEventNotifier();
    HystrixMetricsPublisher metricsPublisher = plugins.getMetricsPublisher();
    HystrixPropertiesStrategy propertiesStrategy = plugins.getPropertiesStrategy();
    HystrixConcurrencyStrategy concurrencyStrategy = plugins.getConcurrencyStrategy();

    HystrixMetricsCollector collector = new HystrixMetricsCollector(namespace,
            new Consumer<Histogram.Builder>() {
                @Override
                public void accept(Histogram.Builder builder) {
                    if (metrics == MetricsType.EXPONENTIAL) {
                        builder.exponentialBuckets(exponentialStart, exponentialFactor, exponentialCount);
                    } else if (metrics == MetricsType.LINEAR) {
                        builder.linearBuckets(linearStart, linearWidth, linearCount);
                    } else if (metrics == MetricsType.DISTINCT) {
                        builder.buckets(distinctBuckets);
                    } else if (metrics == MetricsType.DEFAULT) {
                        // nothing to do
                    } else {
                        throw new IllegalStateException("unknown enum state " + metrics);
                    }
                }
            }).register(registry);

    // wrap the metrics publisher plugin
    HystrixPrometheusMetricsPublisher wrappedMetricsPublisher =
            new HystrixPrometheusMetricsPublisher(exportProperties,
                    exportDeprecatedMetrics, collector, metricsPublisher);

    // reset all plugins
    HystrixPlugins.reset();
    // the following statement wouldn't be necessary, but I'm paranoid that reset might
    // change the plugin instance.
    plugins = HystrixPlugins.getInstance();

    // set previous values for all plugins, but not if they would use the default implementation,
    // as this would block the slot for plugins to be registered.

    // REASON: if there was no previous setting, Hystrix would have returned the default implementation
    // and not all other plugin use the reset-and-wrap approach we do here.

    // ASSUMPTION: the default strategies/hooks can't wrap a different strategy/hook

    // CAVEAT: instead of a default implementation there is a sophisticated Archaius configuration mechanism
    // to determine a class from property settings. There is a corner case where someone would register a
    // default implementation manually overriding an Archaius configuration. Therefore this is configurable
    // using "registerDefaultPlugins".

    if (registerDefaultPlugins || concurrencyStrategy.getClass() != HystrixConcurrencyStrategyDefault.class) {
        plugins.registerConcurrencyStrategy(concurrencyStrategy);
    }
    if (registerDefaultPlugins || commandExecutionHook.getClass() != HystrixCommandExecutionHookDefault.class) {
        plugins.registerCommandExecutionHook(commandExecutionHook);
    }
    if (registerDefaultPlugins || eventNotifier.getClass() != HystrixEventNotifierDefault.class) {
        plugins.registerEventNotifier(eventNotifier);
    }
    if (registerDefaultPlugins || propertiesStrategy.getClass() != HystrixPropertiesStrategyDefault.class) {
        plugins.registerPropertiesStrategy(propertiesStrategy);
    }

    // ... except for the metrics publisher that will now be wrapped
    plugins.registerMetricsPublisher(wrappedMetricsPublisher);
}