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

View File

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