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

Go to the SVN repository for this file.

1 #ifndef GET_BLOB_CALLBACK__HPP
2 #define GET_BLOB_CALLBACK__HPP
3 
4 /* $Id: get_blob_callback.hpp 101848 2024-02-22 13:57:25Z satskyse $
5  * ===========================================================================
6  *
7  * PUBLIC DOMAIN NOTICE
8  * National Center for Biotechnology Information
9  *
10  * This software/database is a "United States Government Work" under the
11  * terms of the United States Copyright Act. It was written as part of
12  * the author's official duties as a United States Government employee and
13  * thus cannot be copyrighted. This software/database is freely available
14  * to the public for use. The National Library of Medicine and the U.S.
15  * Government have not placed any restriction on its use or reproduction.
16  *
17  * Although all reasonable efforts have been taken to ensure the accuracy
18  * and reliability of the software and data, the NLM and the U.S.
19  * Government do not and cannot warrant the performance or results that
20  * may be obtained by using this software or data. The NLM and the U.S.
21  * Government disclaim all warranties, express or implied, including
22  * warranties of performance, merchantability or fitness for any particular
23  * purpose.
24  *
25  * Please cite the author in any work or product based on this material.
26  *
27  * ===========================================================================
28  *
29  * Authors: Sergey Satskiy
30  *
31  * File Description:
32  *
33  */
34 
35 #include "cass_fetch.hpp"
36 #include "pubseq_gateway.hpp"
38 
39 #include <functional>
40 
41 using TBlobChunkCB = function<void(CCassBlobFetch * fetch_details,
42  CBlobRecord const & blob,
43  const unsigned char * chunk_data,
44  unsigned int data_size,
45  int chunk_no)>;
46 using TBlobPropsCB = function<void(CCassBlobFetch * fetch_details,
47  CBlobRecord const & blob,
48  bool is_found)>;
49 using TBlobErrorCB = function<void(CCassBlobFetch * fetch_details,
50  CRequestStatus::ECode status,
51  int code,
52  EDiagSev severity,
53  const string & message)>;
54 
55 class IPSGS_Processor;
56 
57 
59 {
60  public:
62  TBlobChunkCB blob_chunk_cb,
63  CCassBlobFetch * fetch_details,
64  EPSGOperation retrieve_statistic=eBlobRetrieve) :
65  m_Processor(processor),
66  m_BlobChunkCB(blob_chunk_cb),
67  m_FetchDetails(fetch_details),
68  m_RetrieveStatistic(retrieve_statistic),
69  m_BlobSize(0),
71  {}
72 
73  void operator()(CBlobRecord const & blob,
74  const unsigned char * chunk_data,
75  unsigned int data_size, int chunk_no)
76  {
77  if (chunk_no >= 0)
78  m_BlobSize += data_size;
79  else
83 
84  m_BlobChunkCB(m_FetchDetails, blob, chunk_data, data_size, chunk_no);
85  }
86 
87  private:
92 
93  unsigned long m_BlobSize;
95 };
96 
97 
99 {
100  public:
102  IPSGS_Processor * processor,
103  TBlobPropsCB blob_prop_cb,
104  shared_ptr<CPSGS_Request> request,
105  shared_ptr<CPSGS_Reply> reply,
106  CCassBlobFetch * fetch_details,
107  bool need_timing) :
108  m_Processor(processor),
109  m_BlobPropCB(blob_prop_cb),
110  m_Request(request),
111  m_Reply(reply),
112  m_FetchDetails(fetch_details),
114  m_NeedTiming(need_timing)
115  {
116  if (need_timing)
117  m_BlobPropTiming = psg_clock_t::now();
118  }
119 
120  void operator()(CBlobRecord const & blob, bool is_found)
121  {
122  if (!m_InProcess) {
123  if (m_Request->NeedTrace()) {
124  if (is_found) {
125  m_Reply->SendTrace("Cassandra blob props: " +
126  ToJsonString(blob),
127  m_Request->GetStartTimestamp());
128  } else {
129  m_Reply->SendTrace("Cassandra blob props not found",
130  m_Request->GetStartTimestamp());
131  }
132  }
133 
134  if (m_NeedTiming) {
136  if (is_found)
141  else
146  }
147 
148  m_InProcess = true;
149  m_BlobPropCB(m_FetchDetails, blob, is_found);
150  m_InProcess = false;
151  }
152  }
153 
154  private:
157  shared_ptr<CPSGS_Request> m_Request;
158  shared_ptr<CPSGS_Reply> m_Reply;
160 
161  // Avoid an infinite loop
163 
164  // Timing
167 };
168 
169 
171 {
172  public:
174  TBlobErrorCB blob_error_cb,
175  CCassBlobFetch * fetch_details,
176  EPSGOperation retrieve_statistic=eBlobRetrieve) :
177  m_Processor(processor),
178  m_BlobErrorCB(blob_error_cb),
179  m_FetchDetails(fetch_details),
180  m_RetrieveStatistic(retrieve_statistic),
182  {}
183 
185  int code,
186  EDiagSev severity,
187  const string & message)
188  {
189  if (status == CRequestStatus::e404_NotFound)
193  m_BlobErrorCB(m_FetchDetails, status, code, severity, message);
194  }
195 
196  private:
201 
203 };
204 
205 #endif
206 
TBlobChunkCB m_BlobChunkCB
unsigned long m_BlobSize
psg_time_point_t m_BlobRetrieveTiming
CCassBlobFetch * m_FetchDetails
EPSGOperation m_RetrieveStatistic
CBlobChunkCallback(IPSGS_Processor *processor, TBlobChunkCB blob_chunk_cb, CCassBlobFetch *fetch_details, EPSGOperation retrieve_statistic=eBlobRetrieve)
IPSGS_Processor * m_Processor
void operator()(CBlobRecord const &blob, const unsigned char *chunk_data, unsigned int data_size, int chunk_no)
void operator()(CBlobRecord const &blob, bool is_found)
shared_ptr< CPSGS_Reply > m_Reply
CCassBlobFetch * m_FetchDetails
psg_time_point_t m_BlobPropTiming
CBlobPropCallback(IPSGS_Processor *processor, TBlobPropsCB blob_prop_cb, shared_ptr< CPSGS_Request > request, shared_ptr< CPSGS_Reply > reply, CCassBlobFetch *fetch_details, bool need_timing)
shared_ptr< CPSGS_Request > m_Request
IPSGS_Processor * m_Processor
EPSGOperation m_RetrieveStatistic
CCassBlobFetch * m_FetchDetails
CGetBlobErrorCallback(IPSGS_Processor *processor, TBlobErrorCB blob_error_cb, CCassBlobFetch *fetch_details, EPSGOperation retrieve_statistic=eBlobRetrieve)
void operator()(CRequestStatus::ECode status, int code, EDiagSev severity, const string &message)
psg_time_point_t m_BlobRetrieveTiming
IPSGS_Processor * m_Processor
uint64_t Register(IPSGS_Processor *processor, EPSGOperation operation, EPSGOperationStatus status, const psg_time_point_t &op_begin_ts, size_t blob_size=0)
Definition: timing.cpp:1068
COperationTiming & GetTiming(void)
static CPubseqGatewayApp * GetInstance(void)
Interface class (and self-factory) for request processor objects that can retrieve data from a given ...
#define false
Definition: bool.h:36
function< void(CCassBlobFetch *fetch_details, CRequestStatus::ECode status, int code, EDiagSev severity, const string &message)> TBlobErrorCB
function< void(CCassBlobFetch *fetch_details, CBlobRecord const &blob, bool is_found)> TBlobPropsCB
function< void(CCassBlobFetch *fetch_details, CBlobRecord const &blob, const unsigned char *chunk_data, unsigned int data_size, int chunk_no)> TBlobChunkCB
EDiagSev
Severity level for the posted diagnostics.
Definition: ncbidiag.hpp:650
string ToJsonString(const CBioseqInfoRecord &bioseq_info, SPSGS_ResolveRequest::TPSGS_BioseqIncludeData include_data_flags, const string &custom_blob_id)
chrono::steady_clock psg_clock_t
psg_clock_t::time_point psg_time_point_t
Definition: inftrees.h:24
@ eOpStatusFound
Definition: timing.hpp:61
@ eOpStatusNotFound
Definition: timing.hpp:62
EPSGOperation
Definition: timing.hpp:65
@ eLookupCassBlobProp
Definition: timing.hpp:72
@ eBlobRetrieve
Definition: timing.hpp:98
Modified on Fri Sep 20 14:57:51 2024 by modify_doxy.py rev. 669887