NCBI C++ ToolKit
blob_storage.cpp
Go to the documentation of this file.

Go to the SVN repository for this file.

1 /* $Id: blob_storage.cpp 77706 2017-05-03 12:26:07Z ivanov $
2  * ===========================================================================
3  *
4  * PUBLIC DOMAIN NOTICE
5  * National Center for Biotechnology Information
6  *
7  * This software/database is a "United States Government Work" under the
8  * terms of the United States Copyright Act. It was written as part of
9  * the author's official duties as a United States Government employee and
10  * thus cannot be copyrighted. This software/database is freely available
11  * to the public for use. The National Library of Medicine and the U.S.
12  * Government have not placed any restriction on its use or reproduction.
13  *
14  * Although all reasonable efforts have been taken to ensure the accuracy
15  * and reliability of the software and data, the NLM and the U.S.
16  * Government do not and cannot warrant the performance or results that
17  * may be obtained by using this software or data. The NLM and the U.S.
18  * Government disclaim all warranties, express or implied, including
19  * warranties of performance, merchantability or fitness for any particular
20  * purpose.
21  *
22  * Please cite the author in any work or product based on this material.
23  *
24  * ===========================================================================
25  *
26  * Author: Maxim Didenko
27  *
28  *
29  */
30 
31 
32 #include <ncbi_pch.hpp>
33 #include <corelib/blob_storage.hpp>
34 #include <corelib/ncbi_config.hpp>
36 #include <corelib/error_codes.hpp>
37 
38 
39 #define NCBI_USE_ERRCODE_X Corelib_Blob
40 
41 
43 
44 
46 {
47 }
49 {
50  NCBI_THROW(CBlobStorageException, eNotImplemented,
51  "DeleteStorage operation is not implemented.");
52 }
53 
54 
56 {
57 }
58 
59 
61  : m_Params(CConfig::ConvertRegToTree(reg), eTakeOwnership)
62 {
63 }
65  EOwnership own)
66  : m_Params(params, own)
67 {
68 }
69 
71 {
72 }
73 
75 {
76  typedef CPluginManager<IBlobStorage> TCacheManager;
77  typedef CPluginManagerGetter<IBlobStorage> TCacheManagerStore;
78 
80  //unique_ptr<TPluginManagerParamTree> params( MakeParamTree() );
81  IBlobStorage* drv = NULL;
82 
83  _ASSERT( cache_manager );
84 
85  const TPluginManagerParamTree* storage_tree =
86  m_Params->FindSubNode("blob_storage");
87 
88  string driver_name = "netcache";
89  if (storage_tree) {
90  const TPluginManagerParamTree* driver_tree =
91  storage_tree->FindSubNode("driver");
92  if (driver_tree && !driver_tree->GetValue().value.empty()) {
93  driver_name = driver_tree->GetValue().value;
94  storage_tree = m_Params->FindSubNode(driver_name);
95  }
96  } else
97  storage_tree = m_Params->FindSubNode("netcache_api");
98  if (!storage_tree)
99  storage_tree = m_Params->FindSubNode("netcache_client");
100 
101 
102  try {
103  drv = cache_manager->CreateInstance(
104  driver_name,
106  storage_tree
107  );
108  } catch (CPluginManagerException& ex) {
110  ERR_POST_X(1, Warning << ex);
112  } else {
113  throw;
114  }
115  }
116 
117  if (!drv)
118  drv = new CBlobStorage_Null;
119 
120  return drv;
121 }
122 
123 
125 {
126  switch (GetErrCode())
127  {
128  case eReader: return "eReaderError";
129  case eWriter: return "eWriterError";
130  case eBlocked: return "eBlocked";
131  case eBlobNotFound: return "eBlobNotFound";
132  case eBusy: return "eBusy";
133  case eNotImplemented: return "eNotImplemented";
134  default: return CException::GetErrCodeString();
135  }
136 }
137 
138 
Blob Storage Exception.
@ eBlobNotFound
A blob is not found.
@ eBusy
An instance of storage is busy.
@ eNotImplemented
An operation is not implemented.
@ eBlocked
A blob is blocked by another reader/writer.
@ eWriter
A problem arised while writing to a storage.
@ eReader
A problem arised while reading from a storage.
virtual const char * GetErrCodeString(void) const override
Get error code interpreted as text.
CBlobStorageFactory(const IRegistry &reg)
virtual IBlobStorage * CreateInstance(void)
Create an instance of Blob Storage.
AutoPtr< const TPluginManagerParamTree > m_Params
virtual ~CBlobStorageFactory()
An Empty implementation of Blob Storage Interface.
CPluginManagerException –.
CPluginManager<> –.
CRef –.
Definition: ncbiobj.hpp:618
definition of a Culling tree
Definition: ncbi_tree.hpp:100
virtual ~IBlobStorageFactory()
Blob Storage interface.
virtual void DeleteStorage(void)
Delete the storage with all its data.
virtual ~IBlobStorage()
IRegistry –.
Definition: ncbireg.hpp:73
@ eTakeOwnership
An object can take ownership of another.
Definition: ncbi_types.h:136
#define NULL
Definition: ncbistd.hpp:225
#define ERR_POST_X(err_subcode, message)
Error posting with default error code and given error subcode.
Definition: ncbidiag.hpp:550
TErrCode GetErrCode(void) const
Get error code.
Definition: ncbiexpt.cpp:453
#define NCBI_THROW(exception_class, err_code, message)
Generic macro to throw an exception, given the exception class, error code and message string.
Definition: ncbiexpt.hpp:704
void Warning(CExceptionArgs_Base &args)
Definition: ncbiexpt.hpp:1191
TErrCode GetErrCode(void) const
Definition: ncbiexpt.hpp:1493
virtual const char * GetErrCodeString(void) const
Get error code interpreted as text.
Definition: ncbiexpt.cpp:444
#define NCBI_INTERFACE_VERSION(iface)
Macro to construct CVersionInfo class using interface name (relies on CInterfaceVersion class)
@ eResolveFailure
Cannot resolve interface driver.
@ eNullInstance
Factory returned NULL instance.
#define END_NCBI_SCOPE
End previously defined NCBI scope.
Definition: ncbistl.hpp:103
#define BEGIN_NCBI_SCOPE
Define ncbi namespace.
Definition: ncbistl.hpp:100
const TTreeType * FindSubNode(const TKeyType &key) const
Non recursive linear scan of all subnodes, with key comparison.
Definition: ncbi_tree.hpp:940
const TValue & GetValue(void) const
Return node's value.
Definition: ncbi_tree.hpp:184
enum ENcbiOwnership EOwnership
Ownership relations between objects.
Definition of all error codes used in corelib (xncbi.lib).
const TYPE & Get(const CNamedParameterList *param)
Parameters initialization model.
#define _ASSERT
Modified on Wed Feb 21 09:56:38 2024 by modify_doxy.py rev. 669887