Skip to content

Dualstack example #11451

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

Merged
merged 7 commits into from
Aug 8, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Added javadoc and eliminated unnecessary null checks.
  • Loading branch information
larry-safran committed Aug 8, 2024
commit 8acb4c0cb914a635d96d7797248836960e2a8514
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,14 @@
import java.util.logging.Level;
import java.util.logging.Logger;

/**
* A client that requests greetings from the {@link DualStackServer}.
* First it sends 5 requests using the default nameresolver and load balancer.
* Then it sends 10 requests using the example nameresolver and round robin load balancer. These
* requests are evenly distributed among the 3 servers rather than favoring the server listening
* on both addresses because the ExampleDualStackNameResolver groups the 3 servers as 3 endpoints
* each with 2 addresses.
*/
public class DualStackClient {
public static final String channelTarget = "example:///lb.example.grpc.io";
private static final Logger logger = Logger.getLogger(DualStackClient.class.getName());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,11 @@
import java.util.concurrent.TimeUnit;
import java.util.logging.Logger;

/**
* Starts 3 different greeter services each on its own port, but all for localhost.
* The first service listens on both IPv4 and IPv6,
* the second on just IPv4, and the third on just IPv6.
*/
public class DualStackServer {
private static final Logger logger = Logger.getLogger(DualStackServer.class.getName());
private List<Server> servers;
Expand Down Expand Up @@ -89,17 +94,13 @@ private void start() throws IOException {

private void stop() throws InterruptedException {
for (Server server : servers) {
if (server != null) {
server.shutdown().awaitTermination(30, TimeUnit.SECONDS);
}
server.shutdown().awaitTermination(30, TimeUnit.SECONDS);
}
}

private void blockUntilShutdown() throws InterruptedException {
for (Server server : servers) {
if (server != null) {
server.awaitTermination();
}
server.awaitTermination();
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@
import java.util.List;
import java.util.stream.Collectors;

/**
* A fake name resolver that resolves to a hard-coded list of 3 endpoints (EquivalentAddressGropu)
* each with 2 addresses (one IPv4 and one IPv6).
*/
public class ExampleDualStackNameResolver extends NameResolver {
static public final int[] SERVER_PORTS = {50051, 50052, 50053};

Expand Down
Loading