rad 6.2.0
|
#include <oldbAdapter.hpp>
Public Member Functions | |
OldbAdapter () | |
OldbAdapter (const std::chrono::seconds conn_timeout) | |
OldbAdapter (const OldbAdapter &)=default | |
virtual | ~OldbAdapter () |
OldbAdapter & | operator= (const OldbAdapter &)=default |
std::shared_ptr< elt::oldb::CiiOldb > | GetOldbInstance () |
void | SetOldbInstance (std::shared_ptr< elt::oldb::CiiOldb > oldb) |
void | ConfigureConnTimeout (const std::chrono::seconds conn_timeout) |
virtual void | Connect () |
void | ClearDataPoints () |
std::shared_ptr< elt::oldb::CiiOldbTypedDataBase > | GetDataPoint (const std::string &key) |
template<typename T > | |
void | Get (const std::string &key, T &value) |
template<typename T > | |
std::shared_ptr< elt::oldb::CiiOldbDpValue< T > > | Get (const std::string &key) |
template<typename T > | |
bool | TryGet (const std::string &key, T &value) noexcept |
template<typename T > | |
std::shared_ptr< elt::oldb::CiiOldbDpValue< T > > | TryGet (const std::string &key) noexcept |
template<typename T > | |
void | Get (const std::string &key, std::vector< T > &value) |
template<typename T > | |
std::shared_ptr< elt::oldb::CiiOldbDpValue< std::vector< T > > > | GetVector (const std::string &key) |
template<typename T > | |
bool | TryGet (const std::string &key, std::vector< T > &value) noexcept |
template<typename T > | |
std::shared_ptr< elt::oldb::CiiOldbDpValue< std::vector< T > > > | TryGetVector (const std::string &key) noexcept |
template<typename T > | |
void | Set (const std::string &key, const T &value, const std::int64_t timestamp=elt::oldb::CiiOldbUtil::Now()) |
template<typename T > | |
bool | TrySet (const std::string &key, const T &value, const std::int64_t timestamp=elt::oldb::CiiOldbUtil::Now()) noexcept |
template<typename T > | |
void | Set (const std::string &key, const std::vector< T > &value, const std::int64_t timestamp=elt::oldb::CiiOldbUtil::Now()) |
template<typename T > | |
bool | TrySet (const std::string &key, const std::vector< T > &value, const std::int64_t timestamp=elt::oldb::CiiOldbUtil::Now()) noexcept |
template<typename T > | |
void | Set (const std::string &key, elt::mal::shared_vector< const T > &value, const std::int64_t timestamp=elt::oldb::CiiOldbUtil::Now()) |
template<typename T > | |
bool | TrySet (const std::string &key, elt::mal::shared_vector< const T > &value, const std::int64_t timestamp=elt::oldb::CiiOldbUtil::Now()) noexcept |
template<typename T > | |
void | Set (const std::string &key, const T &value, std::shared_ptr< elt::oldb::CiiOldbDataPoint< T > > &dp, const std::int64_t timestamp=elt::oldb::CiiOldbUtil::Now()) |
template<typename T > | |
void | Set (const std::string &key, const std::vector< T > &values, std::shared_ptr< elt::oldb::CiiOldbDataPoint< std::vector< T > > > &dp, const std::int64_t timestamp=elt::oldb::CiiOldbUtil::Now()) |
template<typename T > | |
void | Set (const std::string &key, elt::mal::shared_vector< const T > &values, std::shared_ptr< elt::oldb::CiiOldbDataPoint< std::vector< T > > > &dp, const std::int64_t timestamp=elt::oldb::CiiOldbUtil::Now()) |
void | Del (const std::string &key) |
This class allows to synchronously read from and write to the CII OLDB.
The goal is to be able to read/write attributes when the CII OLDB service is running and be "transparent" (i.e. supress errors) in case the service is not available (e.g. not started/or temporary down).
This is done by adding to the Get/Set methods the capability of:
rad::cii::OldbAdapter::OldbAdapter | ( | ) |
Default constructor.
Use the file based (or default) configuration to connect to the centralized config service to get the OLDB metadata info.
|
explicit |
Constructor that allows to configure the connection timeout. Note that the timeout is used to connect to the CII centralized configuration service to get the OLDB metadata info (it is not the timeout to connect to Redis).
conn_timeout | Timeout in sec. to connect to the CII centralized config service. |
|
default |
Copy constructor.
|
virtual |
Destructor.
Reimplemented in rad::utest::OldbAdapter.
void rad::cii::OldbAdapter::ClearDataPoints | ( | ) |
Delete all data points from the cache.
void rad::cii::OldbAdapter::ConfigureConnTimeout | ( | const std::chrono::seconds | conn_timeout | ) |
Configure the connection timeout.
conn_timeout | Timeout in sec. to connect to the CII centralized config service. |
|
virtual |
Obtains an OLDB instance.
This method is virtual to allow for creating, for example, dummy adapters that do not really connect (as may be needed in Unit Tests).
Note that with template methods it is not easy to create interface classes.
Reimplemented in OldbAdapterDummy, OldbAdapterBad, and rad::utest::OldbAdapter.
void rad::cii::OldbAdapter::Del | ( | const std::string & | key | ) |
Delete an attribute.
If the OLDB instance is nullptr, it tries to get one via the Connect method.
[in] | key | URI of the attribute. |
Delete an OLDB attribute.
std::shared_ptr< elt::oldb::CiiOldbDpValue< T > > rad::cii::OldbAdapter::Get | ( | const std::string & | key | ) |
Read value/timestamp/quality associated to a given key.
Note that it would be nice to pass another parameter, bool check_bad_quality=true, as it is done for the underlying CII method. But this would conflict with the above template instantiation for T=bool. If the older getter methods that only return the value ever get removed, we could discuss adding check_bad_quality to all remaining getter methods.
[in] | key | URI of the attribute. |
CiiOldbException | (see CiiOldbDataPoint::ReadValue for subtypes). |
void rad::cii::OldbAdapter::Get | ( | const std::string & | key, |
std::vector< T > & | value ) |
Read the vector of values associated to a given key.
[in] | key | URI of the attribute. |
[out] | value | If the key is accessible, the vector of values associated to the key. |
void rad::cii::OldbAdapter::Get | ( | const std::string & | key, |
T & | value ) |
Read the value associated to a given key.
[in] | key | URI of the attribute. |
[out] | value | If the key is accessible, the value associated to the key. |
std::shared_ptr< elt::oldb::CiiOldbTypedDataBase > rad::cii::OldbAdapter::GetDataPoint | ( | const std::string & | key | ) |
key | URI of the attribute. |
std::shared_ptr< elt::oldb::CiiOldb > rad::cii::OldbAdapter::GetOldbInstance | ( | ) |
std::shared_ptr< elt::oldb::CiiOldbDpValue< std::vector< T > > > rad::cii::OldbAdapter::GetVector | ( | const std::string & | key | ) |
Read values/timestamp/quality associated to a given key.
[in] | key | URI of the attribute. |
CiiOldbException | (see CiiOldbDataPoint::ReadValue for subtypes). |
|
default |
Assignment operator.
void rad::cii::OldbAdapter::Set | ( | const std::string & | key, |
const std::vector< T > & | value, | ||
const std::int64_t | timestamp = elt::oldb::CiiOldbUtil::Now() ) |
Write a vector of values for the given key.
[in] | key | URI of the attribute. |
[in] | value | The vector of values associated to the key. |
void rad::cii::OldbAdapter::Set | ( | const std::string & | key, |
const std::vector< T > & | values, | ||
std::shared_ptr< elt::oldb::CiiOldbDataPoint< std::vector< T > > > & | dp, | ||
const std::int64_t | timestamp = elt::oldb::CiiOldbUtil::Now() ) |
Writes a vector of values to an existing attribute or, if the attribute does not exists, creates one by value.
If the OLDB instance is nullptr, it tries to get one via the Connect method.
[in] | key | URI of the attribute. |
[in] | values | The value of the attribute. |
[in,out] | dp | Pointer to an existing data point or nullptr. In case of nullptr, the method will try to retrieve the data point. |
void rad::cii::OldbAdapter::Set | ( | const std::string & | key, |
const T & | value, | ||
const std::int64_t | timestamp = elt::oldb::CiiOldbUtil::Now() ) |
Write a value for the given key.
[in] | key | URI of the attribute. |
[in] | value | The value associated to the key. |
void rad::cii::OldbAdapter::Set | ( | const std::string & | key, |
const T & | value, | ||
std::shared_ptr< elt::oldb::CiiOldbDataPoint< T > > & | dp, | ||
const std::int64_t | timestamp = elt::oldb::CiiOldbUtil::Now() ) |
Writes a value to an existing attribute or, if the attribute does not exists, creates one by value.
If the OLDB instance is nullptr, it tries to get one via the Connect method.
[in] | key | URI of the attribute. |
[in] | value | The value of the attribute. |
[in,out] | dp | Pointer to an existing data point or nullptr. In case of nullptr, the method will try to retrieve the data point. |
void rad::cii::OldbAdapter::Set | ( | const std::string & | key, |
elt::mal::shared_vector< const T > & | value, | ||
const std::int64_t | timestamp = elt::oldb::CiiOldbUtil::Now() ) |
Write a shared vector of values for the given key.
[in] | key | URI of the attribute. |
[in] | value | The shared vector of values associated to the key. |
void rad::cii::OldbAdapter::Set | ( | const std::string & | key, |
elt::mal::shared_vector< const T > & | values, | ||
std::shared_ptr< elt::oldb::CiiOldbDataPoint< std::vector< T > > > & | dp, | ||
const std::int64_t | timestamp = elt::oldb::CiiOldbUtil::Now() ) |
Writes a shared vector of values to an existing attribute or, if the attribute does not exists, creates one by value.
If the OLDB instance is nullptr, it tries to get one via the Connect method.
[in] | key | URI of the attribute. |
[in] | value | The shared values of the attribute. |
[in,out] | dp | Pointer to an existing data point or nullptr. In case of nullptr, the method will try to retrieve the data point. |
void rad::cii::OldbAdapter::SetOldbInstance | ( | std::shared_ptr< elt::oldb::CiiOldb > | oldb | ) |
This method allows to set the handler to the OLDB instance.
oldb | OLDB instance to be used when reading/writing attributes. |
|
noexcept |
Try to read value/timestamp/quality associated to a given key.
[in] | key | URI of the attribute. |
|
noexcept |
Try to read the vector of values associated to a given key.
[in] | key | URI of the attribute. |
[out] | value | If the key is accessible, the vector of values associated to the key. |
|
noexcept |
Try to read the value associated to a given key.
[in] | key | URI of the attribute. |
[out] | value | If the key is accessible, the value associated to the key. |
|
noexcept |
Try to read values/timestamp/quality associated to a given key.
[in] | key | URI of the attribute. |
|
noexcept |
Try to write a vector of values for the given key.
[in] | key | URI of the attribute. |
[in] | value | The vector of values associated to the key. |
|
noexcept |
Try to write a value for the given key.
[in] | key | URI of the attribute. |
[in] | value | The value associated to the key. |
|
noexcept |
Try to write a shared vector of values for the given key.
[in] | key | URI of the attribute. |
[in] | value | The shared vector of values associated to the key. |