remove offers from books off user thread

This commit is contained in:
woodser 2024-01-25 10:01:44 -05:00
parent 41290a1f3f
commit 33bd4587c4

View file

@ -317,14 +317,20 @@ public class OpenOfferManager implements PeerManager.Listener, DecryptedDirectMe
int size = openOffers.size(); int size = openOffers.size();
log.info("Remove open offers at shutDown. Number of open offers: {}", size); log.info("Remove open offers at shutDown. Number of open offers: {}", size);
if (offerBookService.isBootstrapped() && size > 0) { if (offerBookService.isBootstrapped() && size > 0) {
ThreadUtils.execute(() -> { // finish tasks ThreadUtils.execute(() -> {
UserThread.execute(() -> {
openOffers.forEach(openOffer -> offerBookService.removeOfferAtShutDown(openOffer.getOffer().getOfferPayload())); // remove offers from offer book
synchronized (openOffers) {
openOffers.forEach(openOffer -> {
if (openOffer.getState() == OpenOffer.State.AVAILABLE) {
offerBookService.removeOfferAtShutDown(openOffer.getOffer().getOfferPayload());
}
});
}
// Force broadcaster to send out immediately, otherwise we could have a 2 sec delay until the // Force broadcaster to send out immediately, otherwise we could have a 2 sec delay until the
// bundled messages sent out. // bundled messages sent out.
broadcaster.flush(); broadcaster.flush();
shutDownThreadPool();
if (completeHandler != null) { if (completeHandler != null) {
// For typical number of offers we are tolerant with delay to give enough time to broadcast. // For typical number of offers we are tolerant with delay to give enough time to broadcast.
@ -332,14 +338,13 @@ public class OpenOfferManager implements PeerManager.Listener, DecryptedDirectMe
int delay = Math.min(3000, size * 200 + 500); int delay = Math.min(3000, size * 200 + 500);
UserThread.runAfter(completeHandler, delay, TimeUnit.MILLISECONDS); UserThread.runAfter(completeHandler, delay, TimeUnit.MILLISECONDS);
} }
});
}, THREAD_ID); }, THREAD_ID);
} else { } else {
broadcaster.flush(); broadcaster.flush();
shutDownThreadPool();
if (completeHandler != null) if (completeHandler != null)
completeHandler.run(); completeHandler.run();
} }
shutDownThreadPool();
} }
private void shutDownThreadPool() { private void shutDownThreadPool() {