From 4f2da750a4aeee3333cb27213e6e3627b5503659 Mon Sep 17 00:00:00 2001 From: Siddhant Srivastava Date: Fri, 6 Sep 2024 10:28:23 -0700 Subject: [PATCH] chore: override state transitions into topic --- src/main/java/com/aws/greengrass/config/Topic.java | 12 ++++++++++++ .../aws/greengrass/lifecyclemanager/Lifecycle.java | 6 +++--- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/aws/greengrass/config/Topic.java b/src/main/java/com/aws/greengrass/config/Topic.java index 45b6066323..4dc72f3a71 100644 --- a/src/main/java/com/aws/greengrass/config/Topic.java +++ b/src/main/java/com/aws/greengrass/config/Topic.java @@ -128,6 +128,10 @@ private Topic overrideValue(Object nv) { return withNewerValue(this.modtime, nv); } + private Topic overrideValue(Object nv, long proposedModTime) { + return withNewerValue(proposedModTime, nv); + } + /** * Update the value in place without changing the timestamp. * @param nv new value @@ -141,6 +145,14 @@ public Topic overrideValue(Number nv) { return overrideValue((Object) nv); } + public Topic overrideValueWithCurrentTimestamp(String nv) { + return overrideValue(nv, System.currentTimeMillis()); + } + + public Topic overrideValueWithCurrentTimestamp(Number nv) { + return overrideValue(nv, System.currentTimeMillis()); + } + private Topic withValue(Object nv) { return withNewerValue(System.currentTimeMillis(), nv); } diff --git a/src/main/java/com/aws/greengrass/lifecyclemanager/Lifecycle.java b/src/main/java/com/aws/greengrass/lifecyclemanager/Lifecycle.java index d23d70190c..d2f7186ea3 100644 --- a/src/main/java/com/aws/greengrass/lifecyclemanager/Lifecycle.java +++ b/src/main/java/com/aws/greengrass/lifecyclemanager/Lifecycle.java @@ -441,9 +441,9 @@ void setState(State current, StateTransitionEvent stateTransitionEvent) { // Sync on State.class to make sure the order of setValue and globalNotifyStateChanged // are consistent across different services. try (LockScope ls = LockScope.lock(globalLock)) { - stateTopic.withValue(newState.ordinal()); - statusCodeTopic.withValue(stateTransitionEvent.getStatusCode().name()); - statusReasonTopic.withValue(stateTransitionEvent.getStatusReason()); + stateTopic.overrideValueWithCurrentTimestamp(newState.ordinal()); + statusCodeTopic.overrideValueWithCurrentTimestamp(stateTransitionEvent.getStatusCode().name()); + statusReasonTopic.overrideValueWithCurrentTimestamp(stateTransitionEvent.getStatusReason()); greengrassService.getContext().globalNotifyStateChanged(greengrassService, current, newState); } }