Skip to content

Commit

Permalink
Add header "twin-fallback-after" for smart channel selection.
Browse files Browse the repository at this point in the history
Signed-off-by: Yufei Cai <yufei.cai@bosch.io>
  • Loading branch information
yufei-cai committed Nov 12, 2021
1 parent 7e10176 commit 4058e35
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -339,6 +339,13 @@ public Optional<Duration> getTimeout() {
.map(DittoDuration::getDuration);
}

@Override
public Optional<Duration> getTwinFallbackAfter() {
return getStringForDefinition(DittoHeaderDefinition.TWIN_FALLBACK_AFTER)
.map(DittoDuration::parseDuration)
.map(DittoDuration::getDuration);
}

@Override
public MetadataHeaders getMetadataHeadersToPut() {
final String metadataHeaderValue = getOrDefault(DittoHeaderDefinition.PUT_METADATA.getKey(), "");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,18 @@ public enum DittoHeaderDefinition implements HeaderDefinition {
TIMEOUT("timeout", DittoDuration.class, String.class, true, true,
HeaderValueValidators.getTimeoutValueValidator()),

/**
* Header definition for when a thing query command with smart channel selection should wait for a live response
* before falling back to the twin response.
* <p>
* Key: {@code "twin-fallback-after"}, Java type: {@code String}.
* </p>
*
* @since 2.2.0
*/
TWIN_FALLBACK_AFTER("twin-fallback-after", DittoDuration.class, String.class, true, false,
HeaderValueValidators.getTimeoutValueValidator()),

/**
* Header definition for the entity ID related to the command/event/response/error.
* <p>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,15 @@ static DittoHeadersBuilder newBuilder(final JsonObject jsonObject) {
*/
Optional<Duration> getTimeout();

/**
* Returns when a thing query command with smart channel selection should wait for a live response
* before falling back to the twin response.
*
* @return Time allocated to the live response in a thing query command with smart channel selection.
* @since 2.2.0
*/
Optional<Duration> getTwinFallbackAfter();

/**
* Returns the metadata headers to put/set for the (modifying) command they were added to.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,7 @@ public void settingAllKnownHeadersWorksAsExpected() {
.acknowledgementRequests(KNOWN_ACK_REQUESTS)
.putMetadata(KNOWN_METADATA_HEADER_KEY, KNOWN_METADATA_VALUE)
.timeout(KNOWN_TIMEOUT)
.putHeader(DittoHeaderDefinition.TWIN_FALLBACK_AFTER.getKey(), KNOWN_TIMEOUT.toMillis() + "ms")
.putHeader(DittoHeaderDefinition.CONNECTION_ID.getKey(), KNOWN_CONNECTION_ID)
.expectedResponseTypes(KNOWN_EXPECTED_RESPONSE_TYPES)
.allowPolicyLockout(KNOWN_ALLOW_POLICY_LOCKOUT)
Expand Down Expand Up @@ -416,6 +417,7 @@ public void toJsonReturnsExpected() {
.set(DittoHeaderDefinition.REQUESTED_ACKS.getKey(), ackRequestsToJsonArray(KNOWN_ACK_REQUESTS))
.set(DittoHeaderDefinition.DECLARED_ACKS.getKey(), charSequencesToJsonArray(KNOWN_ACK_LABELS))
.set(DittoHeaderDefinition.TIMEOUT.getKey(), JsonValue.of(KNOWN_TIMEOUT.toMillis() + "ms"))
.set(DittoHeaderDefinition.TWIN_FALLBACK_AFTER.getKey(), JsonValue.of(KNOWN_TIMEOUT.toMillis() + "ms"))
.set(DittoHeaderDefinition.ENTITY_ID.getKey(), KNOWN_ENTITY_ID)
.set(DittoHeaderDefinition.REPLY_TO.getKey(), KNOWN_REPLY_TO)
.set(DittoHeaderDefinition.WWW_AUTHENTICATE.getKey(), KNOWN_WWW_AUTHENTICATION)
Expand Down Expand Up @@ -646,6 +648,7 @@ private static Map<String, String> createMapContainingAllKnownHeaders() {
result.put(DittoHeaderDefinition.DECLARED_ACKS.getKey(),
charSequencesToJsonArray(KNOWN_ACK_LABELS).toString());
result.put(DittoHeaderDefinition.TIMEOUT.getKey(), KNOWN_TIMEOUT.toMillis() + "ms");
result.put(DittoHeaderDefinition.TWIN_FALLBACK_AFTER.getKey(), KNOWN_TIMEOUT.toMillis() + "ms");
result.put(DittoHeaderDefinition.ENTITY_ID.getKey(), KNOWN_ENTITY_ID);
result.put(DittoHeaderDefinition.REPLY_TO.getKey(), KNOWN_REPLY_TO);
result.put(DittoHeaderDefinition.WWW_AUTHENTICATE.getKey(), KNOWN_WWW_AUTHENTICATION);
Expand Down

0 comments on commit 4058e35

Please sign in to comment.