forked from TrueCloudLab/frostfs-sdk-java
[#1] code cleanup
update README.md Signed-off-by: Ori Bruk <o.bruk@yadro.com>
This commit is contained in:
parent
b0db7df192
commit
a7fab6f314
28 changed files with 177 additions and 203 deletions
26
client/src/main/java/info/FrostFS/sdk/tools/GrpcClient.java
Normal file
26
client/src/main/java/info/FrostFS/sdk/tools/GrpcClient.java
Normal file
|
@ -0,0 +1,26 @@
|
|||
package info.FrostFS.sdk.tools;
|
||||
|
||||
import io.grpc.Channel;
|
||||
import io.grpc.ChannelCredentials;
|
||||
import io.grpc.netty.NettyChannelBuilder;
|
||||
|
||||
import java.net.URI;
|
||||
import java.net.URISyntaxException;
|
||||
|
||||
import static java.util.Objects.isNull;
|
||||
|
||||
public class GrpcClient {
|
||||
private static final String ERROR_INVALID_HOST_TEMPLATE = "Host %s has invalid format. Error: %s";
|
||||
|
||||
public static Channel initGrpcChannel(String host, ChannelCredentials creds) {
|
||||
try {
|
||||
URI uri = new URI(host);
|
||||
var channelBuilder = isNull(creds) ? NettyChannelBuilder.forAddress(uri.getHost(), uri.getPort())
|
||||
: NettyChannelBuilder.forAddress(uri.getHost(), uri.getPort(), creds);
|
||||
|
||||
return channelBuilder.usePlaintext().build();
|
||||
} catch (URISyntaxException exp) {
|
||||
throw new IllegalArgumentException(String.format(ERROR_INVALID_HOST_TEMPLATE, host, exp.getMessage()));
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue