Skip to content

Commit 68e0382

Browse files
committed
move GrpcUtil.getFlag to api
1 parent e84abc5 commit 68e0382

3 files changed

Lines changed: 66 additions & 13 deletions

File tree

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
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+
class FeatureFlags {
22+
static boolean getFlag(String envVarName, boolean enableByDefault) {
23+
String envVar = System.getenv(envVarName);
24+
if (envVar == null) {
25+
envVar = System.getProperty(envVarName);
26+
}
27+
if (envVar != null) {
28+
envVar = envVar.trim();
29+
}
30+
if (enableByDefault) {
31+
return Strings.isNullOrEmpty(envVar) || Boolean.parseBoolean(envVar);
32+
} else {
33+
return !Strings.isNullOrEmpty(envVar) && Boolean.parseBoolean(envVar);
34+
}
35+
}
36+
37+
private FeatureFlags() {}
38+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
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+
@Internal
20+
public class InternalFeatureFlags {
21+
public static boolean getFlag(String envVarName, boolean enableByDefault) {
22+
return FeatureFlags.getFlag(envVarName, enableByDefault);
23+
}
24+
25+
private InternalFeatureFlags() {}
26+
}

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)