Skip to content

Commit

Permalink
chore: use target instead of name resolver factory (#3306)
Browse files Browse the repository at this point in the history
  • Loading branch information
siyuan0322 authored Oct 23, 2023
1 parent 2d19869 commit 43f5176
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 81 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@
import io.grpc.stub.StreamObserver;

import java.io.IOException;
import java.net.InetSocketAddress;
import java.net.SocketAddress;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Path;
Expand Down Expand Up @@ -466,30 +464,19 @@ public static GrootClientBuilder newBuilder() {
}

public static class GrootClientBuilder {
private List<SocketAddress> addrs;
private String target;
private String username;
private String password;

private GrootClientBuilder() {
this.addrs = new ArrayList<>();
}

public GrootClientBuilder addAddress(SocketAddress address) {
this.addrs.add(address);
return this;
}
private GrootClientBuilder() {}

public GrootClientBuilder addHost(String host, int port) {
return this.addAddress(new InetSocketAddress(host, port));
target = host + ":" + port;
return this;
}

public GrootClientBuilder setHosts(String hosts) {
List<SocketAddress> addresses = new ArrayList<>();
for (String host : hosts.split(",")) {
String[] items = host.split(":");
addresses.add(new InetSocketAddress(items[0], Integer.valueOf(items[1])));
}
this.addrs = addresses;
public GrootClientBuilder setHosts(String target) {
this.target = target;
return this;
}

Expand All @@ -504,14 +491,12 @@ public GrootClientBuilder setPassword(String password) {
}

public GrootClient build() {
MultiAddrResovlerFactory multiAddrResovlerFactory =
new MultiAddrResovlerFactory(this.addrs);
ManagedChannel channel =
ManagedChannelBuilder.forTarget("hosts")
.nameResolverFactory(multiAddrResovlerFactory)
ManagedChannelBuilder.forTarget(target)
.defaultLoadBalancingPolicy("round_robin")
.usePlaintext()
.build();

ClientGrpc.ClientBlockingStub clientBlockingStub = ClientGrpc.newBlockingStub(channel);
ClientWriteGrpc.ClientWriteBlockingStub clientWriteBlockingStub =
ClientWriteGrpc.newBlockingStub(channel);
Expand Down

This file was deleted.

0 comments on commit 43f5176

Please sign in to comment.