rad 6.2.0
Loading...
Searching...
No Matches
Public Member Functions | List of all members
rad::cii::OldbAdapter Class Reference

#include <oldbAdapter.hpp>

Inheritance diagram for rad::cii::OldbAdapter:
OldbAdapterBad OldbAdapterDummy rad::utest::OldbAdapter

Public Member Functions

 OldbAdapter ()
 
 OldbAdapter (const std::chrono::seconds conn_timeout)
 
 OldbAdapter (const OldbAdapter &)=default
 
virtual ~OldbAdapter ()
 
OldbAdapteroperator= (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)
 

Detailed Description

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:

Constructor & Destructor Documentation

◆ OldbAdapter() [1/3]

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.

◆ OldbAdapter() [2/3]

rad::cii::OldbAdapter::OldbAdapter ( const std::chrono::seconds conn_timeout)
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).

Parameters
conn_timeoutTimeout in sec. to connect to the CII centralized config service.

◆ OldbAdapter() [3/3]

rad::cii::OldbAdapter::OldbAdapter ( const OldbAdapter & )
default

Copy constructor.

◆ ~OldbAdapter()

rad::cii::OldbAdapter::~OldbAdapter ( )
virtual

Destructor.

Reimplemented in rad::utest::OldbAdapter.

Member Function Documentation

◆ ClearDataPoints()

void rad::cii::OldbAdapter::ClearDataPoints ( )

Delete all data points from the cache.

◆ ConfigureConnTimeout()

void rad::cii::OldbAdapter::ConfigureConnTimeout ( const std::chrono::seconds conn_timeout)

Configure the connection timeout.

Parameters
conn_timeoutTimeout in sec. to connect to the CII centralized config service.

◆ Connect()

void rad::cii::OldbAdapter::Connect ( )
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.

◆ Del()

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.

Parameters
[in]keyURI of the attribute.

Delete an OLDB attribute.

◆ Get() [1/3]

template<typename T >
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.

Parameters
[in]keyURI of the attribute.
Returns
A snapshot of the triplet value/timestamp/quality associated to the key.
Exceptions
CiiOldbException(see CiiOldbDataPoint::ReadValue for subtypes).

◆ Get() [2/3]

template<typename T >
void rad::cii::OldbAdapter::Get ( const std::string & key,
std::vector< T > & value )

Read the vector of values associated to a given key.

Parameters
[in]keyURI of the attribute.
[out]valueIf the key is accessible, the vector of values associated to the key.

◆ Get() [3/3]

template<typename T >
void rad::cii::OldbAdapter::Get ( const std::string & key,
T & value )

Read the value associated to a given key.

Parameters
[in]keyURI of the attribute.
[out]valueIf the key is accessible, the value associated to the key.

◆ GetDataPoint()

std::shared_ptr< elt::oldb::CiiOldbTypedDataBase > rad::cii::OldbAdapter::GetDataPoint ( const std::string & key)
Parameters
keyURI of the attribute.
Returns
The CII Data Point associated to the given key.

◆ GetOldbInstance()

std::shared_ptr< elt::oldb::CiiOldb > rad::cii::OldbAdapter::GetOldbInstance ( )
Returns
The current CII OLDB instance or nullptr.

◆ GetVector()

template<typename T >
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.

Parameters
[in]keyURI of the attribute.
Returns
A snapshot of the triplet values/timestamp/quality associated to the key.
Exceptions
CiiOldbException(see CiiOldbDataPoint::ReadValue for subtypes).

◆ operator=()

OldbAdapter & rad::cii::OldbAdapter::operator= ( const OldbAdapter & )
default

Assignment operator.

◆ Set() [1/6]

template<typename T >
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.

Parameters
[in]keyURI of the attribute.
[in]valueThe vector of values associated to the key.

◆ Set() [2/6]

template<typename T >
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.

Parameters
[in]keyURI of the attribute.
[in]valuesThe value of the attribute.
[in,out]dpPointer to an existing data point or nullptr. In case of nullptr, the method will try to retrieve the data point.

◆ Set() [3/6]

template<typename T >
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.

Parameters
[in]keyURI of the attribute.
[in]valueThe value associated to the key.

◆ Set() [4/6]

template<typename T >
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.

Parameters
[in]keyURI of the attribute.
[in]valueThe value of the attribute.
[in,out]dpPointer to an existing data point or nullptr. In case of nullptr, the method will try to retrieve the data point.

◆ Set() [5/6]

template<typename T >
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.

Parameters
[in]keyURI of the attribute.
[in]valueThe shared vector of values associated to the key.

◆ Set() [6/6]

template<typename T >
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.

Parameters
[in]keyURI of the attribute.
[in]valueThe shared values of the attribute.
[in,out]dpPointer to an existing data point or nullptr. In case of nullptr, the method will try to retrieve the data point.

◆ SetOldbInstance()

void rad::cii::OldbAdapter::SetOldbInstance ( std::shared_ptr< elt::oldb::CiiOldb > oldb)

This method allows to set the handler to the OLDB instance.

Parameters
oldbOLDB instance to be used when reading/writing attributes.

◆ TryGet() [1/3]

template<typename T >
std::shared_ptr< elt::oldb::CiiOldbDpValue< T > > rad::cii::OldbAdapter::TryGet ( const std::string & key)
noexcept

Try to read value/timestamp/quality associated to a given key.

Parameters
[in]keyURI of the attribute.
Returns
A snapshot of the triplet value/timestamp/quality associated to the key, or nullptr in case of errors.

◆ TryGet() [2/3]

template<typename T >
bool rad::cii::OldbAdapter::TryGet ( const std::string & key,
std::vector< T > & value )
noexcept

Try to read the vector of values associated to a given key.

Parameters
[in]keyURI of the attribute.
[out]valueIf the key is accessible, the vector of values associated to the key.
Returns
true If the read was successful, false otherwise.

◆ TryGet() [3/3]

template<typename T >
bool rad::cii::OldbAdapter::TryGet ( const std::string & key,
T & value )
noexcept

Try to read the value associated to a given key.

Parameters
[in]keyURI of the attribute.
[out]valueIf the key is accessible, the value associated to the key.
Returns
true If the read was successful, false otherwise.

◆ TryGetVector()

template<typename T >
std::shared_ptr< elt::oldb::CiiOldbDpValue< std::vector< T > > > rad::cii::OldbAdapter::TryGetVector ( const std::string & key)
noexcept

Try to read values/timestamp/quality associated to a given key.

Parameters
[in]keyURI of the attribute.
Returns
A snapshot of the triplet values/timestamp/quality associated to the key, or nullptr in case of errors.

◆ TrySet() [1/3]

template<typename T >
bool rad::cii::OldbAdapter::TrySet ( const std::string & key,
const std::vector< T > & value,
const std::int64_t timestamp = elt::oldb::CiiOldbUtil::Now() )
noexcept

Try to write a vector of values for the given key.

Parameters
[in]keyURI of the attribute.
[in]valueThe vector of values associated to the key.
Returns
true If the write was successful, false otherwise.

◆ TrySet() [2/3]

template<typename T >
bool rad::cii::OldbAdapter::TrySet ( const std::string & key,
const T & value,
const std::int64_t timestamp = elt::oldb::CiiOldbUtil::Now() )
noexcept

Try to write a value for the given key.

Parameters
[in]keyURI of the attribute.
[in]valueThe value associated to the key.
Returns
true If the write was successful, false otherwise.

◆ TrySet() [3/3]

template<typename T >
bool rad::cii::OldbAdapter::TrySet ( const std::string & key,
elt::mal::shared_vector< const T > & value,
const std::int64_t timestamp = elt::oldb::CiiOldbUtil::Now() )
noexcept

Try to write a shared vector of values for the given key.

Parameters
[in]keyURI of the attribute.
[in]valueThe shared vector of values associated to the key.
Returns
true If the write was successful, false otherwise.

The documentation for this class was generated from the following files: