Allow reopening of master node

This commit is contained in:
Andrea Cavalli 2021-07-23 15:20:59 +02:00
parent fe7455dca7
commit b908607905

View File

@ -40,9 +40,11 @@ public class TdClusterManager {
private final ClusterManager mgr; private final ClusterManager mgr;
private final VertxOptions vertxOptions; private final VertxOptions vertxOptions;
private final Vertx vertx; private final Vertx vertx;
private final boolean isMaster;
@SuppressWarnings({"unchecked", "rawtypes"}) @SuppressWarnings({"unchecked", "rawtypes"})
public TdClusterManager(ClusterManager mgr, VertxOptions vertxOptions, Vertx vertx) { public TdClusterManager(ClusterManager mgr, VertxOptions vertxOptions, Vertx vertx, boolean isMaster) {
this.isMaster = isMaster;
this.mgr = mgr; this.mgr = mgr;
this.vertxOptions = vertxOptions; this.vertxOptions = vertxOptions;
this.vertx = vertx; this.vertx = vertx;
@ -78,7 +80,7 @@ public class TdClusterManager {
} }
return of(cfg, return of(cfg,
vertxOptions, vertxOptions,
keyStoreOptions, trustStoreOptions, masterHostname, netInterface, port, nodesAddresses); keyStoreOptions, trustStoreOptions, masterHostname, netInterface, port, nodesAddresses, true);
} else { } else {
return Mono.error(new AlreadyBoundException()); return Mono.error(new AlreadyBoundException());
} }
@ -96,7 +98,7 @@ public class TdClusterManager {
} else { } else {
cfg = null; cfg = null;
} }
return of(cfg, vertxOptions, keyStoreOptions, trustStoreOptions, masterHostname, netInterfaceF, port, nodesAddresses); return of(cfg, vertxOptions, keyStoreOptions, trustStoreOptions, masterHostname, netInterfaceF, port, nodesAddresses, false);
} else { } else {
return Mono.error(new AlreadyBoundException()); return Mono.error(new AlreadyBoundException());
} }
@ -110,7 +112,8 @@ public class TdClusterManager {
String masterHostname, String masterHostname,
String netInterface, String netInterface,
int port, int port,
Set<String> nodesAddresses) { Set<String> nodesAddresses,
boolean isMaster) {
ClusterManager mgr; ClusterManager mgr;
if (cfg != null) { if (cfg != null) {
cfg.getNetworkConfig().setPortCount(1); cfg.getNetworkConfig().setPortCount(1);
@ -191,7 +194,7 @@ public class TdClusterManager {
} }
}) })
.flatMap(vertx -> Mono .flatMap(vertx -> Mono
.fromCallable(() -> new TdClusterManager(mgr, vertxOptions, vertx)) .fromCallable(() -> new TdClusterManager(mgr, vertxOptions, vertx, isMaster))
.subscribeOn(Schedulers.boundedElastic()) .subscribeOn(Schedulers.boundedElastic())
); );
} }
@ -276,4 +279,12 @@ public class TdClusterManager {
public SharedData getSharedData() { public SharedData getSharedData() {
return vertx.sharedData(); return vertx.sharedData();
} }
public Mono<Void> close() {
return Mono.from(vertx.rxClose().toFlowable()).then(Mono.fromRunnable(() -> {
if (isMaster) {
definedMasterCluster.set(false);
}
}));
}
} }