Commit c677b1bdc305bc48338a9fb9c7776da00d7139bf

Authored by Volodymyr Babak
1 parent 138a0ba5

Shutdown before re-opening

... ... @@ -79,6 +79,7 @@ public class EdgeGrpcClient implements EdgeRpcClient {
79 79 throw new RuntimeException(e);
80 80 }
81 81 }
  82 + gracefulShutdown();
82 83 channel = builder.build();
83 84 EdgeRpcServiceGrpc.EdgeRpcServiceStub stub = EdgeRpcServiceGrpc.newStub(channel);
84 85 log.info("[{}] Sending a connect request to the TB!", edgeKey);
... ... @@ -89,6 +90,16 @@ public class EdgeGrpcClient implements EdgeRpcClient {
89 90 .build());
90 91 }
91 92
  93 + private void gracefulShutdown() {
  94 + try {
  95 + if (channel != null) {
  96 + channel.shutdown().awaitTermination(timeoutSecs, TimeUnit.SECONDS);
  97 + }
  98 + } catch (InterruptedException e) {
  99 + log.debug("Error during shutdown of the previous channel", e);
  100 + }
  101 + }
  102 +
92 103 @Override
93 104 public void disconnect() throws InterruptedException {
94 105 inputStream.onCompleted();
... ...