|
126 | 126 | * |
127 | 127 | * }</pre> |
128 | 128 | */ |
129 | | -public final class Microservices { |
| 129 | +public final class Microservices implements AutoCloseable { |
130 | 130 |
|
131 | 131 | public static final Logger LOGGER = LoggerFactory.getLogger(Microservices.class); |
132 | 132 |
|
@@ -190,12 +190,8 @@ public String toString() { |
190 | 190 | private Mono<Microservices> start() { |
191 | 191 | LOGGER.info("[{}][start] Starting", id); |
192 | 192 |
|
193 | | - // Create bootstrap scheduler |
194 | | - Scheduler scheduler = Schedulers.newSingle(toString(), true); |
195 | | - |
196 | 193 | return transportBootstrap |
197 | 194 | .start(this) |
198 | | - .publishOn(scheduler) |
199 | 195 | .flatMap( |
200 | 196 | transportBootstrap -> { |
201 | 197 | final ServiceCall call = call(); |
@@ -229,19 +225,15 @@ private Mono<Microservices> start() { |
229 | 225 |
|
230 | 226 | return createDiscovery( |
231 | 227 | this, new ServiceDiscoveryOptions().serviceEndpoint(serviceEndpoint)) |
232 | | - .publishOn(scheduler) |
233 | 228 | .then(startGateway(new GatewayOptions().call(call))) |
234 | | - .publishOn(scheduler) |
235 | 229 | .then(Mono.fromCallable(() -> Injector.inject(this, serviceInstances))) |
236 | 230 | .then(Mono.fromCallable(() -> JmxMonitorMBean.start(this))) |
237 | 231 | .then(compositeDiscovery.startListen()) |
238 | | - .publishOn(scheduler) |
239 | 232 | .thenReturn(this); |
240 | 233 | }) |
241 | 234 | .onErrorResume( |
242 | 235 | ex -> Mono.defer(this::shutdown).then(Mono.error(ex)).cast(Microservices.class)) |
243 | | - .doOnSuccess(m -> LOGGER.info("[{}][start] Started", id)) |
244 | | - .doOnTerminate(scheduler::dispose); |
| 236 | + .doOnSuccess(m -> LOGGER.info("[{}][start] Started", id)); |
245 | 237 | } |
246 | 238 |
|
247 | 239 | private ServiceEndpoint newServiceEndpoint(ServiceEndpoint serviceEndpoint) { |
@@ -312,6 +304,18 @@ public List<ServiceEndpoint> serviceEndpoints() { |
312 | 304 | return serviceRegistry.listServiceEndpoints(); |
313 | 305 | } |
314 | 306 |
|
| 307 | + public Map<String, String> tags() { |
| 308 | + return tags; |
| 309 | + } |
| 310 | + |
| 311 | + public ServiceRegistry serviceRegistry() { |
| 312 | + return serviceRegistry; |
| 313 | + } |
| 314 | + |
| 315 | + public ServiceMethodRegistry methodRegistry() { |
| 316 | + return methodRegistry; |
| 317 | + } |
| 318 | + |
315 | 319 | /** |
316 | 320 | * Returns default service discovery context. |
317 | 321 | * |
@@ -393,6 +397,15 @@ private Mono<Void> processBeforeDestroy() { |
393 | 397 | .collect(Collectors.toList())); |
394 | 398 | } |
395 | 399 |
|
| 400 | + @Override |
| 401 | + public void close() { |
| 402 | + try { |
| 403 | + shutdown().toFuture().get(); |
| 404 | + } catch (Exception e) { |
| 405 | + throw new RuntimeException(e); |
| 406 | + } |
| 407 | + } |
| 408 | + |
396 | 409 | public static final class Builder { |
397 | 410 |
|
398 | 411 | private Map<String, String> tags = new HashMap<>(); |
|
0 commit comments