diff --git a/core/src/main/java/bisq/core/trade/ClosedTradableManager.java b/core/src/main/java/bisq/core/trade/ClosedTradableManager.java index 92fec33df1..38419132ec 100644 --- a/core/src/main/java/bisq/core/trade/ClosedTradableManager.java +++ b/core/src/main/java/bisq/core/trade/ClosedTradableManager.java @@ -109,15 +109,19 @@ public class ClosedTradableManager implements PersistedDataHost { } public void add(Tradable tradable) { - if (closedTradables.add(tradable)) { - maybeClearSensitiveData(); - requestPersistence(); + synchronized (closedTradables) { + if (closedTradables.add(tradable)) { + maybeClearSensitiveData(); + requestPersistence(); + } } } public void remove(Tradable tradable) { - if (closedTradables.remove(tradable)) { - requestPersistence(); + synchronized (closedTradables) { + if (closedTradables.remove(tradable)) { + requestPersistence(); + } } } @@ -126,7 +130,9 @@ public class ClosedTradableManager implements PersistedDataHost { } public ObservableList getObservableList() { - return closedTradables.getObservableList(); + synchronized (closedTradables) { + return closedTradables.getObservableList(); + } } public List getTradableList() { @@ -134,43 +140,55 @@ public class ClosedTradableManager implements PersistedDataHost { } public List getClosedTrades() { - return ImmutableList.copyOf(getObservableList().stream() - .filter(e -> e instanceof Trade) - .map(e -> (Trade) e) - .collect(Collectors.toList())); + synchronized (closedTradables) { + return ImmutableList.copyOf(getObservableList().stream() + .filter(e -> e instanceof Trade) + .map(e -> (Trade) e) + .collect(Collectors.toList())); + } } public List getCanceledOpenOffers() { - return ImmutableList.copyOf(getObservableList().stream() - .filter(e -> (e instanceof OpenOffer) && ((OpenOffer) e).getState().equals(CANCELED)) - .map(e -> (OpenOffer) e) - .collect(Collectors.toList())); + synchronized (closedTradables) { + return ImmutableList.copyOf(getObservableList().stream() + .filter(e -> (e instanceof OpenOffer) && ((OpenOffer) e).getState().equals(CANCELED)) + .map(e -> (OpenOffer) e) + .collect(Collectors.toList())); + } } public Optional getTradableById(String id) { - return closedTradables.stream().filter(e -> e.getId().equals(id)).findFirst(); + synchronized (closedTradables) { + return closedTradables.stream().filter(e -> e.getId().equals(id)).findFirst(); + } } public Optional getTradeById(String id) { - return closedTradables.stream().filter(e -> e instanceof Trade && e.getId().equals(id)).findFirst(); + synchronized (closedTradables) { + return closedTradables.stream().filter(e -> e instanceof Trade && e.getId().equals(id)).findFirst(); + } } public void maybeClearSensitiveData() { - log.info("checking closed trades eligibility for having sensitive data cleared"); - closedTradables.stream() + synchronized (closedTradables) { + log.info("checking closed trades eligibility for having sensitive data cleared"); + closedTradables.stream() .filter(e -> e instanceof Trade) .map(e -> (Trade) e) .filter(e -> canTradeHaveSensitiveDataCleared(e.getId())) .forEach(Trade::maybeClearSensitiveData); - requestPersistence(); + requestPersistence(); + } } public boolean canTradeHaveSensitiveDataCleared(String tradeId) { Instant safeDate = getSafeDateForSensitiveDataClearing(); - return closedTradables.stream() - .filter(e -> e.getId().equals(tradeId)) - .filter(e -> e.getDate().toInstant().isBefore(safeDate)) - .count() > 0; + synchronized (closedTradables) { + return closedTradables.stream() + .filter(e -> e.getId().equals(tradeId)) + .filter(e -> e.getDate().toInstant().isBefore(safeDate)) + .count() > 0; + } } public Instant getSafeDateForSensitiveDataClearing() { diff --git a/core/src/main/java/bisq/core/trade/failed/FailedTradesManager.java b/core/src/main/java/bisq/core/trade/failed/FailedTradesManager.java index 141016ee9f..971777ad89 100644 --- a/core/src/main/java/bisq/core/trade/failed/FailedTradesManager.java +++ b/core/src/main/java/bisq/core/trade/failed/FailedTradesManager.java @@ -88,14 +88,18 @@ public class FailedTradesManager implements PersistedDataHost { } public void add(Trade trade) { - if (failedTrades.add(trade)) { - requestPersistence(); + synchronized (failedTrades) { + if (failedTrades.add(trade)) { + requestPersistence(); + } } } public void removeTrade(Trade trade) { - if (failedTrades.remove(trade)) { - requestPersistence(); + synchronized (failedTrades) { + if (failedTrades.remove(trade)) { + requestPersistence(); + } } } @@ -104,26 +108,34 @@ public class FailedTradesManager implements PersistedDataHost { } public ObservableList getObservableList() { - return failedTrades.getObservableList(); + synchronized (failedTrades) { + return failedTrades.getObservableList(); + } } public Optional getTradeById(String id) { - return failedTrades.stream().filter(e -> e.getId().equals(id)).findFirst(); + synchronized (failedTrades) { + return failedTrades.stream().filter(e -> e.getId().equals(id)).findFirst(); + } } public Stream getTradesStreamWithFundsLockedIn() { - return failedTrades.stream() - .filter(Trade::isFundsLockedIn); + synchronized (failedTrades) { + return failedTrades.stream() + .filter(Trade::isFundsLockedIn); + } } public void unFailTrade(Trade trade) { - if (unFailTradeCallback == null) - return; + synchronized (failedTrades) { + if (unFailTradeCallback == null) + return; - if (unFailTradeCallback.apply(trade)) { - log.info("Unfailing trade {}", trade.getId()); - if (failedTrades.remove(trade)) { - requestPersistence(); + if (unFailTradeCallback.apply(trade)) { + log.info("Unfailing trade {}", trade.getId()); + if (failedTrades.remove(trade)) { + requestPersistence(); + } } } }