AlexaClientSDK  1.26.0
A cross-platform, modular SDK for interacting with the Alexa Voice Service
Public Types | Public Member Functions | Static Public Member Functions | Static Public Attributes | List of all members
alexaClientSDK::acsdkProperties::RetryExecutor Class Reference

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...
 

Detailed Description

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:

RetryExecutor executor(OperationType::Open, "namespaceUri");
auto action = execute("actionName", []() -> RetryableOperationResult {
.. do something
if (success) {
} else {
// Indicate the operation has failed, but the failure is retryable.
}
// now follow up on result
switch (action} {
when Action::SUCCESS:
// Handle success.
...
break;
// Handle failure.
...
break;
// Clear data and continue.
...
break;
See also
ErrorCallbackInterface
setErrorCallback()

Member Typedef Documentation

◆ 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()

Constructor & Destructor Documentation

◆ RetryExecutor()

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.

Parameters
[in]operationTypeOperation type.
[in]configUriConfiguration URI.

Member Function Documentation

◆ execute()

RetryableOperationResult alexaClientSDK::acsdkProperties::RetryExecutor::execute ( const std::string &  actionName,
const RetryableOperation operation,
Action  continueAction 
)
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.

Parameters
[in]actionNameOperation name for logging.
[in]operationOperation to execute. The operation must return status code, and flag, if the operation may be retried.
[in]continueActionDefault action to use if error callback returns Action::CONTINUE. This parameter must not be Action::CONTINUE.
Returns
Status code from the last attempted execution of operation.

Member Data Documentation

◆ NON_RETRYABLE_CRYPTO_ERROR

const StatusCodeWithRetry alexaClientSDK::acsdkProperties::RetryExecutor::NON_RETRYABLE_CRYPTO_ERROR {StatusCode::CRYPTO_ERROR, false}
static

Non-retryable cryptography error.

◆ NON_RETRYABLE_INNER_PROPERTIES_ERROR

const StatusCodeWithRetry alexaClientSDK::acsdkProperties::RetryExecutor::NON_RETRYABLE_INNER_PROPERTIES_ERROR
static
Initial value:

Non-retryable inner properties interface error.

◆ RETRYABLE_CRYPTO_ERROR

const StatusCodeWithRetry alexaClientSDK::acsdkProperties::RetryExecutor::RETRYABLE_CRYPTO_ERROR {StatusCode::CRYPTO_ERROR, true}
static

Retryable cryptography error.

◆ RETRYABLE_HSM_ERROR

const StatusCodeWithRetry alexaClientSDK::acsdkProperties::RetryExecutor::RETRYABLE_HSM_ERROR {StatusCode::HSM_ERROR, true}
static

Retryable HSM error.

◆ RETRYABLE_INNER_PROPERTIES_ERROR

const StatusCodeWithRetry alexaClientSDK::acsdkProperties::RetryExecutor::RETRYABLE_INNER_PROPERTIES_ERROR {StatusCode::INNER_PROPERTIES_ERROR, true}
static

Retryable inner properties interface error.

◆ SUCCESS

const StatusCodeWithRetry alexaClientSDK::acsdkProperties::RetryExecutor::SUCCESS {StatusCode::SUCCESS, false}
static

Success result.


The documentation for this class was generated from the following files:
alexaClientSDK::acsdkProperties::RetryExecutor::execute
RetryableOperationResult execute(const std::string &actionName, const RetryableOperation &operation, Action continueAction) noexcept
Execute retryable operation.
Definition: RetryExecutor.cpp:67
alexaClientSDK::acsdkProperties::RetryExecutor::RETRYABLE_INNER_PROPERTIES_ERROR
static const StatusCodeWithRetry RETRYABLE_INNER_PROPERTIES_ERROR
Retryable inner properties interface error.
Definition: RetryExecutor.h:135
alexaClientSDK::acsdkProperties::Action::FAIL
@ FAIL
Fail operation. Do not delete data.
alexaClientSDK::acsdkProperties::StatusCode::INNER_PROPERTIES_ERROR
@ INNER_PROPERTIES_ERROR
Underlying properties error.
alexaClientSDK::acsdkProperties::RetryableOperationResult
RetryableOperationResult
Operation result from a retryable operation.
Definition: RetryExecutor.h:47
alexaClientSDK::acsdkProperties::Action::CLEAR_DATA
@ CLEAR_DATA
Continue operation, delete data.
alexaClientSDK::acsdkProperties::RetryExecutor::RetryExecutor
RetryExecutor(OperationType operationType, const std::string &configUri)
Constructs helper object.
Definition: RetryExecutor.cpp:58
alexaClientSDK::acsdkProperties::RetryExecutor::SUCCESS
static const StatusCodeWithRetry SUCCESS
Success result.
Definition: RetryExecutor.h:127
alexaClientSDK::acsdkProperties::OperationType::Open
@ Open
Failed call to open properties container.

AlexaClientSDK 1.26.0 - Copyright 2016-2022 Amazon.com, Inc. or its affiliates. All Rights Reserved. Licensed under the Apache License, Version 2.0