Shutdown before re-opening

This commit is contained in:
Volodymyr Babak 2020-06-05 14:23:21 +03:00
parent 138a0ba581
commit c677b1bdc3

View File

@ -79,6 +79,7 @@ public class EdgeGrpcClient implements EdgeRpcClient {
throw new RuntimeException(e);
}
}
gracefulShutdown();
channel = builder.build();
EdgeRpcServiceGrpc.EdgeRpcServiceStub stub = EdgeRpcServiceGrpc.newStub(channel);
log.info("[{}] Sending a connect request to the TB!", edgeKey);
@ -89,6 +90,16 @@ public class EdgeGrpcClient implements EdgeRpcClient {
.build());
}
private void gracefulShutdown() {
try {
if (channel != null) {
channel.shutdown().awaitTermination(timeoutSecs, TimeUnit.SECONDS);
}
} catch (InterruptedException e) {
log.debug("Error during shutdown of the previous channel", e);
}
}
@Override
public void disconnect() throws InterruptedException {
inputStream.onCompleted();