Skip to content

Commit 7eee128

Browse files
committed
move GrpcUtil.getFlag to api
1 parent 53d97d4 commit 7eee128

File tree

2 files changed

+41
-13
lines changed

2 files changed

+41
-13
lines changed
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
/*
2+
* Copyright 2026 The gRPC Authors
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package io.grpc;
18+
19+
import com.google.common.base.Strings;
20+
21+
@Internal
22+
public class InternalFeatureFlags {
23+
public static boolean getFlag(String envVarName, boolean enableByDefault) {
24+
String envVar = System.getenv(envVarName);
25+
if (envVar == null) {
26+
envVar = System.getProperty(envVarName);
27+
}
28+
if (envVar != null) {
29+
envVar = envVar.trim();
30+
}
31+
if (enableByDefault) {
32+
return Strings.isNullOrEmpty(envVar) || Boolean.parseBoolean(envVar);
33+
} else {
34+
return !Strings.isNullOrEmpty(envVar) && Boolean.parseBoolean(envVar);
35+
}
36+
}
37+
38+
private InternalFeatureFlags() {}
39+
}

core/src/main/java/io/grpc/internal/GrpcUtil.java

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,14 @@
2424
import com.google.common.base.Preconditions;
2525
import com.google.common.base.Splitter;
2626
import com.google.common.base.Stopwatch;
27-
import com.google.common.base.Strings;
2827
import com.google.common.base.Supplier;
2928
import com.google.common.util.concurrent.ListenableFuture;
3029
import com.google.common.util.concurrent.ThreadFactoryBuilder;
3130
import io.grpc.CallOptions;
3231
import io.grpc.ClientStreamTracer;
3332
import io.grpc.ClientStreamTracer.StreamInfo;
3433
import io.grpc.InternalChannelz.SocketStats;
34+
import io.grpc.InternalFeatureFlags;
3535
import io.grpc.InternalLogId;
3636
import io.grpc.InternalMetadata;
3737
import io.grpc.InternalMetadata.TrustedAsciiMarshaller;
@@ -958,18 +958,7 @@ public static String encodeAuthority(String authority) {
958958
}
959959

960960
public static boolean getFlag(String envVarName, boolean enableByDefault) {
961-
String envVar = System.getenv(envVarName);
962-
if (envVar == null) {
963-
envVar = System.getProperty(envVarName);
964-
}
965-
if (envVar != null) {
966-
envVar = envVar.trim();
967-
}
968-
if (enableByDefault) {
969-
return Strings.isNullOrEmpty(envVar) || Boolean.parseBoolean(envVar);
970-
} else {
971-
return !Strings.isNullOrEmpty(envVar) && Boolean.parseBoolean(envVar);
972-
}
961+
return InternalFeatureFlags.getFlag(envVarName, enableByDefault);
973962
}
974963

975964

0 commit comments

Comments
 (0)