Add temporary addresses during pre-deploy

This commit is contained in:
Andrea Cavalli 2021-01-22 13:00:36 +01:00
parent cc56dd4598
commit 26eb359238
2 changed files with 10 additions and 1 deletions

View File

@ -13,6 +13,7 @@ import java.util.stream.Collectors;
public class RemoteClientBotAddresses { public class RemoteClientBotAddresses {
private final LinkedHashSet<String> addresses; private final LinkedHashSet<String> addresses;
private final LinkedHashSet<String> tempAddresses;
private final Path addressesFilePath; private final Path addressesFilePath;
public RemoteClientBotAddresses(Path addressesFilePath) throws IOException { public RemoteClientBotAddresses(Path addressesFilePath) throws IOException {
@ -20,6 +21,7 @@ public class RemoteClientBotAddresses {
if (Files.notExists(addressesFilePath)) { if (Files.notExists(addressesFilePath)) {
Files.createFile(addressesFilePath); Files.createFile(addressesFilePath);
} }
tempAddresses = new LinkedHashSet<>();
addresses = Files addresses = Files
.readAllLines(addressesFilePath, StandardCharsets.UTF_8) .readAllLines(addressesFilePath, StandardCharsets.UTF_8)
.stream() .stream()
@ -28,17 +30,23 @@ public class RemoteClientBotAddresses {
} }
public synchronized void putAddress(String address) throws IOException { public synchronized void putAddress(String address) throws IOException {
tempAddresses.remove(address);
addresses.add(address); addresses.add(address);
Files.write(addressesFilePath, addresses, StandardCharsets.UTF_8, StandardOpenOption.CREATE, StandardOpenOption.SYNC); Files.write(addressesFilePath, addresses, StandardCharsets.UTF_8, StandardOpenOption.CREATE, StandardOpenOption.SYNC);
} }
public synchronized void putTempAddress(String address) {
tempAddresses.add(address);
}
public synchronized void removeAddress(String address) throws IOException { public synchronized void removeAddress(String address) throws IOException {
tempAddresses.remove(address);
addresses.remove(address); addresses.remove(address);
Files.write(addressesFilePath, addresses, StandardCharsets.UTF_8, StandardOpenOption.CREATE, StandardOpenOption.SYNC); Files.write(addressesFilePath, addresses, StandardCharsets.UTF_8, StandardOpenOption.CREATE, StandardOpenOption.SYNC);
} }
public synchronized boolean has(String botAddress) { public synchronized boolean has(String botAddress) {
return addresses.contains(botAddress); return addresses.contains(botAddress) || tempAddresses.contains(botAddress);
} }
public synchronized Set<String> values() { public synchronized Set<String> values() {

View File

@ -190,6 +190,7 @@ public class TDLibRemoteClient implements AutoCloseable {
deploymentLock.release(); deploymentLock.release();
}); });
} else { } else {
botAddresses.putTempAddress(botAddress);
deployableBotAddresses.putIfAbsent(botAddress, netInterface, putResult -> { deployableBotAddresses.putIfAbsent(botAddress, netInterface, putResult -> {
if (putResult.succeeded()) { if (putResult.succeeded()) {
if (putResult.result() == null) { if (putResult.result() == null) {