Skip to content

Commit 250378c

Browse files
committed
Fix for backward compatibility with Hystrix 1.4
1 parent e5075b0 commit 250378c

7 files changed

+469
-82
lines changed

hystrix-core/src/main/java/com/netflix/hystrix/HystrixCollapserProperties.java

+10-10
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717

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

20-
import com.netflix.hystrix.strategy.properties.HystrixPropertiesChainedArchaiusProperty;
20+
import com.netflix.hystrix.strategy.properties.HystrixPropertiesChainedProperty;
2121
import com.netflix.hystrix.strategy.properties.HystrixPropertiesStrategy;
2222
import com.netflix.hystrix.strategy.properties.HystrixProperty;
2323
import com.netflix.hystrix.util.HystrixRollingNumber;
@@ -72,22 +72,22 @@ protected HystrixCollapserProperties(HystrixCollapserKey key, Setter builder, St
7272
}
7373

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

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

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

9393
/**

hystrix-core/src/main/java/com/netflix/hystrix/HystrixCommandProperties.java

+16-16
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@
2222
import org.slf4j.Logger;
2323
import org.slf4j.LoggerFactory;
2424

25-
import com.netflix.hystrix.strategy.properties.HystrixPropertiesChainedArchaiusProperty;
26-
import com.netflix.hystrix.strategy.properties.HystrixPropertiesChainedArchaiusProperty.DynamicStringProperty;
25+
import com.netflix.hystrix.strategy.properties.HystrixPropertiesChainedProperty;
26+
import com.netflix.hystrix.strategy.properties.HystrixPropertiesChainedProperty.DynamicStringProperty;
2727
import com.netflix.hystrix.strategy.properties.HystrixPropertiesStrategy;
2828
import com.netflix.hystrix.strategy.properties.HystrixProperty;
2929
import com.netflix.hystrix.util.HystrixRollingNumber;
@@ -134,7 +134,7 @@ protected HystrixCommandProperties(HystrixCommandKey key, HystrixCommandProperti
134134
this.requestLogEnabled = getProperty(propertyPrefix, key, "requestLog.enabled", builder.getRequestLogEnabled(), default_requestLogEnabled);
135135

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

140140
/**
@@ -412,22 +412,22 @@ public HystrixProperty<Boolean> requestLogEnabled() {
412412
}
413413

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

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

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

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

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

456456
// initialize the enum value from the property
457457
parseProperty();

hystrix-core/src/main/java/com/netflix/hystrix/HystrixThreadPoolProperties.java

+10-10
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
import java.util.concurrent.TimeUnit;
2323

2424
import com.netflix.hystrix.strategy.concurrency.HystrixConcurrencyStrategy;
25-
import com.netflix.hystrix.strategy.properties.HystrixPropertiesChainedArchaiusProperty;
25+
import com.netflix.hystrix.strategy.properties.HystrixPropertiesChainedProperty;
2626
import com.netflix.hystrix.strategy.properties.HystrixPropertiesStrategy;
2727
import com.netflix.hystrix.strategy.properties.HystrixProperty;
2828
import com.netflix.hystrix.util.HystrixRollingNumber;
@@ -68,23 +68,23 @@ protected HystrixThreadPoolProperties(HystrixThreadPoolKey key, Setter builder,
6868
}
6969

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

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

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

9090
/**

hystrix-core/src/main/java/com/netflix/hystrix/HystrixTimerThreadPoolProperties.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
package com.netflix.hystrix;
22

3-
import com.netflix.hystrix.strategy.properties.HystrixPropertiesChainedArchaiusProperty;
3+
import com.netflix.hystrix.strategy.properties.HystrixPropertiesChainedProperty;
44
import com.netflix.hystrix.strategy.properties.HystrixPropertiesStrategy;
55
import com.netflix.hystrix.strategy.properties.HystrixProperty;
66

@@ -24,8 +24,8 @@ protected HystrixTimerThreadPoolProperties(Setter setter) {
2424
}
2525

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

3131
public HystrixProperty<Integer> getCorePoolSize() {

hystrix-core/src/main/java/com/netflix/hystrix/strategy/properties/HystrixPropertiesChainedArchaiusProperty.java

+52-43
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* Copyright 2016 Netflix, Inc.
2+
* Copyright 2012 Netflix, Inc.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -22,7 +22,7 @@
2222
import org.slf4j.Logger;
2323
import org.slf4j.LoggerFactory;
2424

25-
import com.netflix.hystrix.strategy.HystrixPlugins;
25+
import com.netflix.config.PropertyWrapper;
2626

2727
/**
2828
* Chained property allowing a chain of defaults using Archaius (https://github.com/Netflix/archaius) properties which is used by the default properties implementations.
@@ -289,76 +289,85 @@ public String getName() {
289289
/**
290290
* @ExcludeFromJavadoc
291291
*/
292-
public static class DynamicBooleanProperty extends DynamicPropertyWrapper<Boolean> {
292+
public static class DynamicBooleanProperty extends PropertyWrapper<Boolean> {
293293
public DynamicBooleanProperty(String propName, Boolean defaultValue) {
294-
super(propName, defaultValue, Boolean.class);
294+
super(propName, defaultValue);
295+
}
296+
297+
/**
298+
* Get the current value from the underlying DynamicProperty
299+
*/
300+
public Boolean get() {
301+
return prop.getBoolean(defaultValue);
302+
}
303+
304+
@Override
305+
public Boolean getValue() {
306+
return get();
295307
}
296308
}
297309

298310
/**
299311
* @ExcludeFromJavadoc
300312
*/
301-
public static class DynamicIntegerProperty extends DynamicPropertyWrapper<Integer> {
313+
public static class DynamicIntegerProperty extends PropertyWrapper<Integer> {
302314
public DynamicIntegerProperty(String propName, Integer defaultValue) {
303-
super(propName, defaultValue, Integer.class);
315+
super(propName, defaultValue);
316+
}
317+
318+
/**
319+
* Get the current value from the underlying DynamicProperty
320+
*/
321+
public Integer get() {
322+
return prop.getInteger(defaultValue);
323+
}
324+
325+
@Override
326+
public Integer getValue() {
327+
return get();
304328
}
305329
}
306330

307331
/**
308332
* @ExcludeFromJavadoc
309333
*/
310-
public static class DynamicLongProperty extends DynamicPropertyWrapper<Long> {
334+
public static class DynamicLongProperty extends PropertyWrapper<Long> {
311335
public DynamicLongProperty(String propName, Long defaultValue) {
312-
super(propName, defaultValue, Long.class);
336+
super(propName, defaultValue);
337+
}
338+
339+
/**
340+
* Get the current value from the underlying DynamicProperty
341+
*/
342+
public Long get() {
343+
return prop.getLong(defaultValue);
344+
}
345+
346+
@Override
347+
public Long getValue() {
348+
return get();
313349
}
314350
}
315351

316352
/**
317353
* @ExcludeFromJavadoc
318354
*/
319-
public static class DynamicStringProperty extends DynamicPropertyWrapper<String> {
355+
public static class DynamicStringProperty extends PropertyWrapper<String> {
320356
public DynamicStringProperty(String propName, String defaultValue) {
321-
super(propName, defaultValue, String.class);
322-
}
323-
}
324-
325-
private abstract static class DynamicPropertyWrapper<T> implements HystrixDynamicProperty<T> {
326-
327-
private final HystrixDynamicProperty<T> delegate;
328-
private final String propName;
329-
330-
protected DynamicPropertyWrapper(String propName, T defaultValue, Class<T> type) {
331-
super();
332-
this.propName = propName;
333-
this.delegate = getDynamicProperty(propName, defaultValue, type);
357+
super(propName, defaultValue);
334358
}
335359

336-
@Override
337-
public T get() {
338-
return delegate.get();
360+
/**
361+
* Get the current value from the underlying DynamicProperty
362+
*/
363+
public String get() {
364+
return prop.getString(defaultValue);
339365
}
340366

341367
@Override
342-
public void addCallback(Runnable callback) {
343-
delegate.addCallback(callback);
344-
}
345-
346-
public String getName() {
347-
return this.propName;
348-
}
349-
350-
T getValue() {
368+
public String getValue() {
351369
return get();
352370
}
353-
354-
}
355-
356-
private static <T> HystrixDynamicProperty<T>
357-
getDynamicProperty(String propName, T defaultValue, Class<T> type) {
358-
HystrixDynamicProperties properties = HystrixPlugins.getInstance().getDynamicProperties();
359-
HystrixDynamicProperty<T> p =
360-
HystrixDynamicProperties.Util.getProperty(properties, propName, defaultValue, type);
361-
return p;
362371
}
363372

364373
}

0 commit comments

Comments
 (0)