Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: override state transitions into topic #1659

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This doesn't make sense, it won't do anything different from with newer value.
The point of overriding is that the value provided here is going to be set no matter what the timestamp is on the node. This implementation won't do that, this is a straight up alias for with newer value.

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
Loading