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

Go to the SVN repository for this file.

1 /* $Id: dbapi_svc_mapper.cpp 100856 2023-09-20 15:45:25Z ucko $
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: Sergey Sikorskiy
27 *
28 */
29 
30 #include <ncbi_pch.hpp>
31 
34 #include <corelib/ncbiapp.hpp>
35 // #include <connect/ncbi_socket.h>
36 #include <algorithm>
37 #include <cmath>
38 
39 
41 
42 
43 //////////////////////////////////////////////////////////////////////////////
44 static
46 make_server(const CTempString& specification, double& preference)
47 {
48  CTempString server;
49  // string host;
50  Uint4 host = 0;
51  Uint2 port = 0;
52  string::size_type pos = 0;
53 
54  pos = specification.find_first_of("@(", pos);
55  if (pos != string::npos) {
56  server = specification.substr(0, pos);
57 
58  if (specification[pos] == '@') {
59  // string::size_type old_pos = pos + 1;
60  pos = specification.find_first_of(":(", pos + 1);
61  if (pos != string::npos) {
62  // string host_str = specification.substr(old_pos, pos - old_pos);
63  // Ignore host in order to avoid dependebcy on libconnect.
64  // SOCK_StringToHostPort(specification.c_str() + old_pos, &host, &port);
65  if (specification[pos] == ':') {
66  port = NStr::StringToUInt(specification.substr(pos + 1),
70  pos = specification.find("(", pos + 1);
71  if (pos != string::npos) {
72  // preference = NStr::StringToDouble(
73  preference = NStr::StringToUInt(
74  specification.substr(pos + 1),
78  }
79  } else {
80  // preference = NStr::StringToDouble(
81  preference = NStr::StringToUInt(
82  specification.substr(pos + 1),
86  }
87  } else {
88  // host = specification.substr(old_pos);
89  // Ignore host in order to avoid dependebcy on libconnect.
90  // SOCK_StringToHostPort(specification.c_str() + old_pos, &host, &port);
91  }
92  } else {
93  // preference = NStr::StringToDouble(
94  preference = NStr::StringToUInt(
95  specification.substr(pos + 1),
99  }
100  } else {
101  server = specification;
102  }
103 
104  if (server.empty() && host == 0) {
105  DATABASE_DRIVER_ERROR("Either server name or host name expected.",
106  110100 );
107  }
108 
109  return CRef<CDBServerOption>
110  (new CDBServerOption(server, host, port, preference));
111 }
112 
113 
114 
115 //////////////////////////////////////////////////////////////////////////////
117 {
118 }
119 
121 {
122 }
123 
125 {
127 }
128 
129 void
131 {
132  // Do nothing.
133 }
134 
135 TSvrRef
137 {
138  if (m_ExcludeMap.find(service) != m_ExcludeMap.end()) {
139  return TSvrRef();
140  }
141 
142  return TSvrRef(new CDBServer(service));
143 }
144 
145 void
147  const TSvrRef&,
148  double)
149 {
150  // Do nothing.
151 }
152 
153 
154 //////////////////////////////////////////////////////////////////////////////
156 {
157 }
158 
160 {
161 }
162 
164 {
165  if (Top().NotEmpty()) {
166  return Top()->GetName();
167  } else {
169  }
170 }
171 
172 void
174 {
176 
178 }
179 
180 TSvrRef
181 CDBServiceMapperCoR::GetServer(const string& service)
182 {
184 
185  TSvrRef server;
186  TDelegates::reverse_iterator dg_it = m_Delegates.rbegin();
187  TDelegates::reverse_iterator dg_end = m_Delegates.rend();
188 
189  for (; server.Empty() && dg_it != dg_end; ++dg_it) {
190  server = (*dg_it)->GetServer(service);
191  }
192 
193  return server;
194 }
195 
196 void
197 CDBServiceMapperCoR::Exclude(const string& service,
198  const TSvrRef& server)
199 {
201 
203  (*dg_it)->Exclude(service, server);
204  }
205 }
206 
207 void
209 {
211 
213  (*dg_it)->CleanExcluded(service);
214  }
215 }
216 
217 bool CDBServiceMapperCoR::HasExclusions(const string& service) const
218 {
219  ITERATE (TDelegates, dg_it, m_Delegates) {
220  if ((*dg_it)->HasExclusions(service)) {
221  return true;
222  }
223  }
224  return false;
225 }
226 
227 void
229  const TSvrRef& preferred_server,
230  double preference)
231 {
233 
235  (*dg_it)->SetPreference(service, preferred_server, preference);
236  }
237 }
238 
239 void
240 CDBServiceMapperCoR::GetServersList(const string& service, list<string>* serv_list) const
241 {
243 
244  TDelegates::const_reverse_iterator dg_it = m_Delegates.rbegin();
245  TDelegates::const_reverse_iterator dg_end = m_Delegates.rend();
246  for (; serv_list->empty() && dg_it != dg_end; ++dg_it) {
247  (*dg_it)->GetServersList(service, serv_list);
248  }
249 }
250 
251 void
252 CDBServiceMapperCoR::GetServerOptions(const string& service, TOptions* options)
253 {
255 
256  TDelegates::reverse_iterator dg_it = m_Delegates.rbegin();
257  TDelegates::reverse_iterator dg_end = m_Delegates.rend();
258  for (; options->empty() && dg_it != dg_end; ++dg_it) {
259  (*dg_it)->GetServerOptions(service, options);
260  }
261 }
262 
263 
264 bool
266 {
269  if ((*dg_it)->RecordServer(extra)) {
270  return true;
271  }
272  }
273  return false;
274 }
275 
276 
277 void
279 {
281  (*dg_it)->Configure(registry);
282  }
283 }
284 
285 void
287 {
288  if (mapper.NotNull()) {
290 
291  m_Delegates.push_back(mapper);
292  }
293 }
294 
295 void
297 {
299 
300  m_Delegates.pop_back();
301 }
302 
305 {
307 
308  return m_Delegates.back();
309 }
310 
311 bool
313 {
315 
316  return m_Delegates.empty();
317 }
318 
319 //////////////////////////////////////////////////////////////////////////////
321 {
322  random_device rdev;
323  m_RandomEngine.seed(rdev());
325 }
326 
328 {
329 }
330 
331 string CDBUDRandomMapper::GetName(void) const
332 {
334 }
335 
336 void
338 {
340 
342 }
343 
344 void
346 {
347  const string section_name
349  list<string> entries;
350 
351  // Get current registry ...
354  }
355 
356  if (registry) {
357  // Erase previous data ...
358  m_LBNameMap.clear();
359  m_ServerMap.clear();
362 
363  registry->EnumerateEntries(section_name, &entries);
364  ITERATE(list<string>, cit, entries) {
365  vector<string> server_name;
366  string service_name = *cit;
367 
368  NStr::Split(registry->GetString(section_name,
369  service_name,
370  service_name),
371  " ,;",
372  server_name,
374 
375  // Replace with new data ...
376  if (!server_name.empty()) {
377  TOptions& server_list = m_ServerMap[service_name];
378 
379  ITERATE(vector<string>, sn_it, server_name) {
380  double tmp_preference = 0;
381 
382  // Parse server preferences.
383  auto cur_server = make_server(*sn_it, tmp_preference);
384  if (tmp_preference < 0) {
385  cur_server->m_Ranking = 0;
386  } else if (tmp_preference >= 100) {
387  cur_server->m_Ranking = 100;
388  m_FavoritesMap[service_name].push_back(cur_server);
389  }
390 
391  server_list.push_back(cur_server);
392 
393  }
394  x_RecalculatePreferences(service_name);
395  }
396  }
397  }
398 }
399 
400 TSvrRef
401 CDBUDRandomMapper::GetServer(const string& service)
402 {
404 
405  if (m_LBNameMap.find(service) != m_LBNameMap.end() &&
406  m_LBNameMap[service] == false) {
407  // We've tried this service already. It is not served by load
408  // balancer. There is no reason to try it again.
409  return TSvrRef();
410  }
411 
412  const auto& it = m_PreferenceMap.find(service);
413  if (it != m_PreferenceMap.end()) {
414  m_LBNameMap[service] = true;
415  return it->second.servers[(*it->second.distribution)(m_RandomEngine)];
416  }
417 
418  m_LBNameMap[service] = false;
419  return TSvrRef();
420 }
421 
422 void
423 CDBUDRandomMapper::Add(const string& service,
424  const TSvrRef& server,
425  double preference)
426 {
427  _ASSERT(false);
428 
429  if (service.empty() || server.Empty()) {
430  return;
431  }
432 
433  TOptions& server_list = m_ServerMap[service];
435  (new CDBServerOption(server->GetName(), server->GetHost(),
436  server->GetPort(), preference));
437 
438  if (preference < 0) {
439  option->m_Ranking = 0;
440  } else if (preference >= 100) {
441  option->m_Ranking = 100;
442  m_FavoritesMap[service].push_back(option);
443  }
444 
445  server_list.push_back(option);
446 
447  x_RecalculatePreferences(service);
448 }
449 
450 void
451 CDBUDRandomMapper::Exclude(const string& service, const TSvrRef& server)
452 {
454  auto svc = m_ServerMap.find(service);
455  if (svc != m_ServerMap.end()) {
456  for (auto svr : svc->second) {
457  if (svr->Matches(*server, service)) {
458  svr->m_State |= CDBServerOption::fState_Excluded;
459  }
460  }
461  x_RecalculatePreferences(service);
462  }
463 }
464 
465 void
466 CDBUDRandomMapper::CleanExcluded(const string& service)
467 {
469  auto svc = m_ServerMap.find(service);
470  if (svc != m_ServerMap.end()) {
471  for (auto svr : svc->second) {
472  svr->m_State &= ~CDBServerOption::fState_Excluded;
473  }
474  x_RecalculatePreferences(service);
475  }
476 }
477 
478 bool
479 CDBUDRandomMapper::HasExclusions(const string& service) const
480 {
482  auto svc = m_ServerMap.find(service);
483  auto prefs = m_PreferenceMap.find(service);
484  if (svc == m_ServerMap.end()) {
485  return false;
486  } else if (prefs == m_PreferenceMap.end()) {
487  return true;
488  } else if (svc->second.size() == prefs->second.servers.size()) {
489  return false;
490  } else if (prefs->second.servers.size() != 1) {
491  return true;
492  } else {
493  return prefs->second.servers[0]->GetRanking() < 100.0;
494  }
495 }
496 
497 void
498 CDBUDRandomMapper::SetPreference(const string& service,
499  const TSvrRef& preferred_server,
500  double preference)
501 {
503 
504  auto svc = m_ServerMap.find(service);
505  if (svc != m_ServerMap.end()) {
506  for (auto svr : svc->second) {
507  if (svr == preferred_server || *svr == *preferred_server) {
508  double old_preference = svr->GetRanking();
509  svr->m_Ranking = max(0.0, min(100.0, preference));
510  if (preference >= 100.0 && old_preference < 100.0) {
511  m_FavoritesMap[service].push_back(svr);
512  } else if (preference < 100.0 && old_preference >= 100.0) {
513  auto& favorites = m_FavoritesMap[service];
514  favorites.erase(find(favorites.begin(), favorites.end(),
515  svr));
516  if (favorites.empty()) {
517  m_FavoritesMap.erase(service);
518  }
519  }
520  }
521  }
522  x_RecalculatePreferences(service);
523  }
524 }
525 
526 void
527 CDBUDRandomMapper::GetServerOptions(const string& service, TOptions* options)
528 {
530  auto it = m_ServerMap.find(service);
531  if (it == m_ServerMap.end()) {
532  options->clear();
533  } else {
534  *options = it->second;
535  }
536 }
537 
540 {
541  return new CDBUDRandomMapper(registry);
542 }
543 
544 void
546 {
547  SPreferences& service_preferences = m_PreferenceMap[service];
548  service_preferences.servers.clear();
549  {{
551  if (favs != m_FavoritesMap.end()) {
552  REVERSE_ITERATE(TOptions, it, favs->second) {
553  if ( !(*it)->IsExcluded() ) {
554  service_preferences.servers.push_back(*it);
555  service_preferences.distribution.reset
556  (new discrete_distribution<>({100.0}));
557  return;
558  }
559  }
560  }
561  }}
562  vector<double> weights;
563  bool all_zero = true;
564  for (const auto & it : m_ServerMap[service]) {
565  double weight = 0.0;
566  if ( !it->IsExcluded() ) {
567  weight = it->GetRanking();
568  _ASSERT(weight < 100.0);
569  if (weight > 0.0) {
570  all_zero = false;
571  }
572  }
573  weights.push_back(weight);
574  }
575  if (all_zero) {
576  for (auto & w : weights) {
577  w = 1.0;
578  }
579  }
580  service_preferences.distribution.reset
581  (new discrete_distribution<>(weights.begin(), weights.end()));
582 }
583 
584 
585 //////////////////////////////////////////////////////////////////////////////
587 {
589 }
590 
592 {
593 }
594 
596 {
598 }
599 
600 void
602 {
604 
606 }
607 
608 void
610 {
611  const string section_name
613  list<string> entries;
614 
615  // Get current registry ...
618  }
619 
620  if (registry) {
621  // Erase previous data ...
622  m_ServerMap.clear();
624 
625  registry->EnumerateEntries(section_name, &entries);
626 
627  ITERATE(list<string>, cit, entries) {
628  vector<string> server_name;
629  string service_name = *cit;
630 
631  NStr::Split(registry->GetString(section_name,
632  service_name,
633  service_name),
634  " ,;",
635  server_name,
637 
638  // Replace with new data ...
639  if (!server_name.empty()) {
640 // TSvrMap& server_list = m_ServerMap[service_name];
641 // TServerUsageMap& usage_map = m_ServiceUsageMap[service_name];
642 
643  ITERATE(vector<string>, sn_it, server_name) {
644  double tmp_preference = 0;
645 
646  // Parse server preferences.
647  TSvrRef cur_server = make_server(*sn_it, tmp_preference);
648 
649  // Replaced with Add()
650 // if (tmp_preference < 0) {
651 // tmp_preference = 0;
652 // } else if (tmp_preference > 100) {
653 // tmp_preference = 100;
654 // }
655 //
656 // server_list.insert(
657 // TSvrMap::value_type(cur_server, tmp_preference));
658 // usage_map.insert(TServerUsageMap::value_type(
659 // 100 - tmp_preference,
660 // cur_server));
661 
662  Add(service_name, cur_server, tmp_preference);
663  }
664  }
665  }
666  }
667 }
668 
669 TSvrRef
670 CDBUDPriorityMapper::GetServer(const string& service)
671 {
673 
674  if (m_LBNameMap.find(service) != m_LBNameMap.end() &&
675  m_LBNameMap[service] == false) {
676  // We've tried this service already. It is not served by load
677  // balancer. There is no reason to try it again.
678  return TSvrRef();
679  }
680 
681  TServerUsageMap& usage_map = m_ServiceUsageMap[service];
682  TSvrMap& server_map = m_ServerMap[service];
683 
684  if (!server_map.empty() && !usage_map.empty()) {
685  TServerUsageMap::iterator su_it = usage_map.begin();
686  double new_preference = su_it->first;
687  TSvrRef cur_server = su_it->second;
688 
689  // Recalculate preferences ...
690  TSvrMap::const_iterator pr_it = server_map.find(cur_server);
691 
692  if (pr_it != server_map.end()) {
693  new_preference += 100 - pr_it->second;
694  } else {
695  new_preference += 100;
696  }
697 
698  // Reset usage map ...
699  usage_map.erase(su_it);
700  usage_map.insert(TServerUsageMap::value_type(new_preference,
701  cur_server));
702 
703  m_LBNameMap[service] = true;
704  return cur_server;
705  }
706 
707  m_LBNameMap[service] = false;
708  return TSvrRef();
709 }
710 
711 void
712 CDBUDPriorityMapper::Exclude(const string& service,
713  const TSvrRef& server)
714 {
715  IDBServiceMapper::Exclude(service, server);
716 
718 
719  TServerUsageMap& usage_map = m_ServiceUsageMap[service];
720 
721  // Remove elements ...
722  for (TServerUsageMap::iterator it = usage_map.begin();
723  it != usage_map.end();) {
724 
725  if (it->second->Matches(*server, service)) {
726  it = usage_map.erase(it);
727  break;
728  }
729  else {
730  ++it;
731  }
732  }
733 }
734 
735 void
737 {
739 
741  m_ServiceUsageMap[service] = m_OrigServiceUsageMap[service];
742 }
743 
744 void
746  const TSvrRef& preferred_server,
747  double preference)
748 {
750 
751  TSvrMap& server_map = m_ServerMap[service];
752  TSvrMap::iterator pr_it = server_map.find(preferred_server);
753 
754  if (preference < 0) {
755  preference = 0;
756  } else if (preference > 100) {
757  preference = 100;
758  }
759 
760  if (pr_it != server_map.end()) {
761  pr_it->second = preference;
762  }
763 }
764 
765 
766 void
768  TOptions* options)
769 {
771  options->clear();
772  auto sit = m_ServerMap.find(service);
773  if (sit == m_ServerMap.end() || sit->second.empty()) {
774  return;
775  }
776  auto uit = m_ServiceUsageMap.find(service);
777  if (uit == m_ServiceUsageMap.end() || uit->second.empty()) {
778  _TROUBLE;
779  return;
780  }
781  map<TSvrRef, double> rankings;
782  auto baseline = uit->second.begin()->first;
783  for (const auto &uit2 : uit->second) {
784  auto sit2 = sit->second.find(uit2.second);
785  _ASSERT(sit2 != sit->second.end());
786  rankings[sit2->first]
787  += exp2(0.1 * (sit2->second + baseline - uit2.first));
788  }
789  for (const auto& sit2 : sit->second) {
790  auto rit = rankings.find(sit2.first);
791  double ranking;
793  if (rit == rankings.end()) {
794  ranking = exp2(0.1 * sit2.second);
796  } else {
797  ranking = rit->second;
798  }
799  // Expiration?
800  options->emplace_back(new CDBServerOption(sit2.first->GetName(),
801  sit2.first->GetHost(),
802  sit2.first->GetPort(),
803  ranking, state));
804  }
805 }
806 
807 
808 void
809 CDBUDPriorityMapper::Add(const string& service,
810  const TSvrRef& server,
811  double preference)
812 {
813  TSvrMap& server_list = m_ServerMap[service];
814  TServerUsageMap& usage_map = m_ServiceUsageMap[service];
815  TServerUsageMap& usage_map2 = m_OrigServiceUsageMap[service];
816 
817  if (preference < 0) {
818  preference = 0;
819  } else if (preference > 100) {
820  preference = 100;
821  }
822 
823  server_list.insert(
824  TSvrMap::value_type(server, preference)
825  );
826  TServerUsageMap::value_type usage(100 - preference, server);
827  usage_map.insert(usage);
828  usage_map2.insert(usage);
829 }
830 
831 
834 {
835  return new CDBUDPriorityMapper(registry);
836 }
837 
838 
839 //////////////////////////////////////////////////////////////////////////////
841  const TMapperConf& ext_mapper)
842 {
843  if (!ext_mapper.first.empty() && ext_mapper.second != NULL) {
844  m_ExtMapperConf = ext_mapper;
845  }
846 
847  this->ConfigureFromRegistry(registry);
849 }
850 
852 {
853 }
854 
855 string CDBUniversalMapper::GetName(void) const
856 {
857  if (Top().NotEmpty()) {
858  return Top()->GetName();
859  } else {
861  }
862 }
863 
864 void
866 {
868 
869  this->ConfigureFromRegistry(registry);
871 }
872 
873 void
875 {
876  vector<string> service_name;
877  const string section_name
879  const string def_mapper_name =
880  (m_ExtMapperConf.second ? m_ExtMapperConf.first :
882 
883  // Get current registry ...
886  }
887 
888  if (registry) {
889 
891  (section_name, "MAPPERS",
892  def_mapper_name),
893  " ,;",
894  service_name,
896 
897  } else {
898  service_name.push_back(def_mapper_name);
899  }
900 
901  ITERATE(vector<string>, it, service_name) {
902  IDBServiceMapper* mapper = NULL;
903  string mapper_name = *it;
904 
906  (mapper_name,
908  0) {
909  mapper = new CDBDefaultServiceMapper();
910  } else if (NStr::CompareNocase
911  (mapper_name,
913  == 0) {
914  mapper = new CDBUDRandomMapper(registry);
915  } else if (NStr::CompareNocase
916  (mapper_name,
918  == 0) {
919  mapper = new CDBUDPriorityMapper(registry);
920  } else if (m_ExtMapperConf.second && NStr::CompareNocase
921  (mapper_name, m_ExtMapperConf.first) == 0) {
922  mapper = (*m_ExtMapperConf.second)(registry);
923  }
924 
925  Push(CRef<IDBServiceMapper>(mapper));
926  }
927 }
928 
929 
930 //////////////////////////////////////////////////////////////////////////////
931 string
933 {
934  return "DEFAULT_NAME_MAPPER";
935 }
936 
937 string
939 {
940  return "COR_NAME_MAPPER";
941 }
942 
943 string
945 {
946  return "USER_DEFINED_RANDOM_DBNAME_MAPPER";
947 }
948 
949 string
951 {
952  return "USER_DEFINED_PRIORITY_DBNAME_MAPPER";
953 }
954 
955 string
957 {
958  return "UNIVERSAL_NAME_MAPPER";
959 }
960 
962 
const char * usage
CDBDefaultServiceMapper.
virtual void SetPreference(const string &service, const TSvrRef &preferred_server, double preference=100.0)
Set up mapping preferences for a service preference - value between 0 and 100 (0 means *no particular...
virtual void Configure(const IRegistry *registry=NULL)
virtual string GetName(void) const
virtual TSvrRef GetServer(const string &service)
Map a service to a server.
virtual ~CDBDefaultServiceMapper(void)
CDBServerOption – CDBServer extended with additional information that helps maintain a balanced pool ...
@ fState_Normal
Fully available.
@ fState_Excluded
Excluded by DBAPI.
IDBServiceMapper.
Uint2 GetPort(void) const
const string & GetName(void) const
Uint4 GetHost(void) const
virtual void Exclude(const string &service, const TSvrRef &server)
Exclude a server from the mapping for a service.
virtual ~CDBServiceMapperCoR(void)
virtual TSvrRef GetServer(const string &service)
Map a service to a server.
virtual void GetServersList(const string &service, list< string > *serv_list) const
Get list of all servers for the given service disregarding any exclusions.
bool Empty(void) const
virtual void Configure(const IRegistry *registry=NULL)
virtual bool RecordServer(I_ConnectionExtra &extra) const
Given a connection that succeeded even though this service mapper was unable to identify a good serve...
virtual bool HasExclusions(const string &service) const
void Push(const CRef< IDBServiceMapper > &mapper)
virtual void GetServerOptions(const string &service, TOptions *options)
Get an annotated list of all servers for the given service.
CRef< IDBServiceMapper > Top(void) const
virtual void SetPreference(const string &service, const TSvrRef &preferred_server, double preference=100.0)
Set up mapping preferences for a service preference - value between 0 and 100 (0 means *no particular...
virtual string GetName(void) const
vector< CRef< IDBServiceMapper > > TDelegates
virtual void CleanExcluded(const string &service)
Clean the list of excluded servers for the given service.
void ConfigureFromRegistry(const IRegistry *registry=NULL)
DBServiceMapperTraits IDBServiceMapper traits.
static string GetName(void)
CDBUDPriorityMapper.
void Add(const string &service, const TSvrRef &server, double preference=0.0)
virtual ~CDBUDPriorityMapper(void)
TServiceUsageMap m_OrigServiceUsageMap
void ConfigureFromRegistry(const IRegistry *registry=NULL)
virtual void CleanExcluded(const string &service)
Clean the list of excluded servers for the given service.
virtual void Exclude(const string &service, const TSvrRef &server)
Exclude a server from the mapping for a service.
virtual void SetPreference(const string &service, const TSvrRef &preferred_server, double preference=100.0)
Set up mapping preferences for a service preference - value between 0 and 100 (0 means *no particular...
CDBUDPriorityMapper(const IRegistry *registry=NULL)
virtual void Configure(const IRegistry *registry=NULL)
virtual TSvrRef GetServer(const string &service)
Map a service to a server.
TServiceUsageMap m_ServiceUsageMap
virtual string GetName(void) const
static IDBServiceMapper * Factory(const IRegistry *registry)
virtual void GetServerOptions(const string &service, TOptions *options)
Get an annotated list of all servers for the given service.
CDBUDRandomMapper.
default_random_engine m_RandomEngine
virtual void CleanExcluded(const string &service)
Clean the list of excluded servers for the given service.
TPreferenceMap m_PreferenceMap
virtual string GetName(void) const
virtual void Configure(const IRegistry *registry=NULL)
static IDBServiceMapper * Factory(const IRegistry *registry)
void ConfigureFromRegistry(const IRegistry *registry=NULL)
void x_RecalculatePreferences(const string &service)
virtual ~CDBUDRandomMapper(void)
virtual void SetPreference(const string &service, const TSvrRef &preferred_server, double preference=100.0)
Set up mapping preferences for a service preference - value between 0 and 100 (0 means *no particular...
TServiceMap m_FavoritesMap
virtual void GetServerOptions(const string &service, TOptions *options)
Get an annotated list of all servers for the given service.
virtual TSvrRef GetServer(const string &service)
Map a service to a server.
void Add(const string &service, const TSvrRef &server, double preference=0.0)
virtual bool HasExclusions(const string &service) const
virtual void Exclude(const string &service, const TSvrRef &server)
Exclude a server from the mapping for a service.
CDBUDRandomMapper(const IRegistry *registry=NULL)
pair< string, TFactory > TMapperConf
virtual string GetName(void) const
CDBUniversalMapper(const IRegistry *registry=nullptr, const TMapperConf &ext_mapper=TMapperConf(kEmptyStr,(TFactory) nullptr))
void ConfigureFromRegistry(const IRegistry *registry=NULL)
virtual void Configure(const IRegistry *registry=NULL)
virtual ~CDBUniversalMapper(void)
static CNcbiApplication * Instance(void)
Singleton method.
Definition: ncbiapp.cpp:264
CTempString implements a light-weight string on top of a storage buffer whose lifetime management is ...
Definition: tempstr.hpp:65
IDBServiceMapper.
virtual void CleanExcluded(const string &service)
Clean the list of excluded servers for the given service.
TExcludeMap m_ExcludeMap
list< CRef< CDBServerOption > > TOptions
virtual string GetName(void) const
virtual void Exclude(const string &service, const TSvrRef &server)
Exclude a server from the mapping for a service.
IRegistry –.
Definition: ncbireg.hpp:73
I_ConnectionExtra.
void erase(iterator pos)
Definition: map.hpp:167
container_type::const_iterator const_iterator
Definition: map.hpp:53
container_type::iterator iterator
Definition: map.hpp:54
const_iterator begin() const
Definition: map.hpp:151
const_iterator end() const
Definition: map.hpp:152
iterator_bool insert(const value_type &val)
Definition: map.hpp:165
bool empty() const
Definition: map.hpp:149
container_type::value_type value_type
Definition: map.hpp:52
void clear()
Definition: map.hpp:169
const_iterator find(const key_type &key) const
Definition: map.hpp:153
Definition: map.hpp:338
void erase(iterator pos)
Definition: map.hpp:307
const_iterator end() const
Definition: map.hpp:292
iterator insert(const value_type &val)
Definition: map.hpp:305
const_iterator begin() const
Definition: map.hpp:291
bool empty() const
Definition: map.hpp:289
static CMemoryRegistry registry
Definition: cn3d_tools.cpp:81
static CRef< CDBServerOption > make_server(const CTempString &specification, double &preference)
#define option
const CNcbiRegistry & GetConfig(void) const
Get the application's cached configuration parameters (read-only).
#define ITERATE(Type, Var, Cont)
ITERATE macro to sequence through container elements.
Definition: ncbimisc.hpp:815
#define NON_CONST_ITERATE(Type, Var, Cont)
Non constant version of ITERATE macro.
Definition: ncbimisc.hpp:822
#define REVERSE_ITERATE(Type, Var, Cont)
ITERATE macro to reverse sequence through container elements.
Definition: ncbimisc.hpp:827
#define NULL
Definition: ncbistd.hpp:225
#define DATABASE_DRIVER_ERROR(message, err_code)
Definition: exception.hpp:740
bool NotNull(void) const THROWS_NONE
Check if pointer is not null – same effect as NotEmpty().
Definition: ncbiobj.hpp:744
bool Empty(void) const THROWS_NONE
Check if CRef is empty – not pointing to any object, which means having a null value.
Definition: ncbiobj.hpp:719
uint32_t Uint4
4-byte (32-bit) unsigned integer
Definition: ncbitype.h:103
uint16_t Uint2
2-byte (16-bit) unsigned integer
Definition: ncbitype.h:101
virtual void EnumerateEntries(const string &section, list< string > *entries, TFlags flags=fAllLayers) const
Enumerate parameter names for a specified section.
Definition: ncbireg.cpp:514
virtual string GetString(const string &section, const string &name, const string &default_value, TFlags flags=0) const
Get the parameter string value.
Definition: ncbireg.cpp:321
#define END_NCBI_SCOPE
End previously defined NCBI scope.
Definition: ncbistl.hpp:103
#define BEGIN_NCBI_SCOPE
Define ncbi namespace.
Definition: ncbistl.hpp:100
static int CompareNocase(const CTempString s1, SIZE_TYPE pos, SIZE_TYPE n, const char *s2)
Case-insensitive compare of a substring with another string.
Definition: ncbistr.cpp:219
static list< string > & Split(const CTempString str, const CTempString delim, list< string > &arr, TSplitFlags flags=0, vector< SIZE_TYPE > *token_pos=NULL)
Split a string using specified delimiters.
Definition: ncbistr.cpp:3461
bool empty(void) const
Return true if the represented string is empty (i.e., the length is zero)
Definition: tempstr.hpp:334
static unsigned int StringToUInt(const CTempString str, TStringToNumFlags flags=0, int base=10)
Convert string to unsigned int.
Definition: ncbistr.cpp:642
CTempString substr(size_type pos) const
Obtain a substring from this string, beginning at a given offset.
Definition: tempstr.hpp:776
size_type find_first_of(const CTempString match, size_type pos=0) const
Find the first occurrence of any character in the matching string within the current string,...
Definition: tempstr.hpp:538
size_type find(const CTempString match, size_type pos=0) const
Find the first instance of the entire matching string within the current string, beginning at an opti...
Definition: tempstr.hpp:655
@ fConvErr_NoThrow
Do not throw an exception on error.
Definition: ncbistr.hpp:285
@ fAllowTrailingSymbols
Ignore trailing non-numerics characters.
Definition: ncbistr.hpp:298
@ fAllowLeadingSpaces
Ignore leading spaces in converted string.
Definition: ncbistr.hpp:294
@ fSplit_MergeDelimiters
Merge adjacent delimiters.
Definition: ncbistr.hpp:2498
n font weight
CRef< CDBServer > TSvrRef
Defines the CNcbiApplication and CAppException classes for creating NCBI applications.
T exp2(T x_)
T max(T x_, T y_)
T min(T x_, T y_)
vector< CRef< CDBServerOption > > servers
unique_ptr< discrete_distribution<> > distribution
#define _TROUBLE
#define _ASSERT
static wxAcceleratorEntry entries[3]
Modified on Sun May 05 05:20:34 2024 by modify_doxy.py rev. 669887