rad  4.0.0
Public Member Functions | List of all members
rad::cii::OldbAdapter Class Reference

#include <oldbAdapter.hpp>

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

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 >
bool TryGet (const std::string &key, T &value) noexcept
 
template<typename T >
void Get (const std::string &key, std::vector< T > &value)
 
template<typename T >
bool TryGet (const std::string &key, std::vector< T > &value) 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 Get (const std::string &key, T &value, std::shared_ptr< elt::oldb::CiiOldbDataPoint< T >> &dp)
 
template<typename T >
void Get (const std::string &key, std::vector< T > &values, std::shared_ptr< elt::oldb::CiiOldbDataPoint< std::vector< T >>> &dp)
 
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, const bool is_matrix, 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, const bool is_matrix, 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.

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, OldbAdapterDummy, and OldbAdapterDummy.

◆ 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/4]

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

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.

◆ Get() [2/4]

template<typename T >
void rad::cii::OldbAdapter::Get ( const std::string &  key,
std::vector< T > &  values,
std::shared_ptr< elt::oldb::CiiOldbDataPoint< std::vector< T >>> &  dp 
)

Read a vector of values from an existing attribute.

If the OLDB instance is nullptr, it tries to get one via the Connect method.

Parameters
[in]keyURI of the attribute.
[in,out]valuesThe value of the attribute if it is possible to read it, otherwise the content of 'values' is not changed.
[in,out]dpPointer to an existing data point or nullptr. In case of nullptr, the method will try to retrieve the data point.

◆ Get() [3/4]

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.

◆ Get() [4/4]

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

Read a value from an existing attribute.

If the OLDB instance is nullptr, it tries to get one via the Connect method.

Parameters
[in]keyURI of the attribute.
[in,out]valueThe value of the attribute if it is possible to read it, otherwise the content of 'value' is not changed.
[in,out]dpPointer to an existing data point or nullptr. In case of nullptr, the method will try to retrieve the data point.

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

◆ 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,
const bool  is_matrix,
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]is_matrixTrue if values are matrix, False otherwise.
[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,
const bool  is_matrix,
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]is_matrixTrue if values are matrix, False otherwise.
[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/2]

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() [2/2]

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.

◆ 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: