Skip to content

Commit

Permalink
Fix for backward compatibility with Hystrix 1.4
Browse files Browse the repository at this point in the history
  • Loading branch information
agentgt committed Feb 4, 2016
1 parent e5075b0 commit 5d0e7ae
Show file tree
Hide file tree
Showing 8 changed files with 473 additions and 83 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

import static com.netflix.hystrix.strategy.properties.HystrixProperty.Factory.asProperty;

import com.netflix.hystrix.strategy.properties.HystrixPropertiesChainedArchaiusProperty;
import com.netflix.hystrix.strategy.properties.HystrixPropertiesChainedProperty;
import com.netflix.hystrix.strategy.properties.HystrixPropertiesStrategy;
import com.netflix.hystrix.strategy.properties.HystrixProperty;
import com.netflix.hystrix.util.HystrixRollingNumber;
Expand Down Expand Up @@ -72,22 +72,22 @@ protected HystrixCollapserProperties(HystrixCollapserKey key, Setter builder, St
}

private static HystrixProperty<Integer> getProperty(String propertyPrefix, HystrixCollapserKey key, String instanceProperty, Integer builderOverrideValue, Integer defaultValue) {
return asProperty(new HystrixPropertiesChainedArchaiusProperty.IntegerProperty(
new HystrixPropertiesChainedArchaiusProperty.DynamicIntegerProperty(propertyPrefix + ".collapser." + key.name() + "." + instanceProperty, builderOverrideValue),
new HystrixPropertiesChainedArchaiusProperty.DynamicIntegerProperty(propertyPrefix + ".collapser.default." + instanceProperty, defaultValue)));
return asProperty(new HystrixPropertiesChainedProperty.IntegerProperty(
new HystrixPropertiesChainedProperty.DynamicIntegerProperty(propertyPrefix + ".collapser." + key.name() + "." + instanceProperty, builderOverrideValue),
new HystrixPropertiesChainedProperty.DynamicIntegerProperty(propertyPrefix + ".collapser.default." + instanceProperty, defaultValue)));
}

private static HystrixProperty<Boolean> getProperty(String propertyPrefix, HystrixCollapserKey key, String instanceProperty, Boolean builderOverrideValue, Boolean defaultValue) {
return asProperty(new HystrixPropertiesChainedArchaiusProperty.BooleanProperty(
new HystrixPropertiesChainedArchaiusProperty.DynamicBooleanProperty(propertyPrefix + ".collapser." + key.name() + "." + instanceProperty, builderOverrideValue),
new HystrixPropertiesChainedArchaiusProperty.DynamicBooleanProperty(propertyPrefix + ".collapser.default." + instanceProperty, defaultValue)));
return asProperty(new HystrixPropertiesChainedProperty.BooleanProperty(
new HystrixPropertiesChainedProperty.DynamicBooleanProperty(propertyPrefix + ".collapser." + key.name() + "." + instanceProperty, builderOverrideValue),
new HystrixPropertiesChainedProperty.DynamicBooleanProperty(propertyPrefix + ".collapser.default." + instanceProperty, defaultValue)));
}

@SuppressWarnings("unused")
private static HystrixProperty<String> getProperty(String propertyPrefix, HystrixCollapserKey key, String instanceProperty, String builderOverrideValue, String defaultValue) {
return asProperty(new HystrixPropertiesChainedArchaiusProperty.StringProperty(
new HystrixPropertiesChainedArchaiusProperty.DynamicStringProperty(propertyPrefix + ".collapser." + key.name() + "." + instanceProperty, builderOverrideValue),
new HystrixPropertiesChainedArchaiusProperty.DynamicStringProperty(propertyPrefix + ".collapser.default." + instanceProperty, defaultValue)));
return asProperty(new HystrixPropertiesChainedProperty.StringProperty(
new HystrixPropertiesChainedProperty.DynamicStringProperty(propertyPrefix + ".collapser." + key.name() + "." + instanceProperty, builderOverrideValue),
new HystrixPropertiesChainedProperty.DynamicStringProperty(propertyPrefix + ".collapser.default." + instanceProperty, defaultValue)));
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.netflix.hystrix.strategy.properties.HystrixPropertiesChainedArchaiusProperty;
import com.netflix.hystrix.strategy.properties.HystrixPropertiesChainedArchaiusProperty.DynamicStringProperty;
import com.netflix.hystrix.strategy.properties.HystrixPropertiesChainedProperty;
import com.netflix.hystrix.strategy.properties.HystrixPropertiesChainedProperty.DynamicStringProperty;
import com.netflix.hystrix.strategy.properties.HystrixPropertiesStrategy;
import com.netflix.hystrix.strategy.properties.HystrixProperty;
import com.netflix.hystrix.util.HystrixRollingNumber;
Expand Down Expand Up @@ -134,7 +134,7 @@ protected HystrixCommandProperties(HystrixCommandKey key, HystrixCommandProperti
this.requestLogEnabled = getProperty(propertyPrefix, key, "requestLog.enabled", builder.getRequestLogEnabled(), default_requestLogEnabled);

// threadpool doesn't have a global override, only instance level makes sense
this.executionIsolationThreadPoolKeyOverride = asProperty(new DynamicStringProperty(propertyPrefix + ".command." + key.name() + ".threadPoolKeyOverride", null));
this.executionIsolationThreadPoolKeyOverride = new DynamicStringProperty(propertyPrefix + ".command." + key.name() + ".threadPoolKeyOverride", null);
}

/**
Expand Down Expand Up @@ -412,22 +412,22 @@ public HystrixProperty<Boolean> requestLogEnabled() {
}

private static HystrixProperty<Boolean> getProperty(String propertyPrefix, HystrixCommandKey key, String instanceProperty, Boolean builderOverrideValue, Boolean defaultValue) {
return asProperty(new HystrixPropertiesChainedArchaiusProperty.BooleanProperty(
new HystrixPropertiesChainedArchaiusProperty.DynamicBooleanProperty(propertyPrefix + ".command." + key.name() + "." + instanceProperty, builderOverrideValue),
new HystrixPropertiesChainedArchaiusProperty.DynamicBooleanProperty(propertyPrefix + ".command.default." + instanceProperty, defaultValue)));
return asProperty(new HystrixPropertiesChainedProperty.BooleanProperty(
new HystrixPropertiesChainedProperty.DynamicBooleanProperty(propertyPrefix + ".command." + key.name() + "." + instanceProperty, builderOverrideValue),
new HystrixPropertiesChainedProperty.DynamicBooleanProperty(propertyPrefix + ".command.default." + instanceProperty, defaultValue)));
}

private static HystrixProperty<Integer> getProperty(String propertyPrefix, HystrixCommandKey key, String instanceProperty, Integer builderOverrideValue, Integer defaultValue) {
return asProperty(new HystrixPropertiesChainedArchaiusProperty.IntegerProperty(
new HystrixPropertiesChainedArchaiusProperty.DynamicIntegerProperty(propertyPrefix + ".command." + key.name() + "." + instanceProperty, builderOverrideValue),
new HystrixPropertiesChainedArchaiusProperty.DynamicIntegerProperty(propertyPrefix + ".command.default." + instanceProperty, defaultValue)));
return asProperty(new HystrixPropertiesChainedProperty.IntegerProperty(
new HystrixPropertiesChainedProperty.DynamicIntegerProperty(propertyPrefix + ".command." + key.name() + "." + instanceProperty, builderOverrideValue),
new HystrixPropertiesChainedProperty.DynamicIntegerProperty(propertyPrefix + ".command.default." + instanceProperty, defaultValue)));
}

@SuppressWarnings("unused")
private static HystrixProperty<String> getProperty(String propertyPrefix, HystrixCommandKey key, String instanceProperty, String builderOverrideValue, String defaultValue) {
return asProperty(new HystrixPropertiesChainedArchaiusProperty.StringProperty(
new HystrixPropertiesChainedArchaiusProperty.DynamicStringProperty(propertyPrefix + ".command." + key.name() + "." + instanceProperty, builderOverrideValue),
new HystrixPropertiesChainedArchaiusProperty.DynamicStringProperty(propertyPrefix + ".command.default." + instanceProperty, defaultValue)));
return asProperty(new HystrixPropertiesChainedProperty.StringProperty(
new HystrixPropertiesChainedProperty.DynamicStringProperty(propertyPrefix + ".command." + key.name() + "." + instanceProperty, builderOverrideValue),
new HystrixPropertiesChainedProperty.DynamicStringProperty(propertyPrefix + ".command.default." + instanceProperty, defaultValue)));
}

private static HystrixProperty<ExecutionIsolationStrategy> getProperty(final String propertyPrefix, final HystrixCommandKey key, final String instanceProperty, final ExecutionIsolationStrategy builderOverrideValue, final ExecutionIsolationStrategy defaultValue) {
Expand All @@ -439,7 +439,7 @@ private static HystrixProperty<ExecutionIsolationStrategy> getProperty(final Str
* HystrixProperty that converts a String to ExecutionIsolationStrategy so we remain TypeSafe.
*/
private static final class ExecutionIsolationStrategyHystrixProperty implements HystrixProperty<ExecutionIsolationStrategy> {
private final HystrixPropertiesChainedArchaiusProperty.StringProperty property;
private final HystrixPropertiesChainedProperty.StringProperty property;
private volatile ExecutionIsolationStrategy value;
private final ExecutionIsolationStrategy defaultValue;

Expand All @@ -449,9 +449,9 @@ private ExecutionIsolationStrategyHystrixProperty(ExecutionIsolationStrategy bui
if (builderOverrideValue != null) {
overrideValue = builderOverrideValue.name();
}
property = new HystrixPropertiesChainedArchaiusProperty.StringProperty(
new HystrixPropertiesChainedArchaiusProperty.DynamicStringProperty(propertyPrefix + ".command." + key.name() + "." + instanceProperty, overrideValue),
new HystrixPropertiesChainedArchaiusProperty.DynamicStringProperty(propertyPrefix + ".command.default." + instanceProperty, defaultValue.name()));
property = new HystrixPropertiesChainedProperty.StringProperty(
new HystrixPropertiesChainedProperty.DynamicStringProperty(propertyPrefix + ".command." + key.name() + "." + instanceProperty, overrideValue),
new HystrixPropertiesChainedProperty.DynamicStringProperty(propertyPrefix + ".command.default." + instanceProperty, defaultValue.name()));

// initialize the enum value from the property
parseProperty();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
import java.util.concurrent.TimeUnit;

import com.netflix.hystrix.strategy.concurrency.HystrixConcurrencyStrategy;
import com.netflix.hystrix.strategy.properties.HystrixPropertiesChainedArchaiusProperty;
import com.netflix.hystrix.strategy.properties.HystrixPropertiesChainedProperty;
import com.netflix.hystrix.strategy.properties.HystrixPropertiesStrategy;
import com.netflix.hystrix.strategy.properties.HystrixProperty;
import com.netflix.hystrix.util.HystrixRollingNumber;
Expand Down Expand Up @@ -68,23 +68,23 @@ protected HystrixThreadPoolProperties(HystrixThreadPoolKey key, Setter builder,
}

private static HystrixProperty<Integer> getProperty(String propertyPrefix, HystrixThreadPoolKey key, String instanceProperty, Integer builderOverrideValue, Integer defaultValue) {
return asProperty(new HystrixPropertiesChainedArchaiusProperty.IntegerProperty(
new HystrixPropertiesChainedArchaiusProperty.DynamicIntegerProperty(propertyPrefix + ".threadpool." + key.name() + "." + instanceProperty, builderOverrideValue),
new HystrixPropertiesChainedArchaiusProperty.DynamicIntegerProperty(propertyPrefix + ".threadpool.default." + instanceProperty, defaultValue)));
return asProperty(new HystrixPropertiesChainedProperty.IntegerProperty(
new HystrixPropertiesChainedProperty.DynamicIntegerProperty(propertyPrefix + ".threadpool." + key.name() + "." + instanceProperty, builderOverrideValue),
new HystrixPropertiesChainedProperty.DynamicIntegerProperty(propertyPrefix + ".threadpool.default." + instanceProperty, defaultValue)));
}

@SuppressWarnings("unused")
private static HystrixProperty<Boolean> getProperty(String propertyPrefix, HystrixThreadPoolKey key, String instanceProperty, Boolean builderOverrideValue, Boolean defaultValue) {
return asProperty(new HystrixPropertiesChainedArchaiusProperty.BooleanProperty(
new HystrixPropertiesChainedArchaiusProperty.DynamicBooleanProperty(propertyPrefix + ".threadpool." + key.name() + "." + instanceProperty, builderOverrideValue),
new HystrixPropertiesChainedArchaiusProperty.DynamicBooleanProperty(propertyPrefix + ".threadpool.default." + instanceProperty, defaultValue)));
return asProperty(new HystrixPropertiesChainedProperty.BooleanProperty(
new HystrixPropertiesChainedProperty.DynamicBooleanProperty(propertyPrefix + ".threadpool." + key.name() + "." + instanceProperty, builderOverrideValue),
new HystrixPropertiesChainedProperty.DynamicBooleanProperty(propertyPrefix + ".threadpool.default." + instanceProperty, defaultValue)));
}

@SuppressWarnings("unused")
private static HystrixProperty<String> getProperty(String propertyPrefix, HystrixThreadPoolKey key, String instanceProperty, String builderOverrideValue, String defaultValue) {
return asProperty(new HystrixPropertiesChainedArchaiusProperty.StringProperty(
new HystrixPropertiesChainedArchaiusProperty.DynamicStringProperty(propertyPrefix + ".threadpool." + key.name() + "." + instanceProperty, builderOverrideValue),
new HystrixPropertiesChainedArchaiusProperty.DynamicStringProperty(propertyPrefix + ".threadpool.default." + instanceProperty, defaultValue)));
return asProperty(new HystrixPropertiesChainedProperty.StringProperty(
new HystrixPropertiesChainedProperty.DynamicStringProperty(propertyPrefix + ".threadpool." + key.name() + "." + instanceProperty, builderOverrideValue),
new HystrixPropertiesChainedProperty.DynamicStringProperty(propertyPrefix + ".threadpool.default." + instanceProperty, defaultValue)));
}

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.netflix.hystrix;

import com.netflix.hystrix.strategy.properties.HystrixPropertiesChainedArchaiusProperty;
import com.netflix.hystrix.strategy.properties.HystrixPropertiesChainedProperty;
import com.netflix.hystrix.strategy.properties.HystrixPropertiesStrategy;
import com.netflix.hystrix.strategy.properties.HystrixProperty;

Expand All @@ -24,8 +24,8 @@ protected HystrixTimerThreadPoolProperties(Setter setter) {
}

private static HystrixProperty<Integer> getProperty(String propertyPrefix, String instanceProperty, Integer defaultValue) {
return asProperty(new HystrixPropertiesChainedArchaiusProperty.IntegerProperty(
new HystrixPropertiesChainedArchaiusProperty.DynamicIntegerProperty(propertyPrefix + ".timer.threadpool.default." + instanceProperty, defaultValue)));
return asProperty(new HystrixPropertiesChainedProperty.IntegerProperty(
new HystrixPropertiesChainedProperty.DynamicIntegerProperty(propertyPrefix + ".timer.threadpool.default." + instanceProperty, defaultValue)));
}

public HystrixProperty<Integer> getCorePoolSize() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,10 @@ public HystrixDynamicProperty<Boolean> getBoolean(final String name, final Boole

@Override
public Boolean get() {
return System.getProperty(name) == null ? null : Boolean.getBoolean(name);
if (System.getProperty(name) == null) {
return fallback;
}
return Boolean.getBoolean(name);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* Copyright 2016 Netflix, Inc.
* Copyright 2012 Netflix, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -22,7 +22,7 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.netflix.hystrix.strategy.HystrixPlugins;
import com.netflix.config.PropertyWrapper;

/**
* Chained property allowing a chain of defaults using Archaius (https://github.com/Netflix/archaius) properties which is used by the default properties implementations.
Expand Down Expand Up @@ -289,76 +289,85 @@ public String getName() {
/**
* @ExcludeFromJavadoc
*/
public static class DynamicBooleanProperty extends DynamicPropertyWrapper<Boolean> {
public static class DynamicBooleanProperty extends PropertyWrapper<Boolean> {
public DynamicBooleanProperty(String propName, Boolean defaultValue) {
super(propName, defaultValue, Boolean.class);
super(propName, defaultValue);
}

/**
* Get the current value from the underlying DynamicProperty
*/
public Boolean get() {
return prop.getBoolean(defaultValue);
}

@Override
public Boolean getValue() {
return get();
}
}

/**
* @ExcludeFromJavadoc
*/
public static class DynamicIntegerProperty extends DynamicPropertyWrapper<Integer> {
public static class DynamicIntegerProperty extends PropertyWrapper<Integer> {
public DynamicIntegerProperty(String propName, Integer defaultValue) {
super(propName, defaultValue, Integer.class);
super(propName, defaultValue);
}

/**
* Get the current value from the underlying DynamicProperty
*/
public Integer get() {
return prop.getInteger(defaultValue);
}

@Override
public Integer getValue() {
return get();
}
}

/**
* @ExcludeFromJavadoc
*/
public static class DynamicLongProperty extends DynamicPropertyWrapper<Long> {
public static class DynamicLongProperty extends PropertyWrapper<Long> {
public DynamicLongProperty(String propName, Long defaultValue) {
super(propName, defaultValue, Long.class);
super(propName, defaultValue);
}

/**
* Get the current value from the underlying DynamicProperty
*/
public Long get() {
return prop.getLong(defaultValue);
}

@Override
public Long getValue() {
return get();
}
}

/**
* @ExcludeFromJavadoc
*/
public static class DynamicStringProperty extends DynamicPropertyWrapper<String> {
public static class DynamicStringProperty extends PropertyWrapper<String> {
public DynamicStringProperty(String propName, String defaultValue) {
super(propName, defaultValue, String.class);
}
}

private abstract static class DynamicPropertyWrapper<T> implements HystrixDynamicProperty<T> {

private final HystrixDynamicProperty<T> delegate;
private final String propName;

protected DynamicPropertyWrapper(String propName, T defaultValue, Class<T> type) {
super();
this.propName = propName;
this.delegate = getDynamicProperty(propName, defaultValue, type);
super(propName, defaultValue);
}

@Override
public T get() {
return delegate.get();
/**
* Get the current value from the underlying DynamicProperty
*/
public String get() {
return prop.getString(defaultValue);
}

@Override
public void addCallback(Runnable callback) {
delegate.addCallback(callback);
}

public String getName() {
return this.propName;
}

T getValue() {
public String getValue() {
return get();
}

}

private static <T> HystrixDynamicProperty<T>
getDynamicProperty(String propName, T defaultValue, Class<T> type) {
HystrixDynamicProperties properties = HystrixPlugins.getInstance().getDynamicProperties();
HystrixDynamicProperty<T> p =
HystrixDynamicProperties.Util.getProperty(properties, propName, defaultValue, type);
return p;
}

}
Loading

0 comments on commit 5d0e7ae

Please sign in to comment.