1 #ifndef NCBI_CACHED_TAXON3_HPP 2 #define NCBI_CACHED_TAXON3_HPP 3 4 /* $Id: cached_taxon3.hpp 473749 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 39 #include <objects/taxon3/taxon3__.hpp> 40 #include <objects/taxon3/itaxon3.hpp> 41 #include <objects/seqfeat/seqfeat__.hpp> 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 52 BEGIN_NCBI_SCOPE 53 54 class CObjectOStream; 55 class CConn_ServiceStream; 56 57 58 BEGIN_objects_SCOPE 59 60 class NCBI_TAXON3_EXPORT CCachedTaxon3 : public ITaxon3, 61 protected CCache<string, CRef<CTaxon3_reply> > 62 { 63 64 private: 65 CCachedTaxon3(AutoPtr<ITaxon3> taxon, TSizeType capacity); 66 67 public: ~CCachedTaxon3()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. GetLastError() const98 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 108 ESerialDataFormat m_eDataFormat; 109 const char* m_pchService; 110 STimeout* m_timeout; // NULL, or points to "m_timeout_value" 111 STimeout m_timeout_value; 112 113 unsigned m_nReconnectAttempts; 114 115 string m_sLastError; 116 117 /// The cached taxon does not own the taxon. 118 AutoPtr<ITaxon3> m_taxon; 119 120 void SetLastError(const char* err_msg); 121 122 }; 123 124 125 END_objects_SCOPE 126 END_NCBI_SCOPE 127 128 #endif //NCBI_CACHED_TAXON3_HPP 129