NCBI C++ ToolKit
|
Search Toolkit Book for CDataCrawlerCache
Base class for data crawler cache objects. More...
#include <gui/widgets/loaders/data_crawler_cache.hpp>
Public Types | |
enum | ECacheState { eState_None , eState_InProgress , eState_NotAccessible , eState_Created } |
Cache object states. More... | |
Public Member Functions | |
CDataCrawlerCache ()=default | |
Default constructor. More... | |
ECacheState | GetState () const |
Gets the state of the cache object. More... | |
ECacheState | SetState (ECacheState desired_state) |
Changes the state of the cache object. More... | |
size_t | GetReadSize () const |
Returns size of existing BLOB data. More... | |
std::unique_ptr< CNcbiIstream > | GetReadStream () |
Returns stream interface to read BLOB data. More... | |
std::unique_ptr< CNcbiOstream > | GetWriteStream () |
Returns stream interface to write BLOB data. More... | |
void | Remove () |
Removes the cache entry. More... | |
const std::string & | GetKey () const |
Returns the NetCache key of the BLOB. More... | |
const std::string | GetCompoundKey () const |
Returns the compound NetCache key of the BLOB. More... | |
virtual | ~CDataCrawlerCache () |
Destructor. More... | |
Protected Types | |
enum | ECacheType { eCache_Blob , eCache_Sync } |
Types of cache objects. More... | |
Protected Member Functions | |
void | x_Initialize () |
Initializes the cache instances. More... | |
std::string | x_GetCacheKey (ECacheType type) |
Generates the cache key for a given type. More... | |
virtual CNetICacheClient | x_InitBlobCache ()=0 |
Creates the BLOB NetCache instance. More... | |
virtual CNetICacheClient | x_InitSyncCache ()=0 |
Creates the sync NetCache instance. More... | |
virtual std::string | x_GetCacheKey ()=0 |
Generates the cache key. More... | |
void | x_StartHeartbeat () |
Starts the heartbeat (thread to keep the sybc object alive) More... | |
void | x_StopHeartbeat () |
Stops the heartbeat (thread to keep the sybc object alive) More... | |
void | x_Heartbeat () |
The heartbeat thread function. More... | |
CNetICacheClient | x_InitICache (const std::string &cache, const std::string &service, const std::string &db) |
Creates a NetCache instance. More... | |
ECacheState | x_ReadState () const |
Reads the state of the sync object. More... | |
void | x_WriteState (ECacheState state, unsigned int ttl=300) |
Writes a new state to the sync object. More... | |
Protected Attributes | |
bool | m_isImmutableKey {false} |
do not try to shorten or otherwise modify the root cache key More... | |
Private Attributes | |
std::string | m_BlobKey |
The NetCache key of the BLOB object. More... | |
std::string | m_SyncKey |
The NetCache key of the sync object. More... | |
CNetICacheClient | m_BlobCache |
Blobs NetCache instance. More... | |
CNetICacheClient | m_SyncCache |
Sync objects NetCache instance. More... | |
std::mutex | m_SyncCacheMutex |
Mutex, controlling the access to the sync cache. More... | |
std::atomic_bool | m_StopHeartbeat { false } |
Boolean flag to stop the heartbeat thread. More... | |
std::unique_ptr< std::thread > | m_Heartbeat |
The heartbeat thread. More... | |
Base class for data crawler cache objects.
Definition at line 47 of file data_crawler_cache.hpp.
Cache object states.
Definition at line 51 of file data_crawler_cache.hpp.
|
protected |
Types of cache objects.
Enumerator | |
---|---|
eCache_Blob | |
eCache_Sync | BLOB object. Synchronization object |
Definition at line 101 of file data_crawler_cache.hpp.
|
default |
Default constructor.
|
virtual |
Returns the compound NetCache key of the BLOB.
Definition at line 231 of file data_crawler_cache.cpp.
References CNetStorageObjectLoc::Create(), CNetICacheClient::GetCacheName(), CNetICacheClient::GetService(), CNetService::GetServiceName(), m_BlobCache, m_BlobKey, and version.
|
inline |
Returns the NetCache key of the BLOB.
Definition at line 90 of file data_crawler_cache.hpp.
References m_BlobKey.
size_t CDataCrawlerCache::GetReadSize | ( | ) | const |
Returns size of existing BLOB data.
Definition at line 107 of file data_crawler_cache.cpp.
References CNetICacheClient::GetSize(), m_BlobCache, and m_BlobKey.
unique_ptr< CNcbiIstream > CDataCrawlerCache::GetReadStream | ( | ) |
Returns stream interface to read BLOB data.
Definition at line 112 of file data_crawler_cache.cpp.
References CRWStreambuf::fOwnReader, CNetICacheClient::GetReadStream(), m_BlobCache, and m_BlobKey.
CDataCrawlerCache::ECacheState CDataCrawlerCache::GetState | ( | void | ) | const |
Gets the state of the cache object.
Definition at line 48 of file data_crawler_cache.cpp.
References eState_Created, eState_None, CNetICacheClient::HasBlob(), Info(), LOG_POST, m_BlobCache, m_BlobKey, m_SyncCache, m_SyncKey, and x_ReadState().
Referenced by SetState().
unique_ptr< CNcbiOstream > CDataCrawlerCache::GetWriteStream | ( | ) |
Returns stream interface to write BLOB data.
Definition at line 118 of file data_crawler_cache.cpp.
References CRWStreambuf::fOwnWriter, CNetICacheClient::GetWriteStream(), m_BlobCache, and m_BlobKey.
Referenced by ColumnarVcfCache::CreateBlob().
void CDataCrawlerCache::Remove | ( | void | ) |
Removes the cache entry.
Definition at line 124 of file data_crawler_cache.cpp.
References m_BlobCache, m_BlobKey, and CNetICacheClient::Remove().
CDataCrawlerCache::ECacheState CDataCrawlerCache::SetState | ( | ECacheState | desired_state | ) |
Changes the state of the cache object.
[in] | desired_state | The desired state to switch to. |
Definition at line 63 of file data_crawler_cache.cpp.
References eState_Created, eState_InProgress, eState_None, eState_NotAccessible, GetState(), m_SyncCache, m_SyncCacheMutex, m_SyncKey, CNetICacheClient::Remove(), x_StartHeartbeat(), x_StopHeartbeat(), and x_WriteState().
Referenced by ColumnarVcfCache::CreateBlob().
|
protectedpure virtual |
Generates the cache key.
Implemented in CColumnarVcfCache.
Referenced by x_GetCacheKey(), and x_Initialize().
|
protected |
Generates the cache key for a given type.
[in] | type | The desired cache type. |
Definition at line 138 of file data_crawler_cache.cpp.
References eCache_Blob, eCache_Sync, ncbi::grid::netcache::search::fields::key, m_isImmutableKey, md5(), and x_GetCacheKey().
|
protected |
The heartbeat thread function.
Definition at line 194 of file data_crawler_cache.cpp.
References Error(), eState_InProgress, LOG_POST, m_StopHeartbeat, and x_WriteState().
Referenced by x_StartHeartbeat().
|
protectedpure virtual |
Creates the BLOB NetCache instance.
Implemented in CColumnarVcfCache.
Referenced by x_Initialize().
|
protected |
Initializes the cache instances.
Definition at line 129 of file data_crawler_cache.cpp.
References eCache_Blob, eCache_Sync, ICache::fBestReliability, m_BlobCache, m_BlobKey, m_SyncCache, m_SyncKey, CNetICacheClient::SetFlags(), x_GetCacheKey(), x_InitBlobCache(), and x_InitSyncCache().
Referenced by CColumnarVcfCache::CColumnarVcfCache().
|
protected |
Creates a NetCache instance.
[in] | cache | Name of the registry section to look for the configuration parameters in. |
[in] | service | The service name. |
[in] | db | The cache name. |
Definition at line 207 of file data_crawler_cache.cpp.
References CNcbiApplicationAPI::GetConfig(), IRegistry::GetString(), Info(), CNcbiApplication::Instance(), and LOG_POST.
Referenced by CColumnarVcfCache::x_InitBlobCache(), and CColumnarVcfCache::x_InitSyncCache().
|
protectedpure virtual |
Creates the sync NetCache instance.
Implemented in CColumnarVcfCache.
Referenced by x_Initialize().
|
inlineprotected |
Reads the state of the sync object.
Definition at line 216 of file data_crawler_cache.cpp.
References eState_None, m_SyncCache, m_SyncCacheMutex, m_SyncKey, CNetICacheClient::Read(), and result.
Referenced by GetState().
|
protected |
Starts the heartbeat (thread to keep the sybc object alive)
Definition at line 166 of file data_crawler_cache.cpp.
References Error(), eUnknown, Info(), LOG_POST, m_Heartbeat, m_StopHeartbeat, NCBI_THROW, and x_Heartbeat().
Referenced by SetState().
|
protected |
Stops the heartbeat (thread to keep the sybc object alive)
Definition at line 179 of file data_crawler_cache.cpp.
References Error(), Info(), LOG_POST, m_Heartbeat, and m_StopHeartbeat.
Referenced by SetState(), and ~CDataCrawlerCache().
|
inlineprotected |
Writes a new state to the sync object.
[in] | state | The state to write. |
[in] | ttl | Time to live in seconds. 5 minutes by default. |
Definition at line 224 of file data_crawler_cache.cpp.
References m_SyncCache, m_SyncCacheMutex, m_SyncKey, and CNetICacheClient::Store().
Referenced by SetState(), and x_Heartbeat().
|
mutableprivate |
Blobs NetCache instance.
Definition at line 168 of file data_crawler_cache.hpp.
Referenced by GetCompoundKey(), GetReadSize(), GetReadStream(), GetState(), GetWriteStream(), Remove(), and x_Initialize().
|
private |
The NetCache key of the BLOB object.
Definition at line 164 of file data_crawler_cache.hpp.
Referenced by GetCompoundKey(), GetKey(), GetReadSize(), GetReadStream(), GetState(), GetWriteStream(), Remove(), and x_Initialize().
|
private |
The heartbeat thread.
Definition at line 176 of file data_crawler_cache.hpp.
Referenced by x_StartHeartbeat(), and x_StopHeartbeat().
do not try to shorten or otherwise modify the root cache key
Definition at line 180 of file data_crawler_cache.hpp.
Referenced by CColumnarVcfCache::CColumnarVcfCache(), and x_GetCacheKey().
|
private |
Boolean flag to stop the heartbeat thread.
Definition at line 174 of file data_crawler_cache.hpp.
Referenced by x_Heartbeat(), x_StartHeartbeat(), and x_StopHeartbeat().
|
mutableprivate |
Sync objects NetCache instance.
Definition at line 170 of file data_crawler_cache.hpp.
Referenced by GetState(), SetState(), x_Initialize(), x_ReadState(), and x_WriteState().
|
mutableprivate |
Mutex, controlling the access to the sync cache.
Definition at line 172 of file data_crawler_cache.hpp.
Referenced by SetState(), x_ReadState(), and x_WriteState().
|
private |
The NetCache key of the sync object.
Definition at line 166 of file data_crawler_cache.hpp.
Referenced by GetState(), SetState(), x_Initialize(), x_ReadState(), and x_WriteState().