-
Notifications
You must be signed in to change notification settings - Fork 4.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Make Archaius a soft dependency through reflection and improve plugin… #1083
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
27b6fe1
Make Archaius a soft dependency through reflection and improve plugin…
agentgt 59a3c91
Fix documentation and some code cleanup.
agentgt e5075b0
Added lazy loading and unit tests.
agentgt 5d0e7ae
Fix for backward compatibility with Hystrix 1.4
agentgt cae8191
Simplify chained properties and expose less public methods/classes.
agentgt ab456d9
Fix unit test.
agentgt 664430f
Add system property to pick HystrixDynamicProperties and made Archaiu…
agentgt a1bc5d8
Updates based on @mattrjacobs comments
agentgt File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
90 changes: 90 additions & 0 deletions
90
hystrix-core/src/main/java/com/netflix/hystrix/strategy/HystrixArchaiusHelper.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
/** | ||
* Copyright 2016 Netflix, Inc. | ||
* <p/> | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* <p/> | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* <p/> | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package com.netflix.hystrix.strategy; | ||
|
||
import java.lang.reflect.InvocationTargetException; | ||
import java.lang.reflect.Method; | ||
|
||
import com.netflix.hystrix.strategy.properties.HystrixDynamicProperties; | ||
|
||
/** | ||
* @ExcludeFromJavadoc | ||
* @author agentgt | ||
*/ | ||
class HystrixArchaiusHelper { | ||
|
||
/** | ||
* To keep class loading minimal for those that have archaius in the classpath but choose not to use it. | ||
* @ExcludeFromJavadoc | ||
* @author agent | ||
*/ | ||
private static class LazyHolder { | ||
private final static Method loadCascadedPropertiesFromResources; | ||
private final static String CONFIG_MANAGER_CLASS = "com.netflix.config.ConfigurationManager"; | ||
|
||
static { | ||
Method load = null; | ||
try { | ||
Class<?> configManager = Class.forName(CONFIG_MANAGER_CLASS); | ||
load = configManager.getMethod("loadCascadedPropertiesFromResources", String.class); | ||
} catch (Exception e) { | ||
} | ||
|
||
loadCascadedPropertiesFromResources = load; | ||
} | ||
} | ||
|
||
/** | ||
* @ExcludeFromJavadoc | ||
*/ | ||
static boolean isArchaiusV1Available() { | ||
return LazyHolder.loadCascadedPropertiesFromResources != null; | ||
} | ||
|
||
static void loadCascadedPropertiesFromResources(String name) { | ||
if (isArchaiusV1Available()) { | ||
try { | ||
LazyHolder.loadCascadedPropertiesFromResources.invoke(null, name); | ||
} catch (IllegalAccessException e) { | ||
} catch (IllegalArgumentException e) { | ||
} catch (InvocationTargetException e) { | ||
} | ||
} | ||
} | ||
|
||
/** | ||
* @ExcludeFromJavadoc | ||
*/ | ||
static HystrixDynamicProperties createArchaiusDynamicProperties() { | ||
if (isArchaiusV1Available()) { | ||
loadCascadedPropertiesFromResources("hystrix-plugins"); | ||
try { | ||
Class<?> defaultProperties = Class.forName( | ||
"com.netflix.hystrix.strategy.properties.archaius" + ".HystrixDynamicPropertiesArchaius"); | ||
return (HystrixDynamicProperties) defaultProperties.newInstance(); | ||
} catch (ClassNotFoundException e) { | ||
throw new RuntimeException(e); | ||
} catch (InstantiationException e) { | ||
throw new RuntimeException(e); | ||
} catch (IllegalAccessException e) { | ||
throw new RuntimeException(e); | ||
} | ||
} | ||
// Fallback to System properties. | ||
return null; | ||
} | ||
|
||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What about the return value here? If we find implementations in the
hystrix-plugins
file, shouldn't we try to instantiate them and return them? Or am I missing something?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Basically this code comes from the original 1.4 code https://github.com/Netflix/Hystrix/blob/1.4.x/hystrix-core/src/main/java/com/netflix/hystrix/strategy/HystrixPlugins.java#L57
What it does is indirectly boots up Archaius and adds the hystrix-plugins properties file as an additional configuration resource. The actual method does not return anything.The assumption here is Archaius isn't going to provide configuration properties to point to use a different
HystrixDynamicProperties
.This is only to create
HystrixDynamicProperties
... all the other implementations will be loaded using cascaded configuration (assuming you have Archaius). That ishystrix-plugins.properties
will be used.This does bring up an excellent point though that theHystrixDynamicPropertiesSystemProperties
(I picked that name to be consistent with the naming scheme) perhaps should loadhystrix-plugins.properties
? Let me know what you think about that.EDIT actually I think its a bad idea given the properties file could have string interpolation characters and/or could be a more advanced properties file (e.g. commons config style and is UTF-8... standard properties files are shockingly not UTF-8 but ISO).