AlexaClientSDK
1.26.0
A cross-platform, modular SDK for interacting with the Alexa Voice Service
|
Helper class to execute with retries. More...
#include <RetryExecutor.h>
Public Types | |
typedef std::function< StatusCodeWithRetry()> | RetryableOperation |
Retryable operation. More... | |
Public Member Functions | |
RetryExecutor (OperationType operationType, const std::string &configUri) | |
Constructs helper object. More... | |
RetryableOperationResult | execute (const std::string &actionName, const RetryableOperation &operation, Action continueAction) noexcept |
Execute retryable operation. More... | |
Static Public Member Functions | |
static bool | setErrorCallback (const std::weak_ptr< ErrorCallbackInterface > &callback, uint32_t maxRetries, std::weak_ptr< ErrorCallbackInterface > *previous=nullptr) noexcept |
Sets an error callback. More... | |
Static Public Attributes | |
static const StatusCodeWithRetry | SUCCESS {StatusCode::SUCCESS, false} |
Success result. More... | |
static const StatusCodeWithRetry | RETRYABLE_CRYPTO_ERROR {StatusCode::CRYPTO_ERROR, true} |
Retryable cryptography error. More... | |
static const StatusCodeWithRetry | NON_RETRYABLE_CRYPTO_ERROR {StatusCode::CRYPTO_ERROR, false} |
Non-retryable cryptography error. More... | |
static const StatusCodeWithRetry | RETRYABLE_HSM_ERROR {StatusCode::HSM_ERROR, true} |
Retryable HSM error. More... | |
static const StatusCodeWithRetry | RETRYABLE_INNER_PROPERTIES_ERROR {StatusCode::INNER_PROPERTIES_ERROR, true} |
Retryable inner properties interface error. More... | |
static const StatusCodeWithRetry | NON_RETRYABLE_INNER_PROPERTIES_ERROR |
Non-retryable inner properties interface error. More... | |
Helper class to execute with retries.
This class handles operation errors and retries. Whenever operation fails, an error callback is notified, and then decision is made to retry operation, fail it, or mark operation for cleanup action.
Executor isn't aware of operation specifics, but it gets OperationType and namespace URI when constructed, executes given operation, and works with RetryableOperationResult. For improved debugging, the classes.
This class also provides functions to set (change) error callback interface to use whenever an operation encounters an error. The number of retries can be limited, and when the retry limit is reached, the class marks operation as failed even if error callback requests a retry.
The class uses the same retry counter for all invocations, so if any of the operations fail, this reduces total number of retry attempts.
The class shall be used as follows:
typedef std::function<StatusCodeWithRetry()> alexaClientSDK::acsdkProperties::RetryExecutor::RetryableOperation |
Retryable operation.
RetryExecutor invokes retryable operation and checks the result. If the result is success, it is propagated to the caller, otherwise error callback is invoked, and operation may be retried.
sa execute()
alexaClientSDK::acsdkProperties::RetryExecutor::RetryExecutor | ( | OperationType | operationType, |
const std::string & | configUri | ||
) |
Constructs helper object.
This method atomically captures configured callback interface and maximum retry count, so that all retries will user the same callback interface and retry limit parameters.
[in] | operationType | Operation type. |
[in] | configUri | Configuration URI. |
|
noexcept |
Execute retryable operation.
This method executes operation until it returns OperationResult::Success, OperationResult::Failure, or there are no more retry attempts left.
If operation execution fails with error, an error callback is called. If callback returns Action::CONTINUE, then value of continueAction is used. If operation result was retryable, and desired action is Action::RETRY, executor retries operation unless there were too many execution attempts.
This method doesn't rest retry counter, so when this method is called for the same instance, the number of retries left decreases.
[in] | actionName | Operation name for logging. |
[in] | operation | Operation to execute. The operation must return status code, and flag, if the operation may be retried. |
[in] | continueAction | Default action to use if error callback returns Action::CONTINUE. This parameter must not be Action::CONTINUE. |
|
static |
Non-retryable cryptography error.
|
static |
Non-retryable inner properties interface error.
|
static |
Retryable cryptography error.
|
static |
Retryable HSM error.
|
static |
Retryable inner properties interface error.
|
static |
Success result.
AlexaClientSDK 1.26.0 - Copyright 2016-2022 Amazon.com, Inc. or its affiliates. All Rights Reserved. Licensed under the Apache License, Version 2.0