|
32 | 32 | import dev.failsafe.RetryPolicy; |
33 | 33 | import java.util.Collections; |
34 | 34 | import java.util.Set; |
| 35 | +import java.util.concurrent.ExecutorService; |
35 | 36 | import java.util.concurrent.Executors; |
36 | 37 | import java.util.concurrent.atomic.AtomicBoolean; |
37 | 38 | import java.util.logging.Level; |
@@ -200,25 +201,26 @@ public NettyServer start() { |
200 | 201 | .build(); |
201 | 202 |
|
202 | 203 | LOG.info("Starting registration process for Node " + node.getUri()); |
203 | | - Executors.newSingleThreadExecutor() |
204 | | - .submit( |
205 | | - () -> { |
206 | | - Failsafe.with(registrationPolicy) |
207 | | - .run( |
208 | | - () -> { |
209 | | - if (nodeRegistered.get()) { |
210 | | - throw new InterruptedException("Stopping registration thread."); |
211 | | - } |
212 | | - HealthCheck.Result check = node.getHealthCheck().check(); |
213 | | - if (DOWN.equals(check.getAvailability())) { |
214 | | - LOG.severe("Node is not alive: " + check.getMessage()); |
215 | | - // Throw an exception to force another check sooner. |
216 | | - throw new UnsupportedOperationException("Node cannot be registered"); |
217 | | - } |
218 | | - bus.fire(new NodeStatusEvent(node.getStatus())); |
219 | | - LOG.info("Sending registration event..."); |
220 | | - }); |
221 | | - }); |
| 204 | + ExecutorService executor = Executors.newSingleThreadExecutor(); |
| 205 | + executor.submit( |
| 206 | + () -> { |
| 207 | + Failsafe.with(registrationPolicy) |
| 208 | + .run( |
| 209 | + () -> { |
| 210 | + if (nodeRegistered.get()) { |
| 211 | + throw new InterruptedException("Stopping registration thread."); |
| 212 | + } |
| 213 | + HealthCheck.Result check = node.getHealthCheck().check(); |
| 214 | + if (DOWN.equals(check.getAvailability())) { |
| 215 | + LOG.severe("Node is not alive: " + check.getMessage()); |
| 216 | + // Throw an exception to force another check sooner. |
| 217 | + throw new UnsupportedOperationException("Node cannot be registered"); |
| 218 | + } |
| 219 | + bus.fire(new NodeStatusEvent(node.getStatus())); |
| 220 | + LOG.info("Sending registration event..."); |
| 221 | + }); |
| 222 | + }); |
| 223 | + executor.shutdown(); |
222 | 224 |
|
223 | 225 | return this; |
224 | 226 | } |
|
0 commit comments