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

Go to the SVN repository for this file.

1 #ifndef NCBI_CACHED_TAXON3_HPP
2 #define NCBI_CACHED_TAXON3_HPP
3 
4 /* $Id: cached_taxon3.hpp 68227 2015-07-22 11:14:39Z holmesbr $
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  * Author: Brad Holmes
30  *
31  * File Description:
32  * Taxon service that caches a parameterized number of replies
33  * for queries by list of org-ref. It *DOES NOT* cache replies
34  * for request objects.
35  *
36  */
37 
38 
42 #include <serial/serialdef.hpp>
43 #include <connect/ncbi_types.h>
44 #include <corelib/ncbi_limits.hpp>
45 #include <util/ncbi_cache.hpp>
46 
47 #include <list>
48 #include <vector>
49 #include <map>
50 
51 
53 
54 class CObjectOStream;
56 
57 
58 BEGIN_objects_SCOPE
59 
61  protected CCache<string, CRef<CTaxon3_reply> >
62 {
63 
64 private:
65  CCachedTaxon3(AutoPtr<ITaxon3> taxon, TSizeType capacity);
66 
67 public:
68  virtual ~CCachedTaxon3() {};
69 
70  typedef string TCacheKey;
71 
72  // The method to create the cache one-off
73  static AutoPtr<CCachedTaxon3> Create(
74  AutoPtr<ITaxon3> taxon, TSizeType capacity = 100000);
75 
76  // This should only be used if it will be
77  // immediately wrapped into a safe pointer
78  static CCachedTaxon3* CreateUnSafe(
79  AutoPtr<ITaxon3> taxon, TSizeType capacity = 100000);
80 
81  //---------------------------------------------
82  // Taxon1 server init
83  // Returns: TRUE - OK
84  // FALSE - Can't open connection to taxonomy service
85  ///
86  virtual void Init(void); // default: 120 sec timeout, 5 reconnect attempts,
87 
88  virtual void Init(const STimeout* timeout, unsigned reconnect_attempts=5);
89 
90  // submit a list of org_refs
91  virtual CRef<CTaxon3_reply> SendOrgRefList(const vector<CRef< COrg_ref> >& list);
92  virtual CRef< CTaxon3_reply > SendRequest(const CTaxon3_request& request);
93 
94  //--------------------------------------------------
95  // Get error message after latest erroneous operation
96  // Returns: error message, or empty string if no error occurred
97  // FIXME: Not implemented properly at this time.
98  virtual const string& GetLastError() const { NCBI_USER_THROW("LastError state is not properly implemented"); return m_sLastError; }
99 
100 
101 private:
102 
103  CRef<CTaxon3_reply> x_AddReplyToCache(const TCacheKey& key, const COrg_ref& org_ref);
104  CRef<CTaxon3_reply> x_GetReplyForOrgRef(const COrg_ref& org_ref);
105 
106 
107 
109  const char* m_pchService;
110  STimeout* m_timeout; // NULL, or points to "m_timeout_value"
112 
114 
115  string m_sLastError;
116 
117  /// The cached taxon does not own the taxon.
119 
120  void SetLastError(const char* err_msg);
121 
122 };
123 
124 
125 END_objects_SCOPE
127 
128 #endif //NCBI_CACHED_TAXON3_HPP
Cache template.
Definition: ncbi_cache.hpp:153
ESerialDataFormat m_eDataFormat
STimeout * m_timeout
virtual const string & GetLastError() const
void SetLastError(const char *err_msg)
STimeout m_timeout_value
const char * m_pchService
unsigned m_nReconnectAttempts
virtual ~CCachedTaxon3()
AutoPtr< ITaxon3 > m_taxon
The cached taxon does not own the taxon.
This stream exchanges data with a named service, in a constraint that the service is implemented as o...
CObjectOStream –.
Definition: objostr.hpp:83
CRef –.
Definition: ncbiobj.hpp:618
CTaxon3_request –.
virtual CRef< CTaxon3_reply > SendRequest(const CTaxon3_request &request)=0
virtual CRef< CTaxon3_reply > SendOrgRefList(const vector< CRef< COrg_ref > > &list, COrg_ref::fOrgref_parts result_parts=COrg_ref::eOrgref_default, fT3reply_parts t3result_parts=eT3reply_default)=0
static void Init(void)
Definition: cursor6.c:76
#define NCBI_USER_THROW(message)
Throw a quick-and-dirty runtime exception of type 'CException' with the given error message and error...
Definition: ncbiexpt.hpp:715
ESerialDataFormat
Data file format.
Definition: serialdef.hpp:71
#define END_NCBI_SCOPE
End previously defined NCBI scope.
Definition: ncbistl.hpp:103
#define BEGIN_NCBI_SCOPE
Define ncbi namespace.
Definition: ncbistl.hpp:100
#define NCBI_TAXON3_EXPORT
Definition: ncbi_export.h:865
const struct ncbi::grid::netcache::search::fields::KEY key
The NCBI C++ generic cache template.
Timeout structure.
Definition: ncbi_types.h:76
Modified on Fri Jun 07 13:33:24 2024 by modify_doxy.py rev. 669887