Skip to content

Commit

Permalink
internal:Happy eyeballs (grpc#10731)
Browse files Browse the repository at this point in the history
* implement happy eyeballs

---------

Co-authored-by: tonyjongyoonan <tonyjan@google.com>
  • Loading branch information
larry-safran and tonyjongyoonan authored Jan 29, 2024
1 parent 8e1cc94 commit 7f4c16e
Show file tree
Hide file tree
Showing 4 changed files with 1,124 additions and 632 deletions.
5 changes: 4 additions & 1 deletion api/src/main/java/io/grpc/LoadBalancer.java
Original file line number Diff line number Diff line change
Expand Up @@ -955,6 +955,8 @@ public abstract static class Helper {
*
* <p>It must be called from {@link #getSynchronizationContext the Synchronization Context}
*
* @return Must return a valid Subchannel object, may not return null.
*
* @since 1.22.0
*/
public Subchannel createSubchannel(CreateSubchannelArgs args) {
Expand Down Expand Up @@ -1287,7 +1289,8 @@ public void start(SubchannelStateListener listener) {
*/
public final EquivalentAddressGroup getAddresses() {
List<EquivalentAddressGroup> groups = getAllAddresses();
Preconditions.checkState(groups.size() == 1, "%s does not have exactly one group", groups);
Preconditions.checkState(groups != null && groups.size() == 1,
"%s does not have exactly one group", groups);
return groups.get(0);
}

Expand Down
15 changes: 15 additions & 0 deletions core/src/main/java/io/grpc/internal/GrpcUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import com.google.common.base.Preconditions;
import com.google.common.base.Splitter;
import com.google.common.base.Stopwatch;
import com.google.common.base.Strings;
import com.google.common.base.Supplier;
import com.google.common.util.concurrent.ListenableFuture;
import com.google.common.util.concurrent.ThreadFactoryBuilder;
Expand Down Expand Up @@ -948,5 +949,19 @@ public static String encodeAuthority(String authority) {
}
}

public static boolean getFlag(String envVarName, boolean enableByDefault) {
String envVar = System.getenv(envVarName);
if (envVar == null) {
envVar = System.getProperty(envVarName);
}
if (enableByDefault) {
return Strings.isNullOrEmpty(envVar) || Boolean.parseBoolean(envVar);
} else {
return !Strings.isNullOrEmpty(envVar) && Boolean.parseBoolean(envVar);
}
}



private GrpcUtil() {}
}
Loading

0 comments on commit 7f4c16e

Please sign in to comment.