Skip to content

Commit

Permalink
Simplify chained properties and expose less public methods/classes.
Browse files Browse the repository at this point in the history
  • Loading branch information
agentgt committed Feb 4, 2016
1 parent 5d0e7ae commit cae8191
Show file tree
Hide file tree
Showing 9 changed files with 170 additions and 238 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,10 @@
*/
package com.netflix.hystrix;

import static com.netflix.hystrix.strategy.properties.HystrixProperty.Factory.asProperty;
import static com.netflix.hystrix.strategy.properties.HystrixPropertiesChainedProperty.forBoolean;
import static com.netflix.hystrix.strategy.properties.HystrixPropertiesChainedProperty.forInteger;
import static com.netflix.hystrix.strategy.properties.HystrixPropertiesChainedProperty.forString;

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 +73,27 @@ 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 HystrixPropertiesChainedProperty.IntegerProperty(
new HystrixPropertiesChainedProperty.DynamicIntegerProperty(propertyPrefix + ".collapser." + key.name() + "." + instanceProperty, builderOverrideValue),
new HystrixPropertiesChainedProperty.DynamicIntegerProperty(propertyPrefix + ".collapser.default." + instanceProperty, defaultValue)));
return forInteger()
.add(propertyPrefix + ".collapser." + key.name() + "." + instanceProperty, builderOverrideValue)
.add(propertyPrefix + ".collapser.default." + instanceProperty, defaultValue)
.build();


}

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

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

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

import static com.netflix.hystrix.strategy.properties.HystrixProperty.Factory.asProperty;
import static com.netflix.hystrix.strategy.properties.HystrixPropertiesChainedProperty.forBoolean;
import static com.netflix.hystrix.strategy.properties.HystrixPropertiesChainedProperty.forInteger;
import static com.netflix.hystrix.strategy.properties.HystrixPropertiesChainedProperty.forString;

import java.util.concurrent.Future;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.netflix.hystrix.strategy.properties.HystrixPropertiesChainedProperty;
import com.netflix.hystrix.strategy.properties.HystrixPropertiesChainedProperty.DynamicStringProperty;
import com.netflix.hystrix.strategy.properties.HystrixDynamicProperty;
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 +135,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 = new DynamicStringProperty(propertyPrefix + ".command." + key.name() + ".threadPoolKeyOverride", null);
this.executionIsolationThreadPoolKeyOverride = forString().add(propertyPrefix + ".command." + key.name() + ".threadPoolKeyOverride", null).build();
}

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

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

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

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

private static HystrixProperty<ExecutionIsolationStrategy> getProperty(final String propertyPrefix, final HystrixCommandKey key, final String instanceProperty, final ExecutionIsolationStrategy builderOverrideValue, final ExecutionIsolationStrategy defaultValue) {
Expand All @@ -439,7 +443,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 HystrixPropertiesChainedProperty.StringProperty property;
private final HystrixDynamicProperty<String> property;
private volatile ExecutionIsolationStrategy value;
private final ExecutionIsolationStrategy defaultValue;

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

// initialize the enum value from the property
parseProperty();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,15 @@
*/
package com.netflix.hystrix;

import static com.netflix.hystrix.strategy.properties.HystrixProperty.Factory.asProperty;
import static com.netflix.hystrix.strategy.properties.HystrixPropertiesChainedProperty.forBoolean;
import static com.netflix.hystrix.strategy.properties.HystrixPropertiesChainedProperty.forInteger;
import static com.netflix.hystrix.strategy.properties.HystrixPropertiesChainedProperty.forString;

import java.util.concurrent.BlockingQueue;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

import com.netflix.hystrix.strategy.concurrency.HystrixConcurrencyStrategy;
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 +69,26 @@ protected HystrixThreadPoolProperties(HystrixThreadPoolKey key, Setter builder,
}

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

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

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

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

import com.netflix.hystrix.strategy.properties.HystrixPropertiesChainedProperty;
import static com.netflix.hystrix.strategy.properties.HystrixPropertiesChainedProperty.forInteger;

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

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

/**
* Properties for Hystrix timer thread pool.
* <p>
Expand All @@ -24,8 +23,10 @@ protected HystrixTimerThreadPoolProperties(Setter setter) {
}

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

return forInteger()
.add(propertyPrefix + ".timer.threadpool.default." + instanceProperty, defaultValue)
.build();
}

public HystrixProperty<Integer> getCorePoolSize() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,11 @@ private static class SystemPropertiesHystrixDynamicProperties implements Hystrix
public HystrixDynamicProperty<Integer> getInteger(final String name, final Integer fallback) {
return new HystrixDynamicProperty<Integer>() {

@Override
public String getName() {
return name;
}

@Override
public Integer get() {
return Integer.getInteger(name, fallback);
Expand All @@ -101,6 +106,11 @@ public void addCallback(Runnable callback) {
public HystrixDynamicProperty<String> getString(final String name, final String fallback) {
return new HystrixDynamicProperty<String>() {

@Override
public String getName() {
return name;
}

@Override
public String get() {
return System.getProperty(name, fallback);
Expand All @@ -116,6 +126,11 @@ public void addCallback(Runnable callback) {
public HystrixDynamicProperty<Long> getLong(final String name, final Long fallback) {
return new HystrixDynamicProperty<Long>() {

@Override
public String getName() {
return name;
}

@Override
public Long get() {
return Long.getLong(name, fallback);
Expand All @@ -131,6 +146,10 @@ public void addCallback(Runnable callback) {
public HystrixDynamicProperty<Boolean> getBoolean(final String name, final Boolean fallback) {
return new HystrixDynamicProperty<Boolean>() {

@Override
public String getName() {
return name;
}
@Override
public Boolean get() {
if (System.getProperty(name) == null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@
*/
public interface HystrixDynamicProperty<T> extends HystrixProperty<T>{

public String getName();

/**
* Register a callback to be run if the property is updated.
* Backing implementations may choose to do nothing.
Expand Down
Loading

0 comments on commit cae8191

Please sign in to comment.