Skip to content

Commit

Permalink
Apply comments
Browse files Browse the repository at this point in the history
- Refactor `getValue` to delegate some logic into `getUserValue`
- Fix documentation for uniformity
  • Loading branch information
seonWKim committed Dec 3, 2023
1 parent 711c984 commit 0936f9a
Showing 1 changed file with 17 additions and 21 deletions.
38 changes: 17 additions & 21 deletions core/src/main/java/com/linecorp/armeria/common/Flags.java
Original file line number Diff line number Diff line change
Expand Up @@ -568,8 +568,10 @@ private static void setUseOpenSslAndDumpOpenSslInfo() {
return;
}

final Boolean useOpenSsl = getUserValue(FlagsProvider::useOpenSsl, "useOpenSsl");
final TlsEngineType tlsEngineTypeValue = getUserValue(FlagsProvider::tlsEngineType, "tlsEngineType");
final Boolean useOpenSsl = getUserValue(FlagsProvider::useOpenSsl, "useOpenSsl",
ignored -> true);
final TlsEngineType tlsEngineTypeValue = getUserValue(FlagsProvider::tlsEngineType,
"tlsEngineType", ignored -> true);

if (useOpenSsl == null) {
tlsEngineType = tlsEngineTypeValue != null ? tlsEngineTypeValue : TlsEngineType.OPENSSL;
Expand Down Expand Up @@ -615,7 +617,7 @@ private static void setUseOpenSslAndDumpOpenSslInfo() {
* option to enable it.
*
* <p>If {@link #tlsEngineType()} does not return {@link TlsEngineType#OPENSSL}, this also returns
* {@code false} no matter you specified the JVM option.
* {@code false} no matter what the specified JVM option is.
*/
public static boolean dumpOpenSslInfo() {
if (dumpOpenSslInfo != null) {
Expand Down Expand Up @@ -1589,28 +1591,17 @@ private static <T> T getValue(Function<FlagsProvider, @Nullable T> method, Strin

private static <T> T getValue(Function<FlagsProvider, @Nullable T> method,
String flagName, Predicate<T> validator) {
for (FlagsProvider provider : FLAGS_PROVIDERS) {
try {
final T value = method.apply(provider);
if (value == null) {
continue;
}
if (!validator.test(value)) {
logger.warn("{}: {} ({}, validation failed)", flagName, value, provider.name());
continue;
}
logger.info("{}: {} ({})", flagName, value, provider.name());
return value;
} catch (Exception ex) {
logger.warn("{}: ({}, {})", flagName, provider.name(), ex.getMessage());
}
final T t = getUserValue(method, flagName, validator);
if (t != null) {
return t;
}
// Should never reach here because DefaultFlagsProvider always returns a normal value.
throw new Error();

return method.apply(DefaultFlagsProvider.INSTANCE);
}

@Nullable
private static <T> T getUserValue(Function<FlagsProvider, @Nullable T> method, String flagName) {
private static <T> T getUserValue(Function<FlagsProvider, @Nullable T> method, String flagName,
Predicate<T> validator) {
for (FlagsProvider provider : FLAGS_PROVIDERS) {
if (provider instanceof DefaultFlagsProvider) {
continue;
Expand All @@ -1622,6 +1613,11 @@ private static <T> T getUserValue(Function<FlagsProvider, @Nullable T> method, S
continue;
}

if (!validator.test(value)) {
logger.warn("{}: {} ({}, validation failed)", flagName, value, provider.name());
continue;
}

logger.info("{}: {} ({})", flagName, value, provider.name());
return value;
} catch (Exception ex) {
Expand Down

0 comments on commit 0936f9a

Please sign in to comment.