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

Go to the SVN repository for this file.

1 #ifndef OBJTOOLS__PUBSEQ_GATEWAY__PSG_CLIENT_HPP
2 #define OBJTOOLS__PUBSEQ_GATEWAY__PSG_CLIENT_HPP
3 
4 /* $Id: psg_client.hpp 101412 2023-12-11 18:11:04Z sadyrovr $
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: Denis Vakatov (design), Rafael Sadyrov (implementation)
30  *
31  */
32 
33 #include <corelib/ncbimisc.hpp>
34 #include <corelib/ncbitime.hpp>
35 #include <corelib/ncbi_url.hpp>
36 #include <corelib/request_ctx.hpp>
39 #include <objects/seq/Seq_inst.hpp>
44 
45 #include <optional>
46 #include <unordered_map>
47 
48 
49 #if defined(NCBI_THREADS) && defined(HAVE_LIBNGHTTP2) && defined(HAVE_LIBUV)
50 # define HAVE_PSG_CLIENT 1
51 #endif
52 
53 
54 #if defined(HAVE_PSG_CLIENT)
56 
57 
58 
59 class CPSG_Exception : public CException
60 {
61 public:
62  enum EErrCode {
67  };
68 
69  virtual const char* GetErrCodeString(void) const override;
70 
72 };
73 
74 
75 
76 /// Arbitrary request URL arguments
77 ///
78 struct SPSG_UserArgs : unordered_map<string, set<string>>
79 {
80  /// Allows regular construction.
81  /// @code
82  /// SPSG_UserArgs args{{ "param1", { "value1", "value2" }}, { "param2", { "value3" }}};
83  /// @endcode
84  using unordered_map<string, set<string>>::unordered_map;
85 
86  /// Allow construction from a CUrlArgs instance or using CUrlArgs parsing.
87  /// @code
88  /// SPSG_UserArgs args("param1=value1&param1=value2&param2=value3");
89  /// @endcode
90  SPSG_UserArgs(const CUrlArgs& url_args);
92 };
93 
94 
95 
96 /// Request to the PSG server (see "CPSG_Request_*" below)
97 ///
98 
100 {
101 public:
102  enum EType {
109  };
110 
111  enum EFlags {
112  fExcludeHUP = (0 << 0),
113  fIncludeHUP = (1 << 0),
115  };
118 
119  /// Get the user-provided context
120  template<typename TUserContext>
121  shared_ptr<TUserContext> GetUserContext() const
122  { return static_pointer_cast<TUserContext>(m_UserContext); }
123 
124  /// Get request context
126 
127  /// Set request context
128  void SetRequestContext(CRef<CRequestContext> request_context);
129 
130  /// Get request type
131  EType GetType() const { return x_GetType(); }
132 
133  // Get request ID
134  string GetId() const { return x_GetId(); }
135 
136  /// Set flags
137  void SetFlags(TOptionalFlags flags) { m_Flags = std::move(flags); }
138 
139  /// Set arbitrary URL arguments to add to this request.
140  /// @code
141  /// request->SetUserArgs("param1=value1&param1=value2&param2=value3");
142  /// request->SetUserArgs({{ "param1", { "value1", "value2" }}, { "param2", { "value3" }}});
143  /// @endcode
144  void SetUserArgs(SPSG_UserArgs user_args) { m_UserArgs = std::move(user_args); }
145 
146 protected:
147  template <class T> T GetCtx(T c) { return c ? c : CDiagContext::GetRequestContext().Clone(); }
148 
149  CPSG_Request(shared_ptr<void> user_context = {},
150  CRef<CRequestContext> request_context = {})
151  : m_UserContext(user_context),
152  m_RequestContext(GetCtx(std::move(request_context)))
153  {}
154 
155  virtual ~CPSG_Request() = default;
156 
157 private:
158  virtual EType x_GetType() const = 0;
159  virtual string x_GetId() const = 0;
160  virtual void x_GetAbsPathRef(ostream&) const = 0;
161 
162  shared_ptr<void> m_UserContext;
166 
167  friend class CPSG_Queue;
168 };
169 
170 
171 
172 /// Bio-id (such as accession)
173 ///
175 {
176 public:
177  using CSeq_id = objects::CSeq_id;
179 
180  /// @param id
181  /// Bio ID (like accession)
182  CPSG_BioId(string id, TType type = {}) : m_Id(std::move(id)), m_Type(type) {}
183 
184  /// @param seq_id
185  /// Seq ID
186  CPSG_BioId(const CSeq_id& seq_id) : m_Type(seq_id.Which()) { seq_id.GetLabel(&m_Id, CSeq_id::eFastaContent); }
187 
188  /// @param seq_id_handle
189  /// Seq ID handle
190  CPSG_BioId(const objects::CSeq_id_Handle& seq_id_handle) : CPSG_BioId(*seq_id_handle.GetSeqId()) {}
191 
192  /// Get tilde-separated string representation of this bio ID (e.g. for logging)
193  string Repr() const;
194 
195  /// Get ID
196  const string& GetId() const { return m_Id; }
197 
198  /// Get type
199  TType GetType() const { return m_Type; }
200 
201 private:
202  string m_Id;
204 };
205 
206 using CPSG_BioIds = vector<CPSG_BioId>;
207 
208 
209 
210 /// Blob data unique ID
211 ///
213 {
214 public:
215  virtual ~CPSG_DataId() = default;
216 
217  /// Get tilde-separated string representation of this data ID (e.g. for logging)
218  virtual string Repr() const = 0;
219 };
220 
221 
222 
223 /// Blob unique ID
224 ///
225 class CPSG_BlobId : public CPSG_DataId
226 {
227 public:
229 
230  /// Mainstream blob ID ctor - from a string ID
231  /// @param id
232  /// Blob ID
233  CPSG_BlobId(string id, TLastModified last_modified = {})
234  : m_Id(std::move(id)),
235  m_LastModified(std::move(last_modified))
236  {}
237 
238  /// Historical blob ID system -- based on the "satellite" and the "key"
239  /// inside it. It'll be translated into "<sat>.<sat_key>" string.
240  /// @sa objects::CID2_Blob_Id::TSat, objects::CID2_Blob_Id::TSat_key
241  CPSG_BlobId(int sat, int sat_key, TLastModified last_modified = {})
242  : m_Id(to_string(sat) + "." + to_string(sat_key)),
243  m_LastModified(std::move(last_modified))
244  {}
245 
246  /// Get tilde-separated string representation of this blob ID (e.g. for logging)
247  string Repr() const override;
248 
249  /// Get ID
250  const string& GetId() const { return m_Id; }
251 
252  /// Get last modified
253  const TLastModified& GetLastModified() const { return m_LastModified; }
254 
255 private:
256  string m_Id;
258 };
259 
260 
261 
262 /// Chunk unique ID
263 ///
264 class CPSG_ChunkId : public CPSG_DataId
265 {
266 public:
267  CPSG_ChunkId(int id2_chunk, string id2_info)
268  : m_Id2Chunk(id2_chunk),
269  m_Id2Info(std::move(id2_info))
270  {}
271 
272  /// Get tilde-separated string representation of this chunk ID (e.g. for logging)
273  string Repr() const override;
274 
275  /// Get ID2 chunk number
276  int GetId2Chunk() const { return m_Id2Chunk; }
277 
278  /// Get ID2 info
279  const string& GetId2Info() const { return m_Id2Info; }
280 
281 private:
283  string m_Id2Info;
284 };
285 
286 
287 
288 /// Whether and how to substitute version-less primary seq-ids with
289 /// the "more unique" secondary seq-ids
291  Default, ///< Substitute always (default)
292  Limited, ///< Substitute only if the resolved record's seq_id_type is GI(12)
293  Never ///< No substitution whatsoever - return exact raw accession info
294 };
295 
296 
297 
298 /// Whether to try to resolve provided seq-ids before use
300  Resolve, ///< Try to resolve provided seq-ids
301  NoResolve, ///< Use provided seq-ids as is
302 };
303 
304 
305 
306 /// Request to the PSG server (by bio-id, for a biodata specific info and data)
307 ///
308 
310 {
311 public:
312  /// @param bio_id
313  /// ID of the bioseq
314  /// @param bio_id_resolution
315  /// Whether to try to resolve using provided ID (or use it as-is)
317  EPSG_BioIdResolution bio_id_resolution,
318  shared_ptr<void> user_context = {},
319  CRef<CRequestContext> request_context = {})
320  : CPSG_Request(std::move(user_context), std::move(request_context)),
321  m_BioId(std::move(bio_id)),
322  m_BioIdResolution(bio_id_resolution)
323  {}
324 
326  shared_ptr<void> user_context = {},
327  CRef<CRequestContext> request_context = {})
328  : CPSG_Request_Biodata(std::move(bio_id), EPSG_BioIdResolution::Resolve, std::move(user_context), std::move(request_context))
329  {}
330 
331  const CPSG_BioId& GetBioId() const { return m_BioId; }
333 
334  /// Specify which info and data is needed
336  /// Server default
338 
339  /// Only the info
341 
342  /// If ID2 split is available, return split info blob only.
343  /// Otherwise, return no data.
345 
346  /// If ID2 split is available, return split info blob only.
347  /// Otherwise, return all Cassandra data chunks of the blob itself.
349 
350  /// If ID2 split is available, return all split blobs.
351  /// Otherwise, return all Cassandra data chunks of the blob itself.
353 
354  /// Return all Cassandra data chunks of the blob itself.
355  eOrigTSE
356  };
357  void IncludeData(EIncludeData include) { m_IncludeData = include; }
358 
360 
361  using TExcludeTSEs = vector<CPSG_BlobId>;
362 
363  void ExcludeTSE(CPSG_BlobId blob_id) { m_ExcludeTSEs.emplace_back(std::move(blob_id)); }
364 
365  const TExcludeTSEs& GetExcludeTSEs() const { return m_ExcludeTSEs; }
366 
367  /// Set substitution policy for version-less primary seq-ids
368  void SetAccSubstitution(EPSG_AccSubstitution acc_substitution) { m_AccSubstitution = acc_substitution; }
369 
370  /// Set resend timeout
371  void SetResendTimeout(CTimeout resend_timeout) { m_ResendTimeout = std::move(resend_timeout); }
372 
373 private:
374  EType x_GetType() const override { return eBiodata; }
375  string x_GetId() const override { return GetBioId().Repr(); }
376  void x_GetAbsPathRef(ostream&) const override;
377 
384 };
385 
386 
387 
388 /// Request to the PSG server (by bio-id, for a biodata specific info and data)
389 ///
390 
392 {
393 public:
394  /// @param bio_id
395  /// ID of the bioseq
396  /// @param bio_id_resolution
397  /// Whether to try to resolve using provided ID (or use it as-is)
399  EPSG_BioIdResolution bio_id_resolution,
400  shared_ptr<void> user_context = {},
401  CRef<CRequestContext> request_context = {})
402  : CPSG_Request(std::move(user_context), std::move(request_context)),
403  m_BioId(std::move(bio_id)),
404  m_BioIdResolution(bio_id_resolution)
405  {}
406 
408  shared_ptr<void> user_context = {},
409  CRef<CRequestContext> request_context = {})
410  : CPSG_Request_Resolve(std::move(bio_id), EPSG_BioIdResolution::Resolve, std::move(user_context), std::move(request_context))
411  {}
412 
413  const CPSG_BioId& GetBioId() const { return m_BioId; }
415 
416  /// Specify which info and data is needed
417  /// Some processors may provide more than the flags prescribe
418  /// Always check if corresponding data is actually available using CPSG_BioseqInfo::IncludedInfo()
419  /// @sa CPSG_BioseqInfo::IncludedInfo()
420  enum EIncludeInfo : unsigned {
421  // These flags correspond exactly to the CPSG_BioseqInfo's getters
422  fCanonicalId = (1 << 1),
423  fName = (1 << 2), ///< Requests name to use for canonical bio-id
424  fOtherIds = (1 << 3),
425  fMoleculeType = (1 << 4),
426  fLength = (1 << 5),
427  fChainState = (1 << 6),
428  fState = (1 << 7),
429  fBlobId = (1 << 8),
430  fTaxId = (1 << 9),
431  fHash = (1 << 10),
432  fDateChanged = (1 << 11),
433  fGi = (1 << 12),
435  };
437  void IncludeInfo(TIncludeInfo include) { m_IncludeInfo = include; }
438 
439  TIncludeInfo GetIncludeInfo() const { return m_IncludeInfo; }
440 
441  /// Set substitution policy for version-less primary seq-ids
442  void SetAccSubstitution(EPSG_AccSubstitution acc_substitution) { m_AccSubstitution = acc_substitution; }
443 
444 private:
445  EType x_GetType() const override { return eResolve; }
446  string x_GetId() const override { return GetBioId().Repr(); }
447  void x_GetAbsPathRef(ostream&) const override;
448 
451  TIncludeInfo m_IncludeInfo = TIncludeInfo(0);
453 };
454 
455 
456 
457 /// Request to the PSG server (by blob-id, for a particular blob of data)
458 ///
459 
461 {
462 public:
463  ///
465  shared_ptr<void> user_context = {},
466  CRef<CRequestContext> request_context = {})
467  : CPSG_Request(std::move(user_context), std::move(request_context)),
468  m_BlobId(std::move(blob_id))
469  {}
470 
471  const CPSG_BlobId& GetBlobId() const { return m_BlobId; }
472 
473  /// Specify which data is needed (info is always returned)
475  void IncludeData(EIncludeData include) { m_IncludeData = include; }
476 
478 
479 private:
480  EType x_GetType() const override { return eBlob; }
481  string x_GetId() const override { return GetBlobId().Repr(); }
482  void x_GetAbsPathRef(ostream&) const override;
483 
486 };
487 
488 
489 
490 /// Request meta-information for the named annotations which are defined on the
491 /// bioseq
492 ///
493 
495 {
496 public:
497  /// Names of the named annotations
498  using TAnnotNames = vector<string>;
499 
500  /// @param bio_ids
501  /// IDs (aliases) of the bioseq
502  /// @param annot_names
503  /// List of NAs for which to request the metainfo
504  /// @param bio_id_resolution
505  /// Whether to try to resolve using provided IDs (or use them as-is)
507  TAnnotNames annot_names,
508  EPSG_BioIdResolution bio_id_resolution,
509  shared_ptr<void> user_context = {},
510  CRef<CRequestContext> request_context = {})
511  : CPSG_Request(std::move(user_context), std::move(request_context)),
512  m_BioIds(std::move(bio_ids)),
513  m_AnnotNames(std::move(annot_names)),
514  m_BioIdResolution(bio_id_resolution)
515  {
516  if (m_BioIds.empty()) {
517  NCBI_THROW(CPSG_Exception, eParameterMissing, "bio_ids cannot be empty");
518  }
519  }
520 
522  TAnnotNames annot_names,
523  shared_ptr<void> user_context = {},
524  CRef<CRequestContext> request_context = {})
525  : CPSG_Request_NamedAnnotInfo(std::move(bio_ids), std::move(annot_names), EPSG_BioIdResolution::Resolve, std::move(user_context), std::move(request_context))
526  {}
527 
528  /// @param bio_id
529  /// ID of the bioseq
530  template <class... TArgs>
531  CPSG_Request_NamedAnnotInfo(CPSG_BioId bio_id, TArgs&&... args)
532  : CPSG_Request_NamedAnnotInfo(CPSG_BioIds{bio_id}, std::forward<TArgs>(args)...)
533  {}
534 
535  const CPSG_BioId& GetBioId() const { return m_BioIds.front(); }
536  const CPSG_BioIds& GetBioIds() const { return m_BioIds; }
537  const TAnnotNames& GetAnnotNames() const { return m_AnnotNames; }
539 
540  /// Set substitution policy for version-less primary seq-ids
541  void SetAccSubstitution(EPSG_AccSubstitution acc_substitution) { m_AccSubstitution = acc_substitution; }
542 
543  /// Specify which data is needed (info is always returned)
545  void IncludeData(EIncludeData include) { m_IncludeData = include; }
546 
548 
549  /// Scale-limit parameter for SNP annotations
550  using ESNPScaleLimit = objects::CSeq_id::ESNPScaleLimit;
551  void SetSNPScaleLimit(ESNPScaleLimit snp_scale_limit) { m_SNPScaleLimit = snp_scale_limit; }
553 
554 private:
555  EType x_GetType() const override { return eNamedAnnotInfo; }
556  string x_GetId() const override { return GetBioId().Repr(); }
557  void x_GetAbsPathRef(ostream&) const override;
558 
564  ESNPScaleLimit m_SNPScaleLimit = ESNPScaleLimit::eSNPScaleLimit_Default;
565 };
566 
567 
568 
569 /// Request blob data chunk
570 ///
571 
573 {
574 public:
576  shared_ptr<void> user_context = {},
577  CRef<CRequestContext> request_context = {})
578  : CPSG_Request(std::move(user_context), std::move(request_context)),
579  m_ChunkId(std::move(chunk_id))
580  {}
581 
582  const CPSG_ChunkId& GetChunkId() const { return m_ChunkId; }
583 
584 private:
585  EType x_GetType() const override { return eChunk; }
586  string x_GetId() const override { return GetChunkId().Repr(); }
587  void x_GetAbsPathRef(ostream&) const override;
588 
590 };
591 
592 
593 
594 /// Request IPG resolve
595 ///
596 
598 {
599 public:
601 
602  CPSG_Request_IpgResolve(string protein,
603  Int8 ipg = {},
604  TNucleotide nucleotide = {},
605  shared_ptr<void> user_context = {},
606  CRef<CRequestContext> request_context = {});
607 
608  const string& GetProtein() const { return m_Protein; }
609  Int8 GetIpg() const { return m_Ipg; }
610  const TNucleotide& GetNucleotide() const { return m_Nucleotide; }
611 
612 private:
613  EType x_GetType() const override { return eIpgResolve; }
614  string x_GetId() const override;
615  void x_GetAbsPathRef(ostream&) const override;
616 
617  string m_Protein;
620 };
621 
622 
623 
624 /// Retrieval result
625 /// @sa GetStatus
626 enum class EPSG_Status {
627  eSuccess, ///< Successfully retrieved
628  eInProgress, ///< Retrieval is not finalized yet, more info may come
629  eNotFound, ///< Not found
630  eCanceled, ///< Request canceled
631  eForbidden, ///< User is not authorized for the retrieval
632 
633  /// An error was encountered while trying to send request or to read
634  /// and to process the reply.
635  /// If PSG server sends a message with severity:
636  /// - Error, Critical or Fatal -- this status will be set, and any data
637  /// data in the reply item must be considered invalid; such messages
638  /// will also be logged by the client API with severity Error.
639  /// - Trace, Info or Warning -- are considered to be informational, so
640  /// these do NOT affect the status; such messages however will still
641  /// be logged by the client API with the same (T, I or W) severity.
642  eError
643 };
644 
645 
646 
648 {
650  optional<int> code;
651  explicit operator bool() const { return !empty(); }
652 };
653 
654 
655 
656 class CPSG_Reply;
657 
658 
659 
660 /// A self-containing part of the reply, e.g. a meta-data or a data blob.
661 
663 {
664 public:
665  enum EType {
675  eEndOfReply, ///< No more items expected in the (overall!) reply
676  };
677 
678  EType GetType() const { return m_Type; }
679 
680  /// Get the final result of this blob's retrieval.
681  /// If the blob retrieval is not finalized by the deadline, then
682  /// "eInProgress" is returned.
683  EPSG_Status GetStatus(CDeadline deadline) const;
684 
685  /// Unstructured text containing auxiliary info about the result --
686  /// such as messages and errors that came from the PSG server or occured
687  /// while trying to send request or to read and to process the reply.
688  /// @param min_severity
689  /// Minimum severity level of messages to be retrieved.
690  SPSG_Message GetNextMessage(EDiagSev min_severity = eDiag_Error) const;
691 
692  /// Get the reply that contains this item
693  shared_ptr<CPSG_Reply> GetReply() const { return m_Reply; }
694 
695  /// Get processor ID
696  const string& GetProcessorId() { return m_ProcessorId; }
697 
698  virtual ~CPSG_ReplyItem();
699 
700 protected:
702 
703 private:
704  struct SImpl;
705  unique_ptr<SImpl> m_Impl;
706  shared_ptr<CPSG_Reply> m_Reply;
707  const EType m_Type;
709 
710  friend class CPSG_Reply;
711 };
712 
713 
714 
715 /// Blob data.
716 
718 {
719 public:
720  /// Get data ID
721  template <class TDataId = CPSG_DataId>
722  const TDataId* GetId() const { return dynamic_cast<const TDataId*>(m_Id.get()); }
723 
724  /// Get the stream from which to read the item's content.
725  /// @note If no content, then reading from the stream will result in EOF.
726  istream& GetStream() const { return *m_Stream; }
727 
728 private:
729  CPSG_BlobData(unique_ptr<CPSG_DataId> id);
730 
731  unique_ptr<CPSG_DataId> m_Id;
732  unique_ptr<istream> m_Stream;
733 
734  friend class CPSG_Reply;
735 };
736 
737 
738 
739 /// Blob data meta information
740 
742 {
743 public:
744  /// Get data ID
745  template <class TDataId = CPSG_DataId>
746  const TDataId* GetId() const { return dynamic_cast<const TDataId*>(m_Id.get()); }
747 
748  /// Get data compression algorithm: gzip, bzip2, zip, compress, nlmzip, ...
749  /// Return empty string if the blob data is not compressed
750  string GetCompression() const;
751 
752  /// Get data serialization format: asn.1, asn1-text, json, xml, ...
753  string GetFormat() const;
754 
755  /// Get size of the blob data (as it is stored)
756  Uint8 GetStorageSize() const;
757 
758  /// Get size of the real (before any compression or encryption) blob data
759  Uint8 GetSize() const;
760 
761  /// Return TRUE if the blob data is "dead"
762  bool IsDead() const;
763 
764  /// Return TRUE if the blob data is "suppressed"
765  bool IsSuppressed() const;
766 
767  /// Return TRUE if the blob data is "withdrawn"
768  bool IsWithdrawn() const;
769 
770  /// Date when the blob data will be released for public use.
771  /// If the blob data is already released, then return "empty" (IsEmpty()) time
772  CTime GetHupReleaseDate() const;
773 
774  /// Blob data owner's ID
775  Uint8 GetOwner() const;
776 
777  /// Date when the blob data was first loaded into the database
778  CTime GetOriginalLoadDate() const;
779 
780  /// Class of this blob data
781  objects::CBioseq_set::EClass GetClass() const;
782 
783  /// Internal division value (used by various dumpers)
784  string GetDivision() const;
785 
786  /// Name of the user who loaded this blob data
787  string GetUsername() const;
788 
789  /// Get ID2 info
790  string GetId2Info() const;
791 
792  /// Get number of Cassandra data chunks that constitute this blob data.
793  Uint8 GetNChunks() const;
794 
795 private:
796  CPSG_BlobInfo(unique_ptr<CPSG_DataId> id);
797 
798  unique_ptr<CPSG_DataId> m_Id;
800 
801  friend class CPSG_Reply;
802 };
803 
804 
805 
806 /// Skipped blob.
807 
809 {
810 public:
812 
813  enum EReason {
814  eExcluded, // Explicitly excluded by the client
815  eInProgress, // Is being sent to the client
816  eSent, // Already sent to the client
817  eUnknown, // Skipped for unknown reason
818  };
819 
820  /// Get data ID
821  template <class TDataId = CPSG_DataId>
822  const TDataId* GetId() const { return dynamic_cast<const TDataId*>(m_Id.get()); }
823 
824  // Get reason for blob skipping
825  EReason GetReason() const { return m_Reason; }
826 
827  /// Seconds passed since the blob was last sent to the client.
828  const TSeconds& GetSentSecondsAgo() const { return m_SentSecondsAgo; }
829 
830  /// Seconds before the blob will be sent to the client.
831  const TSeconds& GetTimeUntilResend() const { return m_TimeUntilResend; }
832 
833 private:
834  CPSG_SkippedBlob(unique_ptr<CPSG_DataId> id, EReason reason, TSeconds sent_seconds_ago, TSeconds time_until_resend);
835 
836  unique_ptr<CPSG_DataId> m_Id;
840 
841  friend class CPSG_Reply;
842 };
843 
844 
845 
846 /// Bio-sequence metainfo -- result of the bio-id resolution.
847 ///
848 /// It can be used to identify which data blobs (related to the requested
849 /// bio-id retrieval) server is sending right away. It also contains
850 /// resolution information as well as the information about which
851 /// other biodata-related blobs are also available on the server and how
852 /// they can be explicitly requested for later retrieval, if needed.
853 ///
854 /// @note
855 /// Most of the data comes from table "BIOSEQ_INFO" and from the named
856 /// annotation tables.
857 
859 {
860 public:
861  /// Get canonical bio-id for the bioseq (usually "accession.version")
862  CPSG_BioId GetCanonicalId() const;
863 
864  /// Get non-canonical bio-ids (aliases) for the bioseq
865  CPSG_BioIds GetOtherIds() const;
866 
867  /// The bioseq's molecule type (DNA, RNA, protein, etc)
868  objects::CSeq_inst::TMol GetMoleculeType() const;
869 
870  /// Length of bio-sequence
871  Uint8 GetLength() const;
872 
873  /// State of the bio-sequence's seq-id
874  enum EState {
875  eDead = 0,
876  eSought = 1,
878  eMerged = 7,
879  eLive = 10
880  };
881  typedef int TState; ///< @sa EState
882 
883  /// State of the bio-sequence's seq-id chain, i.e. the state of the very
884  /// latest seq-id in this bio-sequence's seq-id chain
885  TState GetChainState() const;
886 
887  /// State of this exact bio-sequence's seq-id.
888  /// I.e., for the latest seq-id in a chain it is equal to GetState(), and
889  /// for all other seq-ids in a chain it's zero (eDead).
890  TState GetState() const;
891 
892  /// Get coordinates of the TSE blob that contains the bioseq itself
893  CPSG_BlobId GetBlobId() const;
894 
895  /// Get the bioseq's taxonomy ID
896  TTaxId GetTaxId() const;
897 
898  /// Get the bioseq's (pre-calculated) hash
899  int GetHash() const;
900 
901  /// Date when the bioseq was changed last time
902  CTime GetDateChanged() const;
903 
904  /// Get GI
905  TGi GetGi() const;
906 
907  /// What data is immediately available now. Other data will require
908  /// a separate hit to the server.
909  /// @sa CPSG_Request_Resolve::IncludeInfo()
910  CPSG_Request_Resolve::TIncludeInfo IncludedInfo() const;
911 
912 private:
913  CPSG_BioseqInfo();
914 
916 
917  friend class CPSG_Reply;
918 };
919 
920 
921 
922 /// Named Annotations (NAs) metainfo -- reply to CPSG_Request_NamedAnnotInfo.
923 ///
924 /// It can be used to identify where various types of requested NAs are located
925 /// on the bioseq. It also provides information how to retrieve the
926 /// corresponding NA data blobs (as needed).
927 
929 {
930 public:
931  /// Name of the annotation
932  const string& GetName() const { return m_Name; }
933 
934  /// Coordinates of the blob that contains the NA data
935  CPSG_BlobId GetBlobId() const;
936 
937  /// Base64 encoded asn.1 of ID2-Seq-annot-Info
938  string GetId2AnnotInfo() const;
939 
940  /// Detailed ID2-Seq-annot-Info structures (from GetId2AnnotInfo, decoded)
941  /// @sa GetId2AnnotInfo
942  /// @{
943  using TId2AnnotInfo = objects::CID2S_Seq_annot_Info;
944  using TId2AnnotInfoList = list<CRef<TId2AnnotInfo>>;
946  /// @}
947 
948 private:
949  CPSG_NamedAnnotInfo(string name);
950 
951  string m_Name;
953 
954  friend class CPSG_Reply;
955 };
956 
957 
958 
959 /// Named Annotations (NAs) status -- reply to CPSG_Request_NamedAnnotInfo.
960 ///
961 
963 {
964 public:
965  /// Individual NA statuses
966  using TId2AnnotStatus = pair<string, EPSG_Status>;
967  using TId2AnnotStatusList = list<TId2AnnotStatus>;
969 
970 private:
972 
974 
975  friend class CPSG_Reply;
976 };
977 
978 
979 
980 /// Public comment
981 
983 {
984 public:
985  /// Get data ID for this public comment
986  template <class TDataId = CPSG_DataId>
987  const TDataId* GetId() const { return dynamic_cast<const TDataId*>(m_Id.get()); }
988 
989  /// Get text
990  const string& GetText() const { return m_Text; }
991 
992 private:
993  CPSG_PublicComment(unique_ptr<CPSG_DataId> id, string text);
994 
995  unique_ptr<CPSG_DataId> m_Id;
996  string m_Text;
997 
998  friend class CPSG_Reply;
999 };
1000 
1001 
1002 
1003 /// Processor event
1004 
1006 {
1007 public:
1018  };
1019 
1020  /// Get progress status
1022 
1023 private:
1024  CPSG_Processor(EProgressStatus progress_status);
1025 
1027 
1028  friend class CPSG_Reply;
1029 };
1030 
1031 
1032 
1033 /// Ipg info -- result of the IPG resolution.
1034 
1036 {
1037 public:
1038  /// Get protein
1039  string GetProtein() const;
1040 
1041  /// Get Ipg
1042  Int8 GetIpg() const;
1043 
1044  /// Get nucleotide
1045  string GetNucleotide() const;
1046 
1047  /// Get taxonomy ID
1048  TTaxId GetTaxId() const;
1049 
1050  typedef int TState;
1051 
1052  /// Get state
1053  TState GetGbState() const;
1054 
1055 private:
1056  CPSG_IpgInfo();
1057 
1059 
1060  friend class CPSG_Reply;
1061 };
1062 
1063 
1064 
1065 /// PSG reply -- corresponds to a PSG request. It is used to retrieve data
1066 /// (accession resolution; bio-sequence; annotation blobs) from the storage.
1067 ///
1068 /// Reply may contain:
1069 /// - Reply items (CPSG_ReplyItem), each of which in turn may contain
1070 /// item-specific info and/or data blob
1071 /// - Server messages related to the whole reply
1072 ///
1073 
1075 {
1076 public:
1077  /// Get the final result of this whole reply's retrieval.
1078  /// If the reply retrieval is not finalized by the deadline, then
1079  /// "eInProgress" is returned.
1080  EPSG_Status GetStatus(CDeadline deadline) const;
1081 
1082  /// Unstructured text containing auxiliary info about the result --
1083  /// such as messages and errors that came from the PSG server or occured
1084  /// while trying to send request or to read and to process the reply.
1085  /// @param min_severity
1086  /// Minimum severity level of messages to be retrieved.
1087  SPSG_Message GetNextMessage(EDiagSev min_severity = eDiag_Error) const;
1088 
1089  /// Get the request that resulted in this reply
1090  shared_ptr<const CPSG_Request> GetRequest() const { return m_Request; }
1091 
1092  /// Get the next item which has started arriving from the server.
1093  /// @note
1094  /// Some of the item's data may still be in transit or not even sent
1095  /// in by the server yet.
1096  /// @param deadline
1097  /// Until what time to wait for the next item to start coming in.
1098  /// @return
1099  /// - The item objects from which you can start reading data
1100  /// - If no more items expected in the reply, the returned item will have
1101  /// type eEndOfReply
1102  /// - On expired timeout, the returned pointer will be empty (nullptr)
1103  /// @throw
1104  /// If an error has been detected.
1105  shared_ptr<CPSG_ReplyItem> GetNextItem(CDeadline deadline);
1106 
1107  ~CPSG_Reply();
1108 
1109 private:
1110  CPSG_Reply();
1111 
1112  struct SImpl;
1113  unique_ptr<SImpl> m_Impl;
1114  shared_ptr<const CPSG_Request> m_Request;
1115 
1116  friend class CPSG_Queue;
1117 };
1118 
1119 
1120 
1121 /// A queue to retrieve data (accession resolution info; bio-sequence;
1122 /// annotation blobs) from the storage.
1123 ///
1124 /// Call SendRequest() to schedule retrievals (by their bio-ids or
1125 /// blob-ids). Then, call GetNextReply() to get the next reply whose data
1126 /// has started coming in.
1127 ///
1128 /// All methods are MT-safe. Data from different replies can be read in
1129 /// parallel.
1130 ///
1131 /// The queue object can be used from more than one thread, either to push
1132 /// requests or to get the incoming ready-to-be-retrieved replies.
1133 ///
1134 /// Results for the requests which were pushed into a given instance of
1135 /// the queue will be available for retrieval using this (and only this) queue
1136 /// instance regardless of which threads were used to push the request to the
1137 /// queue.
1138 ///
1139 /// If more than one request was pushed into the queue, then the replies to all
1140 /// of the requests may come, in any order.
1141 ///
1142 
1144 {
1145 public:
1146  /// Creates an uninitialized instance.
1147  /// It allows to postpone queue initialization until later.
1148  /// The uninitialized instances can then be initialized using
1149  /// regular constructor and move assignment operator.
1151 
1152  /// @param service
1153  /// Either a name of service (which can be resolved into a set of PSG
1154  /// servers) or a single fixed PSG server (in format "host:port")
1155  /// or empty value to use one from configuration file/environment/default.
1156  CPSG_Queue(const string& service);
1158 
1159  /// Push request into the queue.
1160  /// @param request
1161  /// The request (containing either bio- or blob-id to retrieve) to send.
1162  /// @param deadline
1163  /// For how long to try to push the request into the queue.
1164  /// @return
1165  /// - TRUE if it succeeds in pushing the request into the queue
1166  /// - FALSE on timeout (ie. if cannot do it before the specified deadline)
1167  /// @throw CPSG_Exception
1168  /// If any (non-timeout) error condition occures.
1169  /// @sa Get()
1170  bool SendRequest(shared_ptr<CPSG_Request> request,
1171  CDeadline deadline);
1172 
1173 
1174  /// Get the next reply which has started arriving from the server.
1175  /// @param deadline
1176  /// Until what time to wait for the next reply to start coming in.
1177  /// @return
1178  /// - Reply object from which you can obtain particular items.
1179  /// - On expired timeout, the returned pointer will be empty (nullptr).
1180  /// @throw
1181  /// If an error has been detected.
1182  shared_ptr<CPSG_Reply> GetNextReply(CDeadline deadline);
1183 
1184 
1185  /// Push request into the queue and get corresponding reply.
1186  /// @param request
1187  /// The request to send.
1188  /// @param deadline
1189  /// For how long to try to push the request into the queue.
1190  /// @return
1191  /// - Reply object from which you can obtain particular items.
1192  /// - On expired timeout, the returned pointer will be empty (nullptr).
1193  /// @throw CPSG_Exception
1194  /// If any (non-timeout) error condition occures.
1195  shared_ptr<CPSG_Reply> SendRequestAndGetReply(shared_ptr<CPSG_Request> request,
1196  CDeadline deadline);
1197 
1198 
1199  /// Wait for events on this queue, on replies returned by this queue and/or
1200  /// on reply items returned by the replies returned by this queue.
1201  /// @param deadline
1202  /// For how long to wait for events in the queue.
1203  bool WaitForEvents(CDeadline deadline);
1204 
1205 
1206  /// Stop accepting new requests.
1207  /// All already accepted requests will be processed as usual.
1208  /// No requests are accepted after the stop.
1209  void Stop();
1210 
1211 
1212  /// Stop accepting new requests and
1213  /// cancel all requests whose replies have not been returned yet.
1214  /// No requests are accepted and no replies are returned after the reset.
1215  void Reset();
1216 
1217 
1218  /// Check whether the queue was stopped/reset and is now empty.
1219  bool IsEmpty() const;
1220 
1221 
1222  /// Check whether the queue has been initialized.
1223  bool IsInitialized() const { return static_cast<bool>(m_Impl); }
1224 
1225 
1226  /// Is the queue in a state (possibly temporary) when requests get immediately rejected.
1227  bool RejectsRequests() const;
1228 
1229 
1230  /// Set request flags
1231  void SetRequestFlags(CPSG_Request::TFlags request_flags);
1232 
1233 
1234  /// Set arbitrary URL arguments to add to every request.
1235  /// @code
1236  /// queue.SetUserArgs("param1=value1&param1=value2&param2=value3");
1237  /// queue.SetUserArgs({{ "param1", { "value1", "value2" }}, { "param2", { "value3" }}});
1238  /// @endcode
1239  void SetUserArgs(SPSG_UserArgs user_args);
1240 
1241 
1242  /// Get an API lock.
1243  /// Holding this API lock is essential if numerous short-lived queue instances are used.
1244  /// It prevents an internal I/O implementation (threads, TCP connections, HTTP sessions, etc)
1245  /// from being destroyed (on destroying last remaining queue instance)
1246  /// and then re-created (with new queue instance).
1247  using TApiLock = shared_ptr<void>;
1248  static TApiLock GetApiLock();
1249 
1250 
1253 
1254 private:
1255  struct SImpl;
1256  unique_ptr<SImpl> m_Impl;
1257 };
1258 
1259 
1260 
1261 /// A class derived from the queue class that additionally allows to run event loop.
1262 ///
1263 /// Call SendRequest() (possibly from other threads) to add requests to the queue.
1264 /// Call RunOnce() to run the event loop once, use IsEmpty() to check
1265 /// if all processing is complete. Or, call Run() to run the event loop until all
1266 /// processing is complete.
1267 ///
1268 /// NOTE: Requests can be added to the queue at any time, including in parallel with
1269 /// calling Run() and RunOnce() methods of the event loop. However, do remember to
1270 /// call Stop() once all required requests have been added to the queue as this will
1271 /// help the event loop to stop promptly, as soon as all submitted requests have
1272 /// been processed.
1273 ///
1274 /// Derived (the event loop) part of the instance is not MT-safe,
1275 /// one event loop cannot be run by multiple threads.
1276 /// Base class methods are MT-safe.
1277 ///
1278 /// The queue base can be used by more than one thread,
1279 /// usually to add requests and stop the queue after.
1280 /// If needed, it can also be used to wait for events and to manually retrieve replies.
1281 /// Manually retrieved replies will not be processed by the event loop though.
1282 ///
1283 /// Results for the requests which were pushed into a given instance
1284 /// will be processed using this (and only this) instance
1285 /// regardless of which threads were used to push the requests.
1286 ///
1287 /// If more than one request was pushed into the instance, then the replies to all
1288 /// of the requests may come, in any order.
1289 ///
1290 
1292 {
1293 public:
1294  using TItemComplete = function<void(EPSG_Status, const shared_ptr<CPSG_ReplyItem>&)>;
1295  using TReplyComplete = function<void(EPSG_Status, const shared_ptr<CPSG_Reply>&)>;
1296  using TNewItem = function<void(const shared_ptr<CPSG_ReplyItem>&)>;
1297 
1298  /// Creates an uninitialized instance.
1299  /// It allows to postpone queue initialization until later.
1300  /// The uninitialized instances can then be initialized using
1301  /// regular constructor and move assignment operator.
1303 
1304  /// @param service
1305  /// Either a name of service (which can be resolved into a set of PSG
1306  /// servers) or a single fixed PSG server (in format "host:port")
1307  /// or empty value to use one from configuration file/environment/default.
1308  /// @param item_complete
1309  /// Mandatory user callback to call when an item is complete (i.e. not eInProgress)
1310  /// @param reply_complete
1311  /// Mandatory user callback to call when a reply and all its items are complete
1312  /// @param new_item
1313  /// Optional user callback to call when new item arrives
1314  CPSG_EventLoop(const string& service,
1315  TItemComplete item_complete,
1316  TReplyComplete reply_complete,
1317  TNewItem new_item = nullptr);
1318 
1319  /// Check whether the queue is empty and all processing is complete
1320  bool IsEmpty() const { return CPSG_Queue::IsEmpty() && m_Replies.empty(); }
1321 
1322  /// Wait once for events in the queue and process any.
1323  /// @param deadline
1324  /// For how long to wait for events in the queue.
1325  /// @return
1326  /// - TRUE if there have been some events
1327  /// - FALSE on timeout (i.e. if there have been no events before the specified deadline)
1328  bool RunOnce(CDeadline deadline);
1329 
1330  /// Process everything in the queue until it's empty or times out.
1331  /// @param deadline
1332  /// For how long to process events in the queue.
1333  /// @return
1334  /// - TRUE if everything has been processed
1335  /// - FALSE on timeout (i.e. if it's still not empty before the specified deadline)
1336  bool Run(CDeadline deadline);
1337 
1340 
1341 private:
1345  list<pair<shared_ptr<CPSG_Reply>, list<shared_ptr<CPSG_ReplyItem>>>> m_Replies;
1346 };
1347 
1348 
1349 
1351 {
1352  m_RequestContext = GetCtx(std::move(request_context));
1353 }
1354 
1355 inline bool CPSG_EventLoop::Run(CDeadline deadline)
1356 {
1357  while (!IsEmpty()) {
1358  if (!RunOnce(deadline)) {
1359  return false;
1360  }
1361  }
1362 
1363  return true;
1364 }
1365 
1366 
1369 
1371 
1372 
1373 #endif /* HAVE_PSG_CLIENT */
1374 #endif /* OBJTOOLS__PUBSEQ_GATEWAY__PSG_CLIENT_HPP */
User-defined methods of the data storage class.
#define bool
Definition: bool.h:34
CDeadline.
Definition: ncbitime.hpp:1830
JSON node abstraction.
Bio-id (such as accession)
Definition: psg_client.hpp:175
TType m_Type
Definition: psg_client.hpp:203
CPSG_BioId(string id, TType type={})
Definition: psg_client.hpp:182
const string & GetId() const
Get ID.
Definition: psg_client.hpp:196
CPSG_BioId(const objects::CSeq_id_Handle &seq_id_handle)
Definition: psg_client.hpp:190
CPSG_BioId(const CSeq_id &seq_id)
Definition: psg_client.hpp:186
string m_Id
Definition: psg_client.hpp:202
TType GetType() const
Get type.
Definition: psg_client.hpp:199
string Repr() const
Get tilde-separated string representation of this bio ID (e.g. for logging)
Definition: psg_client.cpp:190
Bio-sequence metainfo – result of the bio-id resolution.
Definition: psg_client.hpp:859
CPSG_BioId GetCanonicalId() const
Get canonical bio-id for the bioseq (usually "accession.version")
TState GetState() const
State of this exact bio-sequence's seq-id.
TState GetChainState() const
State of the bio-sequence's seq-id chain, i.e.
objects::CSeq_inst::TMol GetMoleculeType() const
The bioseq's molecule type (DNA, RNA, protein, etc)
TGi GetGi() const
Get GI.
CPSG_BioIds GetOtherIds() const
Get non-canonical bio-ids (aliases) for the bioseq.
TTaxId GetTaxId() const
Get the bioseq's taxonomy ID.
CTime GetDateChanged() const
Date when the bioseq was changed last time.
CPSG_Request_Resolve::TIncludeInfo IncludedInfo() const
What data is immediately available now.
Uint8 GetLength() const
Length of bio-sequence.
CJsonNode m_Data
Definition: psg_client.hpp:915
CPSG_BlobId GetBlobId() const
Get coordinates of the TSE blob that contains the bioseq itself.
int GetHash() const
Get the bioseq's (pre-calculated) hash.
Blob data.
Definition: psg_client.hpp:718
unique_ptr< CPSG_DataId > m_Id
Definition: psg_client.hpp:731
unique_ptr< istream > m_Stream
Definition: psg_client.hpp:732
const TDataId * GetId() const
Get data ID.
Definition: psg_client.hpp:722
CPSG_BlobData(unique_ptr< CPSG_DataId > id)
istream & GetStream() const
Get the stream from which to read the item's content.
Definition: psg_client.hpp:726
Blob unique ID.
Definition: psg_client.hpp:226
const string & GetId() const
Get ID.
Definition: psg_client.hpp:250
const TLastModified & GetLastModified() const
Get last modified.
Definition: psg_client.hpp:253
CPSG_BlobId(string id, TLastModified last_modified={})
Mainstream blob ID ctor - from a string ID.
Definition: psg_client.hpp:233
CPSG_BlobId(int sat, int sat_key, TLastModified last_modified={})
Historical blob ID system – based on the "satellite" and the "key" inside it.
Definition: psg_client.hpp:241
TLastModified m_LastModified
Definition: psg_client.hpp:257
string Repr() const override
Get tilde-separated string representation of this blob ID (e.g. for logging)
Definition: psg_client.cpp:214
Blob data meta information.
Definition: psg_client.hpp:742
const TDataId * GetId() const
Get data ID.
Definition: psg_client.hpp:746
bool IsSuppressed() const
Return TRUE if the blob data is "suppressed".
CTime GetOriginalLoadDate() const
Date when the blob data was first loaded into the database.
bool IsWithdrawn() const
Return TRUE if the blob data is "withdrawn".
objects::CBioseq_set::EClass GetClass() const
Class of this blob data.
string GetFormat() const
Get data serialization format: asn.1, asn1-text, json, xml, ...
CTime GetHupReleaseDate() const
Date when the blob data will be released for public use.
string GetDivision() const
Internal division value (used by various dumpers)
CPSG_BlobInfo(unique_ptr< CPSG_DataId > id)
Uint8 GetStorageSize() const
Get size of the blob data (as it is stored)
string GetCompression() const
Get data compression algorithm: gzip, bzip2, zip, compress, nlmzip, ...
unique_ptr< CPSG_DataId > m_Id
Definition: psg_client.hpp:798
bool IsDead() const
Return TRUE if the blob data is "dead".
string GetId2Info() const
Get ID2 info.
CJsonNode m_Data
Definition: psg_client.hpp:799
Uint8 GetSize() const
Get size of the real (before any compression or encryption) blob data.
Uint8 GetNChunks() const
Get number of Cassandra data chunks that constitute this blob data.
Uint8 GetOwner() const
Blob data owner's ID.
string GetUsername() const
Name of the user who loaded this blob data.
Chunk unique ID.
Definition: psg_client.hpp:265
string m_Id2Info
Definition: psg_client.hpp:283
const string & GetId2Info() const
Get ID2 info.
Definition: psg_client.hpp:279
string Repr() const override
Get tilde-separated string representation of this chunk ID (e.g. for logging)
Definition: psg_client.cpp:243
int GetId2Chunk() const
Get ID2 chunk number.
Definition: psg_client.hpp:276
CPSG_ChunkId(int id2_chunk, string id2_info)
Definition: psg_client.hpp:267
Blob data unique ID.
Definition: psg_client.hpp:213
virtual string Repr() const =0
Get tilde-separated string representation of this data ID (e.g. for logging)
virtual ~CPSG_DataId()=default
A class derived from the queue class that additionally allows to run event loop.
bool RunOnce(CDeadline deadline)
Wait once for events in the queue and process any.
bool Run(CDeadline deadline)
Process everything in the queue until it's empty or times out.
CPSG_EventLoop(CPSG_EventLoop &&)
function< void(EPSG_Status, const shared_ptr< CPSG_ReplyItem > &)> TItemComplete
bool IsEmpty() const
Check whether the queue is empty and all processing is complete.
CPSG_EventLoop & operator=(CPSG_EventLoop &&)
CPSG_EventLoop()
Creates an uninitialized instance.
TNewItem m_NewItem
function< void(EPSG_Status, const shared_ptr< CPSG_Reply > &)> TReplyComplete
function< void(const shared_ptr< CPSG_ReplyItem > &)> TNewItem
TReplyComplete m_ReplyComplete
TItemComplete m_ItemComplete
list< pair< shared_ptr< CPSG_Reply >, list< shared_ptr< CPSG_ReplyItem > > > > m_Replies
virtual const char * GetErrCodeString(void) const override
Get error code interpreted as text.
Definition: psg_client.cpp:60
NCBI_EXCEPTION_DEFAULT(CPSG_Exception, CException)
Ipg info – result of the IPG resolution.
string GetNucleotide() const
Get nucleotide.
string GetProtein() const
Get protein.
Int8 GetIpg() const
Get Ipg.
CJsonNode m_Data
TState GetGbState() const
Get state.
TTaxId GetTaxId() const
Get taxonomy ID.
Named Annotations (NAs) metainfo – reply to CPSG_Request_NamedAnnotInfo.
Definition: psg_client.hpp:929
string GetId2AnnotInfo() const
Base64 encoded asn.1 of ID2-Seq-annot-Info.
CPSG_BlobId GetBlobId() const
Coordinates of the blob that contains the NA data.
const string & GetName() const
Name of the annotation.
Definition: psg_client.hpp:932
objects::CID2S_Seq_annot_Info TId2AnnotInfo
Detailed ID2-Seq-annot-Info structures (from GetId2AnnotInfo, decoded)
Definition: psg_client.hpp:943
list< CRef< TId2AnnotInfo > > TId2AnnotInfoList
Definition: psg_client.hpp:944
CPSG_NamedAnnotInfo(string name)
TId2AnnotInfoList GetId2AnnotInfoList() const
Named Annotations (NAs) status – reply to CPSG_Request_NamedAnnotInfo.
Definition: psg_client.hpp:963
list< TId2AnnotStatus > TId2AnnotStatusList
Definition: psg_client.hpp:967
pair< string, EPSG_Status > TId2AnnotStatus
Individual NA statuses.
Definition: psg_client.hpp:966
TId2AnnotStatusList GetId2AnnotStatusList() const
Processor event.
EProgressStatus m_ProgressStatus
EProgressStatus GetProgressStatus() const
Get progress status.
CPSG_Processor(EProgressStatus progress_status)
Public comment.
Definition: psg_client.hpp:983
unique_ptr< CPSG_DataId > m_Id
Definition: psg_client.hpp:995
const TDataId * GetId() const
Get data ID for this public comment.
Definition: psg_client.hpp:987
CPSG_PublicComment(unique_ptr< CPSG_DataId > id, string text)
const string & GetText() const
Get text.
Definition: psg_client.hpp:990
A queue to retrieve data (accession resolution info; bio-sequence; annotation blobs) from the storage...
bool SendRequest(shared_ptr< CPSG_Request > request, CDeadline deadline)
Push request into the queue.
shared_ptr< void > TApiLock
Get an API lock.
CPSG_Queue(CPSG_Queue &&)
unique_ptr< SImpl > m_Impl
bool IsEmpty() const
Check whether the queue was stopped/reset and is now empty.
shared_ptr< CPSG_Reply > GetNextReply(CDeadline deadline)
Get the next reply which has started arriving from the server.
bool WaitForEvents(CDeadline deadline)
Wait for events on this queue, on replies returned by this queue and/or on reply items returned by th...
CPSG_Queue()
Creates an uninitialized instance.
CPSG_Queue & operator=(CPSG_Queue &&)
void SetUserArgs(SPSG_UserArgs user_args)
Set arbitrary URL arguments to add to every request.
void Reset()
Stop accepting new requests and cancel all requests whose replies have not been returned yet.
shared_ptr< CPSG_Reply > SendRequestAndGetReply(shared_ptr< CPSG_Request > request, CDeadline deadline)
Push request into the queue and get corresponding reply.
void Stop()
Stop accepting new requests.
bool IsInitialized() const
Check whether the queue has been initialized.
void SetRequestFlags(CPSG_Request::TFlags request_flags)
Set request flags.
static TApiLock GetApiLock()
bool RejectsRequests() const
Is the queue in a state (possibly temporary) when requests get immediately rejected.
A self-containing part of the reply, e.g. a meta-data or a data blob.
Definition: psg_client.hpp:663
SPSG_Message GetNextMessage(EDiagSev min_severity=eDiag_Error) const
Unstructured text containing auxiliary info about the result – such as messages and errors that came ...
const string & GetProcessorId()
Get processor ID.
Definition: psg_client.hpp:696
shared_ptr< CPSG_Reply > m_Reply
Definition: psg_client.hpp:706
virtual ~CPSG_ReplyItem()
string m_ProcessorId
Definition: psg_client.hpp:708
EPSG_Status GetStatus(CDeadline deadline) const
Get the final result of this blob's retrieval.
EType GetType() const
Definition: psg_client.hpp:678
unique_ptr< SImpl > m_Impl
Definition: psg_client.hpp:704
const EType m_Type
Definition: psg_client.hpp:707
shared_ptr< CPSG_Reply > GetReply() const
Get the reply that contains this item.
Definition: psg_client.hpp:693
CPSG_ReplyItem(EType type)
@ eEndOfReply
No more items expected in the (overall!) reply.
Definition: psg_client.hpp:675
PSG reply – corresponds to a PSG request.
shared_ptr< const CPSG_Request > m_Request
shared_ptr< CPSG_ReplyItem > GetNextItem(CDeadline deadline)
Get the next item which has started arriving from the server.
SPSG_Message GetNextMessage(EDiagSev min_severity=eDiag_Error) const
Unstructured text containing auxiliary info about the result – such as messages and errors that came ...
EPSG_Status GetStatus(CDeadline deadline) const
Get the final result of this whole reply's retrieval.
shared_ptr< const CPSG_Request > GetRequest() const
Get the request that resulted in this reply.
unique_ptr< SImpl > m_Impl
Request to the PSG server (by bio-id, for a biodata specific info and data)
Definition: psg_client.hpp:310
vector< CPSG_BlobId > TExcludeTSEs
Definition: psg_client.hpp:361
EType x_GetType() const override
Definition: psg_client.hpp:374
const TExcludeTSEs & GetExcludeTSEs() const
Definition: psg_client.hpp:365
void SetAccSubstitution(EPSG_AccSubstitution acc_substitution)
Set substitution policy for version-less primary seq-ids.
Definition: psg_client.hpp:368
string x_GetId() const override
Definition: psg_client.hpp:375
void ExcludeTSE(CPSG_BlobId blob_id)
Definition: psg_client.hpp:363
void SetResendTimeout(CTimeout resend_timeout)
Set resend timeout.
Definition: psg_client.hpp:371
EPSG_BioIdResolution GetBioIdResolution() const
Definition: psg_client.hpp:332
EIncludeData
Specify which info and data is needed.
Definition: psg_client.hpp:335
@ eNoTSE
Only the info.
Definition: psg_client.hpp:340
@ eSmartTSE
If ID2 split is available, return split info blob only.
Definition: psg_client.hpp:348
@ eSlimTSE
If ID2 split is available, return split info blob only.
Definition: psg_client.hpp:344
@ eDefault
Server default.
Definition: psg_client.hpp:337
@ eWholeTSE
If ID2 split is available, return all split blobs.
Definition: psg_client.hpp:352
@ eOrigTSE
Return all Cassandra data chunks of the blob itself.
Definition: psg_client.hpp:355
void IncludeData(EIncludeData include)
Definition: psg_client.hpp:357
TExcludeTSEs m_ExcludeTSEs
Definition: psg_client.hpp:381
EPSG_BioIdResolution m_BioIdResolution
Definition: psg_client.hpp:379
EIncludeData GetIncludeData() const
Definition: psg_client.hpp:359
CPSG_Request_Biodata(CPSG_BioId bio_id, shared_ptr< void > user_context={}, CRef< CRequestContext > request_context={})
Definition: psg_client.hpp:325
const CPSG_BioId & GetBioId() const
Definition: psg_client.hpp:331
void x_GetAbsPathRef(ostream &) const override
Definition: psg_client.cpp:818
EPSG_AccSubstitution m_AccSubstitution
Definition: psg_client.hpp:382
EIncludeData m_IncludeData
Definition: psg_client.hpp:380
CPSG_Request_Biodata(CPSG_BioId bio_id, EPSG_BioIdResolution bio_id_resolution, shared_ptr< void > user_context={}, CRef< CRequestContext > request_context={})
Definition: psg_client.hpp:316
Request to the PSG server (by blob-id, for a particular blob of data)
Definition: psg_client.hpp:461
CPSG_Request_Blob(CPSG_BlobId blob_id, shared_ptr< void > user_context={}, CRef< CRequestContext > request_context={})
Definition: psg_client.hpp:464
EIncludeData GetIncludeData() const
Definition: psg_client.hpp:477
string x_GetId() const override
Definition: psg_client.hpp:481
EIncludeData m_IncludeData
Definition: psg_client.hpp:485
CPSG_BlobId m_BlobId
Definition: psg_client.hpp:484
void IncludeData(EIncludeData include)
Definition: psg_client.hpp:475
const CPSG_BlobId & GetBlobId() const
Definition: psg_client.hpp:471
EType x_GetType() const override
Definition: psg_client.hpp:480
void x_GetAbsPathRef(ostream &) const override
Definition: psg_client.cpp:867
Request blob data chunk.
Definition: psg_client.hpp:573
void x_GetAbsPathRef(ostream &) const override
Definition: psg_client.cpp:908
EType x_GetType() const override
Definition: psg_client.hpp:585
string x_GetId() const override
Definition: psg_client.hpp:586
CPSG_ChunkId m_ChunkId
Definition: psg_client.hpp:589
CPSG_Request_Chunk(CPSG_ChunkId chunk_id, shared_ptr< void > user_context={}, CRef< CRequestContext > request_context={})
Definition: psg_client.hpp:575
const CPSG_ChunkId & GetChunkId() const
Definition: psg_client.hpp:582
Request IPG resolve.
Definition: psg_client.hpp:598
const TNucleotide & GetNucleotide() const
Definition: psg_client.hpp:610
void x_GetAbsPathRef(ostream &) const override
Definition: psg_client.cpp:936
EType x_GetType() const override
Definition: psg_client.hpp:613
string x_GetId() const override
Definition: psg_client.cpp:931
const string & GetProtein() const
Definition: psg_client.hpp:608
CPSG_Request_IpgResolve(string protein, Int8 ipg={}, TNucleotide nucleotide={}, shared_ptr< void > user_context={}, CRef< CRequestContext > request_context={})
Definition: psg_client.cpp:914
CNullable< string > TNucleotide
Definition: psg_client.hpp:600
Request meta-information for the named annotations which are defined on the bioseq.
Definition: psg_client.hpp:495
objects::CSeq_id::ESNPScaleLimit ESNPScaleLimit
Scale-limit parameter for SNP annotations.
Definition: psg_client.hpp:550
CPSG_Request_NamedAnnotInfo(CPSG_BioIds bio_ids, TAnnotNames annot_names, EPSG_BioIdResolution bio_id_resolution, shared_ptr< void > user_context={}, CRef< CRequestContext > request_context={})
Definition: psg_client.hpp:506
const CPSG_BioId & GetBioId() const
Definition: psg_client.hpp:535
EPSG_BioIdResolution m_BioIdResolution
Definition: psg_client.hpp:561
vector< string > TAnnotNames
Names of the named annotations.
Definition: psg_client.hpp:498
CPSG_Request_NamedAnnotInfo(CPSG_BioIds bio_ids, TAnnotNames annot_names, shared_ptr< void > user_context={}, CRef< CRequestContext > request_context={})
Definition: psg_client.hpp:521
CPSG_Request_NamedAnnotInfo(CPSG_BioId bio_id, TArgs &&... args)
Definition: psg_client.hpp:531
ESNPScaleLimit m_SNPScaleLimit
Definition: psg_client.hpp:564
void SetAccSubstitution(EPSG_AccSubstitution acc_substitution)
Set substitution policy for version-less primary seq-ids.
Definition: psg_client.hpp:541
void SetSNPScaleLimit(ESNPScaleLimit snp_scale_limit)
Definition: psg_client.hpp:551
const CPSG_BioIds & GetBioIds() const
Definition: psg_client.hpp:536
EPSG_BioIdResolution GetBioIdResolution() const
Definition: psg_client.hpp:538
void x_GetAbsPathRef(ostream &) const override
Definition: psg_client.cpp:887
EType x_GetType() const override
Definition: psg_client.hpp:555
void IncludeData(EIncludeData include)
Definition: psg_client.hpp:545
ESNPScaleLimit GetSNPScaleLimit() const
Definition: psg_client.hpp:552
const TAnnotNames & GetAnnotNames() const
Definition: psg_client.hpp:537
string x_GetId() const override
Definition: psg_client.hpp:556
EPSG_AccSubstitution m_AccSubstitution
Definition: psg_client.hpp:562
EIncludeData GetIncludeData() const
Definition: psg_client.hpp:547
Request to the PSG server (by bio-id, for a biodata specific info and data)
Definition: psg_client.hpp:392
string x_GetId() const override
Definition: psg_client.hpp:446
CPSG_Request_Resolve(CPSG_BioId bio_id, shared_ptr< void > user_context={}, CRef< CRequestContext > request_context={})
Definition: psg_client.hpp:407
DECLARE_SAFE_FLAGS_TYPE(EIncludeInfo, TIncludeInfo)
EIncludeInfo
Specify which info and data is needed Some processors may provide more than the flags prescribe Alway...
Definition: psg_client.hpp:420
@ fName
Requests name to use for canonical bio-id.
Definition: psg_client.hpp:423
EPSG_BioIdResolution GetBioIdResolution() const
Definition: psg_client.hpp:414
EPSG_AccSubstitution m_AccSubstitution
Definition: psg_client.hpp:452
TIncludeInfo m_IncludeInfo
Definition: psg_client.hpp:451
void IncludeInfo(TIncludeInfo include)
Definition: psg_client.hpp:437
EPSG_BioIdResolution m_BioIdResolution
Definition: psg_client.hpp:450
TIncludeInfo GetIncludeInfo() const
Definition: psg_client.hpp:439
void x_GetAbsPathRef(ostream &) const override
Definition: psg_client.cpp:836
CPSG_Request_Resolve(CPSG_BioId bio_id, EPSG_BioIdResolution bio_id_resolution, shared_ptr< void > user_context={}, CRef< CRequestContext > request_context={})
Definition: psg_client.hpp:398
void SetAccSubstitution(EPSG_AccSubstitution acc_substitution)
Set substitution policy for version-less primary seq-ids.
Definition: psg_client.hpp:442
EType x_GetType() const override
Definition: psg_client.hpp:445
const CPSG_BioId & GetBioId() const
Definition: psg_client.hpp:413
Request to the PSG server (see "CPSG_Request_*" below)
Definition: psg_client.hpp:100
void SetUserArgs(SPSG_UserArgs user_args)
Set arbitrary URL arguments to add to this request.
Definition: psg_client.hpp:144
virtual string x_GetId() const =0
virtual EType x_GetType() const =0
CRef< CRequestContext > m_RequestContext
Definition: psg_client.hpp:163
string GetId() const
Definition: psg_client.hpp:134
virtual void x_GetAbsPathRef(ostream &) const =0
virtual ~CPSG_Request()=default
DECLARE_SAFE_FLAGS_TYPE(EFlags, TFlags)
shared_ptr< void > m_UserContext
Definition: psg_client.hpp:162
void SetFlags(TOptionalFlags flags)
Set flags.
Definition: psg_client.hpp:137
TOptionalFlags m_Flags
Definition: psg_client.hpp:164
SPSG_UserArgs m_UserArgs
Definition: psg_client.hpp:165
CRef< CRequestContext > GetRequestContext() const
Get request context.
Definition: psg_client.hpp:125
void SetRequestContext(CRef< CRequestContext > request_context)
Set request context.
EType GetType() const
Get request type.
Definition: psg_client.hpp:131
shared_ptr< TUserContext > GetUserContext() const
Get the user-provided context.
Definition: psg_client.hpp:121
CPSG_Request(shared_ptr< void > user_context={}, CRef< CRequestContext > request_context={})
Definition: psg_client.hpp:149
Skipped blob.
Definition: psg_client.hpp:809
TSeconds m_SentSecondsAgo
Definition: psg_client.hpp:838
const TSeconds & GetSentSecondsAgo() const
Seconds passed since the blob was last sent to the client.
Definition: psg_client.hpp:828
const TDataId * GetId() const
Get data ID.
Definition: psg_client.hpp:822
EReason GetReason() const
Definition: psg_client.hpp:825
const TSeconds & GetTimeUntilResend() const
Seconds before the blob will be sent to the client.
Definition: psg_client.hpp:831
unique_ptr< CPSG_DataId > m_Id
Definition: psg_client.hpp:836
TSeconds m_TimeUntilResend
Definition: psg_client.hpp:839
CPSG_SkippedBlob(unique_ptr< CPSG_DataId > id, EReason reason, TSeconds sent_seconds_ago, TSeconds time_until_resend)
CTime –.
Definition: ncbitime.hpp:296
CTimeout – Timeout interval.
Definition: ncbitime.hpp:1693
CUrlArgs::
Definition: ncbi_url.hpp:240
URL parsing classes.
static uch flags
#define T(s)
Definition: common.h:230
SStrictId_Tax::TId TTaxId
Taxon id type.
Definition: ncbimisc.hpp:1048
@ eDefault
Definition: ncbi_types.h:112
string
Definition: cgiapp.hpp:687
static CRequestContext & GetRequestContext(void)
Shortcut to CDiagContextThreadData::GetThreadData().GetRequestContext()
Definition: ncbidiag.cpp:1901
CRef< CRequestContext > Clone(void) const
Copy current request context to a new one.
EDiagSev
Severity level for the posted diagnostics.
Definition: ncbidiag.hpp:650
@ eDiag_Error
Error message.
Definition: ncbidiag.hpp:653
#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
EErrCode
Error types that an application can generate.
Definition: ncbiexpt.hpp:884
void GetLabel(string *label, ELabelType type=eDefault, TLabelFlags flags=fLabel_Default) const
Append a label for this Seq-id to the supplied string.
Definition: Seq_id.cpp:2039
@ eFastaContent
Like eFasta, but without any tag.
Definition: Seq_id.hpp:576
int64_t Int8
8-byte (64-bit) signed integer
Definition: ncbitype.h:104
uint64_t Uint8
8-byte (64-bit) unsigned integer
Definition: ncbitype.h:105
#define END_NCBI_SCOPE
End previously defined NCBI scope.
Definition: ncbistl.hpp:103
#define BEGIN_NCBI_SCOPE
Define ncbi namespace.
Definition: ncbistl.hpp:100
Int8 TSeconds
Number of seconds.
Definition: ncbitime.hpp:77
@ eDefault
Default timeout (to be interpreted by the client code)
Definition: ncbitime.hpp:1698
E_Choice
Choice variants.
Definition: Seq_id_.hpp:93
static void text(MDB_val *v)
Definition: mdb_dump.c:62
constexpr bool empty(list< Ts... >) noexcept
Miscellaneous common-use basic types and functionality.
Defines: CTimeFormat - storage class for time format.
T max(T x_, T y_)
EPSG_AccSubstitution
Whether and how to substitute version-less primary seq-ids with the "more unique" secondary seq-ids.
Definition: psg_client.hpp:290
@ Never
No substitution whatsoever - return exact raw accession info.
@ Default
Substitute always (default)
@ Limited
Substitute only if the resolved record's seq_id_type is GI(12)
EPSG_Status
Retrieval result.
Definition: psg_client.hpp:626
@ eSuccess
Successfully retrieved.
@ eInProgress
Retrieval is not finalized yet, more info may come.
@ eForbidden
User is not authorized for the retrieval.
@ eCanceled
Request canceled.
@ eError
An error was encountered while trying to send request or to read and to process the reply.
@ eNotFound
Not found.
vector< CPSG_BioId > CPSG_BioIds
Definition: psg_client.hpp:206
EPSG_BioIdResolution
Whether to try to resolve provided seq-ids before use.
Definition: psg_client.hpp:299
@ Resolve
Try to resolve provided seq-ids.
@ NoResolve
Use provided seq-ids as is.
DECLARE_SAFE_FLAGS(CPSG_Request::EFlags)
static bool GetSeqId(const T &d, set< string > &labels, const string name="", bool detect=false, bool found=false)
Defines CRequestContext class for NCBI C++ diagnostic API.
EDiagSev severity
Definition: psg_client.hpp:649
optional< int > code
Definition: psg_client.hpp:650
Arbitrary request URL arguments.
Definition: psg_client.hpp:79
SPSG_UserArgs(const string &query)
Definition: psg_client.hpp:91
SPSG_UserArgs(const CUrlArgs &url_args)
Allow construction from a CUrlArgs instance or using CUrlArgs parsing.
Definition: psg_client.cpp:556
static string query
Definition: type.c:6
Modified on Mon Mar 04 05:12:23 2024 by modify_doxy.py rev. 669887