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

Go to the SVN repository for this file.

1 #ifndef DISPATCHER__HPP_INCLUDED
2 #define DISPATCHER__HPP_INCLUDED
3 /* */
4 
5 /* $Id: dispatcher.hpp 102228 2024-04-09 17:35:06Z vasilche $
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 * Author: Eugene Vasilchenko
29 *
30 * File Description: Dispatcher of readers/writers
31 *
32 */
33 
34 #include <corelib/ncbiobj.hpp>
40 
42 
43 class CStopWatch;
44 
46 
47 class CBlob_id;
48 class CBlob_Info;
49 class CSeq_id_Handle;
50 class CTSE_Info;
51 class CTSE_Chunk_Info;
53 
55 class CLoadLockBlob;
57 struct STimeStatistics;
58 
60 {
61 public:
68  typedef size_t TLevel;
69  typedef vector<CSeq_id_Handle> TIds;
70 
71  CReadDispatcher(void);
72  ~CReadDispatcher(void);
73 
74  // insert reader and set its m_Dispatcher
75  void InsertReader (TLevel level, CRef<CReader> reader);
76  void InsertWriter (TLevel level, CRef<CWriter> writer);
77  void InsertProcessor(CRef<CProcessor> processor);
78  bool HasReaderWithHUPIncluded() const;
79 
80  CWriter* GetWriter(const CReaderRequestResult& result,
81  CWriter::EType type) const;
82  const CProcessor& GetProcessor(CProcessor::EType type) const;
83 
84  static bool CannotProcess(const CSeq_id_Handle& sih);
85 
86  void LoadSeq_idBlob_ids(CReaderRequestResult& result,
87  const CSeq_id_Handle& seq_id,
88  const SAnnotSelector* sel);
89  void LoadSeq_idSeq_ids(CReaderRequestResult& result,
90  const CSeq_id_Handle& seq_id);
91  void LoadSeq_idGi(CReaderRequestResult& result,
92  const CSeq_id_Handle& seq_id);
93  void LoadSeq_idAccVer(CReaderRequestResult& result,
94  const CSeq_id_Handle& seq_id);
95  void LoadSeq_idLabel(CReaderRequestResult& result,
96  const CSeq_id_Handle& seq_id);
97  void LoadSeq_idTaxId(CReaderRequestResult& result,
98  const CSeq_id_Handle& seq_id);
99  void LoadSequenceHash(CReaderRequestResult& result,
100  const CSeq_id_Handle& seq_id);
101  void LoadSequenceLength(CReaderRequestResult& result,
102  const CSeq_id_Handle& seq_id);
103  void LoadSequenceType(CReaderRequestResult& result,
104  const CSeq_id_Handle& seq_id);
105 
106  // bulk requests
107  typedef vector<bool> TLoaded;
108  typedef vector<bool> TKnown;
109  typedef vector<TIds> TBulkIds;
110  typedef vector<TGi> TGis;
111  typedef vector<string> TLabels;
112  typedef vector<TTaxId> TTaxIds;
113  typedef vector<int> THashes;
114  typedef vector<TSeqPos> TLengths;
115  typedef vector<CSeq_inst::EMol> TTypes;
116  typedef vector<TBlobState> TStates;
117  typedef vector<CBlob_id> TBlobIds;
118  typedef vector<CBlob_Info> TBlobInfos;
119  typedef vector<pair<CBlob_id, TChunkIds>> TBlobChunkIds;
120  void LoadBulkIds(CReaderRequestResult& result,
121  const TIds& ids, TLoaded& loaded, TBulkIds& ret);
122  void LoadAccVers(CReaderRequestResult& result,
123  const TIds& ids, TLoaded& loaded, TIds& ret);
124  void LoadGis(CReaderRequestResult& result,
125  const TIds& ids, TLoaded& loaded, TGis& ret);
126  void LoadLabels(CReaderRequestResult& result,
127  const TIds& ids, TLoaded& loaded, TLabels& ret);
128  void LoadTaxIds(CReaderRequestResult& result,
129  const TIds& ids, TLoaded& loaded, TTaxIds& ret);
130  void LoadHashes(CReaderRequestResult& result,
131  const TIds& ids, TLoaded& loaded,
132  THashes& ret, TKnown& known);
133  void LoadLengths(CReaderRequestResult& result,
134  const TIds& ids, TLoaded& loaded, TLengths& ret);
135  void LoadTypes(CReaderRequestResult& result,
136  const TIds& ids, TLoaded& loaded, TTypes& ret);
137  void LoadStates(CReaderRequestResult& result,
138  const TIds& ids, TLoaded& loaded, TStates& ret);
139 
140  static bool SetBlobState(size_t i,
142  const TIds& ids, TLoaded& loaded,
143  TStates& ret);
144 
145  void LoadBlobState(CReaderRequestResult& result,
146  const TBlobId& blob_id);
147  void LoadBlobVersion(CReaderRequestResult& result,
148  const TBlobId& blob_id,
149  const CReader* asking_reader = 0);
150  void LoadBlobs(CReaderRequestResult& result,
151  const CSeq_id_Handle& seq_id,
153  const SAnnotSelector* sel);
154  void LoadBlobs(CReaderRequestResult& result,
155  const CLoadLockBlobIds& blobs,
157  const SAnnotSelector* sel);
158  void LoadBlob(CReaderRequestResult& result,
159  const CBlob_id& blob_id);
160  void LoadBlob(CReaderRequestResult& result,
161  const CBlob_Info& blob_info);
162  void LoadChunk(CReaderRequestResult& result,
163  const TBlobId& blob_id, TChunkId chunk_id);
164  void LoadChunks(CReaderRequestResult& result,
165  const TBlobId& blob_id,
166  const TChunkIds& chunk_ids);
167  void LoadChunks(CReaderRequestResult& result,
168  const TBlobChunkIds& chunk_ids);
169  void LoadBlobSet(CReaderRequestResult& result,
170  const TIds& seq_ids);
171  void LoadBlobs(CReaderRequestResult& result,
172  const TBlobInfos& blob_infos);
173 
174  void CheckReaders(void) const;
176  const CReader* asking_reader = 0);
177  void ResetCaches(void);
178 
179  static int CollectStatistics(void); // 0 - no stats, >1 - verbose
180 
181  static void LogStat(CReadDispatcherCommand& command,
182  CReaderRequestResultRecursion& recursion);
183  static void LogStat(CReadDispatcherCommand& command,
184  CReaderRequestResultRecursion& recursion, double size);
185 
186 private:
190 
194 };
195 
196 
198 {
199 public:
201  virtual ~CReadDispatcherCommand(void);
202 
203  virtual bool IsDone(void) = 0;
204 
205  // return false if it doesn't make sense to retry
206  virtual bool Execute(CReader& reader) = 0;
207 
208  virtual bool MayBeSkipped(void) const;
209 
210  virtual string GetErrMsg(void) const = 0;
211 
213  {
214  return m_Result;
215  }
216 
218  virtual string GetStatisticsDescription(void) const = 0;
219  virtual size_t GetStatisticsCount(void) const;
220 
221 private:
223 };
224 
225 
228 
229 #endif//DISPATCHER__HPP_INCLUDED
ncbi::TMaskedQueryRegions mask
CObject –.
Definition: ncbiobj.hpp:180
virtual CGBRequestStatistics::EStatType GetStatistics(void) const =0
virtual string GetStatisticsDescription(void) const =0
virtual bool Execute(CReader &reader)=0
CReaderRequestResult & m_Result
Definition: dispatcher.hpp:222
virtual string GetErrMsg(void) const =0
virtual bool IsDone(void)=0
CReaderRequestResult & GetResult(void) const
Definition: dispatcher.hpp:212
CReader::TBlobState TBlobState
Definition: dispatcher.hpp:63
vector< CBlob_id > TBlobIds
Definition: dispatcher.hpp:117
TProcessors m_Processors
Definition: dispatcher.hpp:193
CReader::TChunkId TChunkId
Definition: dispatcher.hpp:66
CReader::TBlobId TBlobId
Definition: dispatcher.hpp:65
CReader::TBlobVersion TBlobVersion
Definition: dispatcher.hpp:64
CReader::TContentsMask TContentsMask
Definition: dispatcher.hpp:62
vector< string > TLabels
Definition: dispatcher.hpp:111
CReader::TChunkIds TChunkIds
Definition: dispatcher.hpp:67
vector< int > THashes
Definition: dispatcher.hpp:113
vector< TBlobState > TStates
Definition: dispatcher.hpp:116
vector< pair< CBlob_id, TChunkIds > > TBlobChunkIds
Definition: dispatcher.hpp:119
vector< bool > TLoaded
Definition: dispatcher.hpp:107
vector< bool > TKnown
Definition: dispatcher.hpp:108
map< TLevel, CRef< CReader > > TReaders
Definition: dispatcher.hpp:187
vector< CBlob_Info > TBlobInfos
Definition: dispatcher.hpp:118
vector< CSeq_id_Handle > TIds
Definition: dispatcher.hpp:69
TWriters m_Writers
Definition: dispatcher.hpp:192
vector< CSeq_inst::EMol > TTypes
Definition: dispatcher.hpp:115
vector< TIds > TBulkIds
Definition: dispatcher.hpp:109
TReaders m_Readers
Definition: dispatcher.hpp:191
vector< TTaxId > TTaxIds
Definition: dispatcher.hpp:112
map< CProcessor::EType, CRef< CProcessor > > TProcessors
Definition: dispatcher.hpp:189
vector< TGi > TGis
Definition: dispatcher.hpp:110
vector< TSeqPos > TLengths
Definition: dispatcher.hpp:114
map< TLevel, CRef< CWriter > > TWriters
Definition: dispatcher.hpp:188
int TBlobVersion
Definition: reader.hpp:91
int TChunkId
Definition: reader.hpp:93
vector< TChunkId > TChunkIds
Definition: reader.hpp:95
int TContentsMask
Definition: reader.hpp:94
int TBlobState
Definition: reader.hpp:90
CStopWatch –.
Definition: ncbitime.hpp:1937
Definition: map.hpp:338
#define END_NCBI_SCOPE
End previously defined NCBI scope.
Definition: ncbistl.hpp:103
#define END_SCOPE(ns)
End the previously defined scope.
Definition: ncbistl.hpp:75
#define BEGIN_NCBI_SCOPE
Define ncbi namespace.
Definition: ncbistl.hpp:100
#define BEGIN_SCOPE(ns)
Define a new scope.
Definition: ncbistl.hpp:72
virtual void Process(SOCK sock)=0
Runs asynchronously (from a separate thread) for each request.
#define NCBI_XREADER_EXPORT
Definition: ncbi_export.h:1371
int i
const struct ncbi::grid::netcache::search::fields::SIZE size
Portable reference counted smart and weak pointers using CWeakRef, CRef, CObject and CObjectEx.
const char * command
Plugin manager (using class factory paradigm).
static bool CannotProcess(const CSeq_id_Handle &sih)
SAnnotSelector –.
Definition: type.c:6
else result
Definition: token2.c:20
Modified on Wed Sep 04 15:06:42 2024 by modify_doxy.py rev. 669887