Showing
1 changed file
with
11 additions
and
0 deletions
@@ -79,6 +79,7 @@ public class EdgeGrpcClient implements EdgeRpcClient { | @@ -79,6 +79,7 @@ public class EdgeGrpcClient implements EdgeRpcClient { | ||
79 | throw new RuntimeException(e); | 79 | throw new RuntimeException(e); |
80 | } | 80 | } |
81 | } | 81 | } |
82 | + gracefulShutdown(); | ||
82 | channel = builder.build(); | 83 | channel = builder.build(); |
83 | EdgeRpcServiceGrpc.EdgeRpcServiceStub stub = EdgeRpcServiceGrpc.newStub(channel); | 84 | EdgeRpcServiceGrpc.EdgeRpcServiceStub stub = EdgeRpcServiceGrpc.newStub(channel); |
84 | log.info("[{}] Sending a connect request to the TB!", edgeKey); | 85 | log.info("[{}] Sending a connect request to the TB!", edgeKey); |
@@ -89,6 +90,16 @@ public class EdgeGrpcClient implements EdgeRpcClient { | @@ -89,6 +90,16 @@ public class EdgeGrpcClient implements EdgeRpcClient { | ||
89 | .build()); | 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 | @Override | 103 | @Override |
93 | public void disconnect() throws InterruptedException { | 104 | public void disconnect() throws InterruptedException { |
94 | inputStream.onCompleted(); | 105 | inputStream.onCompleted(); |