NCBI C++ ToolKit
nst_service_parameters.hpp
Go to the documentation of this file.

Go to the SVN repository for this file.

1 #ifndef NETSTORAGE_SERVICE_PARAMETERS__HPP
2 #define NETSTORAGE_SERVICE_PARAMETERS__HPP
3 
4 /* $Id: nst_service_parameters.hpp 73298 2016-06-28 18:55:51Z satskyse $
5  * ===========================================================================
6  *
7  * PUBLIC DOMAIN NOTICE
8  * National Center for Biotechnology Information
9  *
10  * This software/database is a "United States Government Work" under the
11  * terms of the United States Copyright Act. It was written as part of
12  * the author's official duties as a United States Government employee and
13  * thus cannot be copyrighted. This software/database is freely available
14  * to the public for use. The National Library of Medicine and the U.S.
15  * Government have not placed any restriction on its use or reproduction.
16  *
17  * Although all reasonable efforts have been taken to ensure the accuracy
18  * and reliability of the software and data, the NLM and the U.S.
19  * Government do not and cannot warrant the performance or results that
20  * may be obtained by using this software or data. The NLM and the U.S.
21  * Government disclaim all warranties, express or implied, including
22  * warranties of performance, merchantability or fitness for any particular
23  * purpose.
24  *
25  * Please cite the author in any work or product based on this material.
26  *
27  * ===========================================================================
28  *
29  * Authors: Sergey Satskiy
30  *
31  * File Description:
32  * NetStorage services and their properties
33  *
34  */
35 
36 #include <corelib/ncbimtx.hpp>
37 #include <corelib/ncbistr.hpp>
39 
40 #include "nst_database.hpp"
41 
42 
44 
45 
46 // The latest requirement is to make the service name case insensitive.
47 // So this constant can use any letters - the test statements are case
48 // insensitive throughout the code
49 const string k_LBSMDNSTTestService = "LBSMDNSTTestService";
50 const double k_ProlongInTTLsNotConfigured = -1.0;
51 
56 
57 
58 // Note: access to the instances of this class is possible only via the service
59 // registry and the corresponding container access is always done under a lock.
60 // So it is safe to do any modifications in the members without any locks here.
62 {
63  public:
66  const CTimeSpan & prolong_on_read,
67  const CTimeSpan & prolong_on_write,
68  const CTimeSpan & prolong_on_relocate) :
69  m_TTL(ttl), m_ProlongOnRead(prolong_on_read),
71  m_ProlongOnWrite(prolong_on_write),
73  m_ProlongOnRelocate(prolong_on_relocate),
75  {}
76 
78  { return m_TTL; }
79  string GetTTLAsString(void) const;
80  string GetProlongOnReadAsString(void) const
83  string GetProlongOnWriteAsString(void) const
86  string GetProlongOnRelocateAsString(void) const
89 
91  const TNSTDBValue<Int8> & individual_obj_ttl) const;
93  const TNSTDBValue<Int8> & individual_obj_ttl) const;
95  const TNSTDBValue<Int8> & individual_obj_ttl) const;
96 
97  void SetTTL(const TNSTDBValue<CTimeSpan> & new_val)
98  { m_TTL = new_val; }
99  void SetProlongOnRead(const CTimeSpan & new_val)
100  { m_ProlongOnRead = new_val;
102  void SetProlongOnRead(double inTTLs)
103  { m_ProlongOnRead = CTimeSpan(0L);
104  m_ProlongOnReadInTTLs = inTTLs; }
105  void SetProlongOnWrite(const CTimeSpan & new_val)
106  { m_ProlongOnWrite = new_val;
108  void SetProlongOnWrite(double inTTLs)
109  { m_ProlongOnWrite = CTimeSpan(0L);
110  m_ProlongOnWriteInTTLs = inTTLs; }
111  void SetProlongOnRelocate(const CTimeSpan & new_val)
112  { m_ProlongOnRelocate = new_val;
114  void SetProlongOnRelocate(double inTTLs)
116  m_ProlongOnRelocateInTTLs = inTTLs; }
117 
118  CJsonNode Serialize(void) const;
119 
120  bool operator==(const CNSTServiceProperties & other) const
121  { return
122  (m_TTL == other.m_TTL) &&
123  (m_ProlongOnRead == other.m_ProlongOnRead) &&
125  (m_ProlongOnWrite == other.m_ProlongOnWrite) &&
129  bool operator!=(const CNSTServiceProperties & other) const
130  { return !this->operator==(other); }
131 
132  private:
140 
141  private:
142  string x_GetProlongAsString(const CTimeSpan & as_time_span,
143  double in_ttls) const;
145  x_GetProlongInTTLs(double multiplier,
146  const TNSTDBValue<Int8> & individual_obj_ttl) const;
147 };
148 
149 
150 // Specific case for a service info
152 {
153  eUnknownService, // [service_XXX] section is not in the .ini file
154  // at all.
155  eMetadataOn, // [service_XXX] section is in the .ini file and
156  // 'metadata' is set to true
157  eMetadataExplicitOff, // [service_XXX] section is in the .ini file and
158  // 'metadata' is set to false
159  eMetadataDefaultOff // [service_XXX] section is in the .ini file and
160  // 'metadata' is not found i.e. false by default
161 };
162 
163 
165 {
166  public:
168 
169  size_t Size(void) const;
171  CJsonNode Serialize(void) const;
172  EServiceMetadataPresence IsKnown(const string & service) const;
173  bool GetTTL(const string & service,
174  TNSTDBValue<CTimeSpan> & ttl) const;
175  bool GetProlongOnRead(
176  const string & service,
177  const TNSTDBValue<Int8> & individual_obj_ttl,
178  TNSTDBValue<CTimeSpan> & prolong_on_read) const;
179  bool GetProlongOnWrite(
180  const string & service,
181  const TNSTDBValue<Int8> & individual_obj_ttl,
182  TNSTDBValue<CTimeSpan> & prolong_on_write) const;
184  const string & service,
185  const TNSTDBValue<Int8> & individual_obj_ttl,
186  TNSTDBValue<CTimeSpan> & prolong_on_relocate) const;
187  bool GetServiceProperties(const string & service,
188  CNSTServiceProperties & props) const;
190 
191  private:
194  const string & section,
195  const CNSTServiceProperties & defaults);
196  CTimeSpan x_ReadProlongProperty(const string & value);
197  double x_ReadProlongInTTLs(string & value) const;
198  list<string> x_GetMetadataServices(const IRegistry & reg);
199 
200  private:
203 
204  // The latest requirement is to make the service case insensitive
205  typedef map< string,
208  TServiceProperties m_Services; // All the services
209  // netstorage knows about
210 
211  // Auxiliary data to provide a better log messages
214 
215  mutable CMutex m_Lock; // Lock for the map
216 };
217 
218 
220 
221 #endif /* NETSTORAGE_SERVICE_PARAMETERS__HPP */
222 
JSON node abstraction.
CMutex –.
Definition: ncbimtx.hpp:749
void SetProlongOnRead(const CTimeSpan &new_val)
TNSTDBValue< CTimeSpan > GetProlongOnWrite(const TNSTDBValue< Int8 > &individual_obj_ttl) const
void SetTTL(const TNSTDBValue< CTimeSpan > &new_val)
void SetProlongOnRead(double inTTLs)
string GetProlongOnWriteAsString(void) const
TNSTDBValue< CTimeSpan > m_TTL
void SetProlongOnWrite(double inTTLs)
TNSTDBValue< CTimeSpan > x_GetProlongInTTLs(double multiplier, const TNSTDBValue< Int8 > &individual_obj_ttl) const
string x_GetProlongAsString(const CTimeSpan &as_time_span, double in_ttls) const
string GetProlongOnRelocateAsString(void) const
bool operator!=(const CNSTServiceProperties &other) const
CNSTServiceProperties(const TNSTDBValue< CTimeSpan > &ttl, const CTimeSpan &prolong_on_read, const CTimeSpan &prolong_on_write, const CTimeSpan &prolong_on_relocate)
CJsonNode Serialize(void) const
TNSTDBValue< CTimeSpan > GetTTL(void) const
bool operator==(const CNSTServiceProperties &other) const
string GetTTLAsString(void) const
void SetProlongOnRelocate(double inTTLs)
TNSTDBValue< CTimeSpan > GetProlongOnRead(const TNSTDBValue< Int8 > &individual_obj_ttl) const
TNSTDBValue< CTimeSpan > GetProlongOnRelocate(const TNSTDBValue< Int8 > &individual_obj_ttl) const
void SetProlongOnWrite(const CTimeSpan &new_val)
string GetProlongOnReadAsString(void) const
void SetProlongOnRelocate(const CTimeSpan &new_val)
set< string, PNocase > m_ServicesExplicitNoMetadata
bool GetTTL(const string &service, TNSTDBValue< CTimeSpan > &ttl) const
map< string, CNSTServiceProperties, PNocase > TServiceProperties
CTimeSpan x_ReadProlongProperty(const string &value)
list< string > x_GetMetadataServices(const IRegistry &reg)
CNSTServiceProperties GetDefaultProperties(void) const
CNSTServiceProperties m_DefaultProperties
bool GetProlongOnRead(const string &service, const TNSTDBValue< Int8 > &individual_obj_ttl, TNSTDBValue< CTimeSpan > &prolong_on_read) const
set< string, PNocase > m_ServicesDefaultNoMetadata
double x_ReadProlongInTTLs(string &value) const
CJsonNode Serialize(void) const
bool GetServiceProperties(const string &service, CNSTServiceProperties &props) const
TServiceProperties m_Services
CNSTServiceProperties m_LBSMDTestServiceProperties
bool GetProlongOnWrite(const string &service, const TNSTDBValue< Int8 > &individual_obj_ttl, TNSTDBValue< CTimeSpan > &prolong_on_write) const
CJsonNode ReadConfiguration(const IRegistry &reg)
EServiceMetadataPresence IsKnown(const string &service) const
bool GetProlongOnRelocate(const string &service, const TNSTDBValue< Int8 > &individual_obj_ttl, TNSTDBValue< CTimeSpan > &prolong_on_relocate) const
CNSTServiceProperties x_ReadServiceProperties(const IRegistry &reg, const string &section, const CNSTServiceProperties &defaults)
CTimeSpan.
Definition: ncbitime.hpp:1313
IRegistry –.
Definition: ncbireg.hpp:73
Definition: map.hpp:338
The NCBI C++ standard methods for dealing with std::string.
string
Definition: cgiapp.hpp:687
#define END_NCBI_SCOPE
End previously defined NCBI scope.
Definition: ncbistl.hpp:103
#define BEGIN_NCBI_SCOPE
Define ncbi namespace.
Definition: ncbistl.hpp:100
unsigned int TSmartStringFlags
Binary OR of "ESmartStringFlags".
Definition: ncbitime.hpp:1499
@ fSS_Nanosecond
Do not round at all (accurate time span)
Definition: ncbitime.hpp:1460
const GenericPointer< typename T::ValueType > T2 value
Definition: pointer.h:1227
Multi-threading – mutexes; rw-locks; semaphore.
const string k_LBSMDNSTTestService
EServiceMetadataPresence
@ eMetadataExplicitOff
@ eMetadataDefaultOff
const double k_ProlongInTTLsNotConfigured
const CTimeSpan::TSmartStringFlags kTimeSpanFlags
Modified on Sun Apr 14 05:25:48 2024 by modify_doxy.py rev. 669887