Trigger persistence at onAllServicesInitialized in case

we got a requestPersistence called before initialized
This commit is contained in:
chimp1984 2021-03-06 10:59:55 -05:00
parent a055a8bd36
commit 6fac9b17f1
No known key found for this signature in database
GPG key ID: 9801B4EC591F90E3

View file

@ -86,6 +86,14 @@ public class PersistenceManager<T extends PersistableEnvelope> {
public static void onAllServicesInitialized() { public static void onAllServicesInitialized() {
allServicesInitialized.set(true); allServicesInitialized.set(true);
ALL_PERSISTENCE_MANAGERS.values().forEach(persistenceManager -> {
// In case we got a requestPersistence call before we got initialized we trigger the timer for the
// persist call
if (persistenceManager.persistenceRequested) {
persistenceManager.maybeStartTimerForPersistence();
}
});
} }
// We require being called only once from the global shutdown routine. As the shutdown routine has a timeout // We require being called only once from the global shutdown routine. As the shutdown routine has a timeout
@ -363,6 +371,16 @@ public class PersistenceManager<T extends PersistableEnvelope> {
persistenceRequested = true; persistenceRequested = true;
// If we have not initialized yet we postpone the start of the timer and call maybeStartTimerForPersistence at
// onAllServicesInitialized
if (!allServicesInitialized.get()) {
return;
}
maybeStartTimerForPersistence();
}
private void maybeStartTimerForPersistence() {
// We write to disk with a delay to avoid frequent write operations. Depending on the priority those delays // We write to disk with a delay to avoid frequent write operations. Depending on the priority those delays
// can be rather long. // can be rather long.
if (timer == null) { if (timer == null) {