Skip to content

Commit

Permalink
chore: override state transitions into topic
Browse files Browse the repository at this point in the history
  • Loading branch information
alter-mage committed Sep 6, 2024
1 parent 991fa35 commit 4f2da75
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
12 changes: 12 additions & 0 deletions src/main/java/com/aws/greengrass/config/Topic.java
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Expand Down

0 comments on commit 4f2da75

Please sign in to comment.