From 84b1d571254057ad732bb23b1b8d3f4f97cb8ac5 Mon Sep 17 00:00:00 2001 From: Stepan Usatiuk Date: Wed, 14 May 2025 11:27:39 +0200 Subject: [PATCH] Sync-base: skip scheduled execution when app is not running --- .../DeferredInvalidationQueueService.java | 2 +- .../peerdiscovery/PersistentStaticPeerDiscovery.java | 2 +- .../dhfs/peerdiscovery/StaticPeerDiscovery.java | 2 +- .../local/LocalPeerDiscoveryBroadcaster.java | 2 +- .../usatiuk/dhfs/peersync/PeerLastSeenUpdater.java | 2 +- .../usatiuk/dhfs/peersync/ReachablePeerManager.java | 12 +++++++++++- 6 files changed, 16 insertions(+), 6 deletions(-) diff --git a/dhfs-parent/sync-base/src/main/java/com/usatiuk/dhfs/invalidation/DeferredInvalidationQueueService.java b/dhfs-parent/sync-base/src/main/java/com/usatiuk/dhfs/invalidation/DeferredInvalidationQueueService.java index f5447407..aaa7e674 100644 --- a/dhfs-parent/sync-base/src/main/java/com/usatiuk/dhfs/invalidation/DeferredInvalidationQueueService.java +++ b/dhfs-parent/sync-base/src/main/java/com/usatiuk/dhfs/invalidation/DeferredInvalidationQueueService.java @@ -67,7 +67,7 @@ public class DeferredInvalidationQueueService implements PeerConnectedEventListe /** * Periodically returns deferred invalidations to the invalidation queue for all reachable hosts. */ - @Scheduled(every = "15s", concurrentExecution = Scheduled.ConcurrentExecution.SKIP) + @Scheduled(every = "15s", concurrentExecution = Scheduled.ConcurrentExecution.SKIP, skipExecutionIf = Scheduled.ApplicationNotRunning.class) @Blocking void periodicReturn() { for (var reachable : reachablePeerManager.getAvailableHosts()) diff --git a/dhfs-parent/sync-base/src/main/java/com/usatiuk/dhfs/peerdiscovery/PersistentStaticPeerDiscovery.java b/dhfs-parent/sync-base/src/main/java/com/usatiuk/dhfs/peerdiscovery/PersistentStaticPeerDiscovery.java index 52abccf9..f7e4074d 100644 --- a/dhfs-parent/sync-base/src/main/java/com/usatiuk/dhfs/peerdiscovery/PersistentStaticPeerDiscovery.java +++ b/dhfs-parent/sync-base/src/main/java/com/usatiuk/dhfs/peerdiscovery/PersistentStaticPeerDiscovery.java @@ -15,7 +15,7 @@ public class PersistentStaticPeerDiscovery { @Inject PersistentPeerDataService persistentPeerDataService; - @Scheduled(every = "1s", concurrentExecution = Scheduled.ConcurrentExecution.SKIP) + @Scheduled(every = "1s", concurrentExecution = Scheduled.ConcurrentExecution.SKIP, skipExecutionIf = Scheduled.ApplicationNotRunning.class) public void discoverPeers() { var addrs = persistentPeerDataService.getPersistentPeerAddresses(); for (var addr : addrs) { diff --git a/dhfs-parent/sync-base/src/main/java/com/usatiuk/dhfs/peerdiscovery/StaticPeerDiscovery.java b/dhfs-parent/sync-base/src/main/java/com/usatiuk/dhfs/peerdiscovery/StaticPeerDiscovery.java index 9694b33e..49bf76a0 100644 --- a/dhfs-parent/sync-base/src/main/java/com/usatiuk/dhfs/peerdiscovery/StaticPeerDiscovery.java +++ b/dhfs-parent/sync-base/src/main/java/com/usatiuk/dhfs/peerdiscovery/StaticPeerDiscovery.java @@ -25,7 +25,7 @@ public class StaticPeerDiscovery { ).toList(); } - @Scheduled(every = "1s", concurrentExecution = Scheduled.ConcurrentExecution.SKIP) + @Scheduled(every = "1s", concurrentExecution = Scheduled.ConcurrentExecution.SKIP, skipExecutionIf = Scheduled.ApplicationNotRunning.class) public void discoverPeers() { for (var peer : _peers) { peerDiscoveryDirectory.notifyAddr(peer); diff --git a/dhfs-parent/sync-base/src/main/java/com/usatiuk/dhfs/peerdiscovery/local/LocalPeerDiscoveryBroadcaster.java b/dhfs-parent/sync-base/src/main/java/com/usatiuk/dhfs/peerdiscovery/local/LocalPeerDiscoveryBroadcaster.java index a156f056..683b7582 100644 --- a/dhfs-parent/sync-base/src/main/java/com/usatiuk/dhfs/peerdiscovery/local/LocalPeerDiscoveryBroadcaster.java +++ b/dhfs-parent/sync-base/src/main/java/com/usatiuk/dhfs/peerdiscovery/local/LocalPeerDiscoveryBroadcaster.java @@ -54,7 +54,7 @@ public class LocalPeerDiscoveryBroadcaster { _socket.close(); } - @Scheduled(every = "${dhfs.objects.peerdiscovery.interval}", concurrentExecution = Scheduled.ConcurrentExecution.SKIP) + @Scheduled(every = "${dhfs.objects.peerdiscovery.interval}", concurrentExecution = Scheduled.ConcurrentExecution.SKIP, skipExecutionIf = Scheduled.ApplicationNotRunning.class) public void broadcast() throws Exception { if (!enabled) { return; diff --git a/dhfs-parent/sync-base/src/main/java/com/usatiuk/dhfs/peersync/PeerLastSeenUpdater.java b/dhfs-parent/sync-base/src/main/java/com/usatiuk/dhfs/peersync/PeerLastSeenUpdater.java index 35ab5c24..ce7fa424 100644 --- a/dhfs-parent/sync-base/src/main/java/com/usatiuk/dhfs/peersync/PeerLastSeenUpdater.java +++ b/dhfs-parent/sync-base/src/main/java/com/usatiuk/dhfs/peersync/PeerLastSeenUpdater.java @@ -30,7 +30,7 @@ public class PeerLastSeenUpdater { @Inject PersistentPeerDataService persistentPeerDataService; - @Scheduled(every = "${dhfs.objects.last-seen.update}", concurrentExecution = Scheduled.ConcurrentExecution.SKIP) + @Scheduled(every = "${dhfs.objects.last-seen.update}", concurrentExecution = Scheduled.ConcurrentExecution.SKIP, skipExecutionIf = Scheduled.ApplicationNotRunning.class) @Blocking void update() { var snapshot = reachablePeerManager.getHostStateSnapshot(); diff --git a/dhfs-parent/sync-base/src/main/java/com/usatiuk/dhfs/peersync/ReachablePeerManager.java b/dhfs-parent/sync-base/src/main/java/com/usatiuk/dhfs/peersync/ReachablePeerManager.java index 7ef95d39..d63f0333 100644 --- a/dhfs-parent/sync-base/src/main/java/com/usatiuk/dhfs/peersync/ReachablePeerManager.java +++ b/dhfs-parent/sync-base/src/main/java/com/usatiuk/dhfs/peersync/ReachablePeerManager.java @@ -71,7 +71,7 @@ public class ReachablePeerManager { _heartbeatExecutor = Executors.newVirtualThreadPerTaskExecutor(); } - @Scheduled(every = "${dhfs.objects.reconnect_interval}", concurrentExecution = Scheduled.ConcurrentExecution.SKIP) + @Scheduled(every = "${dhfs.objects.reconnect_interval}", concurrentExecution = Scheduled.ConcurrentExecution.SKIP, skipExecutionIf = Scheduled.ApplicationNotRunning.class) @Blocking public void tryConnectAll() { if (_heartbeatExecutor == null) return; @@ -158,6 +158,7 @@ public class ReachablePeerManager { /** * Checks if the given host is reachable. + * * @param host the host to check * @return true if the host is reachable, false otherwise */ @@ -167,6 +168,7 @@ public class ReachablePeerManager { /** * Checks if the given host is reachable. + * * @param host the host to check * @return true if the host is reachable, false otherwise */ @@ -176,6 +178,7 @@ public class ReachablePeerManager { /** * Gets the address of the given host. + * * @param host the host to get the address for * @return the address of the host, or null if not reachable */ @@ -185,6 +188,7 @@ public class ReachablePeerManager { /** * Gets the ids of all reachable hosts. + * * @return a list of ids of all reachable hosts */ public List getAvailableHosts() { @@ -193,6 +197,7 @@ public class ReachablePeerManager { /** * Gets a snapshot of current state of the connected (and not connected) peers + * * @return information about all connected/disconnected peers */ public HostStateSnapshot getHostStateSnapshot() { @@ -205,6 +210,7 @@ public class ReachablePeerManager { /** * Removes the given host from the cluster + * * @param peerId the id of the host to remove */ public void removeRemoteHost(PeerId peerId) { @@ -216,6 +222,7 @@ public class ReachablePeerManager { /** * Selects the best address for the given host. * The address is selected based on the type of the address. (with e.g. LAN address preferred over WAN) + * * @param host the host to select the address for * @return the best address for the host, or null if not reachable */ @@ -225,6 +232,7 @@ public class ReachablePeerManager { /** * Call the given peer and get its information. + * * @param host the peer to get the information for * @return the information about the peer */ @@ -243,6 +251,7 @@ public class ReachablePeerManager { /** * Adds the given peer to the cluster. * The certificate provided is verified against the one peer is using right now. + * * @param host the peer to add * @param cert the certificate of the peer */ @@ -264,6 +273,7 @@ public class ReachablePeerManager { /** * Gets the information about all reachable peers that are not added to the cluster. + * * @return a collection of pairs of peer id and peer info */ public Collection> getSeenButNotAddedHosts() {