]> git.ipfire.org Git - thirdparty/squid.git/blob - src/adaptation/History.h
SourceFormat Enforcement
[thirdparty/squid.git] / src / adaptation / History.h
1 #ifndef SQUID_ADAPT_HISTORY_H
2 #define SQUID_ADAPT_HISTORY_H
3
4 #include "adaptation/DynamicGroupCfg.h"
5 #include "Array.h"
6 #include "HttpHeader.h"
7 #include "RefCount.h"
8 #include "SquidString.h"
9
10 namespace Adaptation
11 {
12
13 /// collects information about adaptations related to a master transaction
14 class History: public RefCountable
15 {
16 public:
17 typedef RefCount<Adaptation::History> Pointer;
18
19 History();
20
21 /// record the start of a xact, return xact history ID
22 int recordXactStart(const String &serviceId, const timeval &when, bool retrying);
23
24 /// record the end of a xact identified by its history ID
25 void recordXactFinish(int hid);
26
27 /// dump individual xaction times to a string
28 void allLogString(const char *serviceId, String &buf);
29
30 /// dump xaction times, merging retried and retry times together
31 void sumLogString(const char *serviceId, String &buf);
32
33 /// sets or resets a cross-transactional database record
34 void updateXxRecord(const char *name, const String &value);
35
36 /// returns true and fills the record fields iff there is a db record
37 bool getXxRecord(String &name, String &value) const;
38
39 /// sets or resets next services for the Adaptation::Iterator to notice
40 void updateNextServices(const String &services);
41
42 /// returns true, fills the value, and resets iff next services were set
43 bool extractNextServices(String &value);
44
45 /// store the last meta header fields received from the adaptation service
46 void recordMeta(const HttpHeader *lm);
47
48 public:
49 /// Last received meta header (REQMOD or RESPMOD, whichever comes last).
50 HttpHeader lastMeta;
51 /// All REQMOD and RESPMOD meta headers merged. Last field wins conflicts.
52 HttpHeader allMeta;
53
54 /// sets future services for the Adaptation::AccessCheck to notice
55 void setFutureServices(const DynamicGroupCfg &services);
56
57 /// returns true, fills the value, and resets iff future services were set
58 bool extractFutureServices(DynamicGroupCfg &services);
59
60 private:
61 /// single Xaction stats (i.e., a historical record entry)
62 class Entry
63 {
64 public:
65 Entry(const String &serviceId, const timeval &when);
66 Entry(); // required by Vector<>
67
68 void stop(); ///< updates stats on transaction end
69 int rptm(); ///< returns response time [msec], calculates it if needed
70
71 String service; ///< adaptation service ID
72 timeval start; ///< when the xaction was started
73
74 private:
75 int theRptm; ///< calculated and cached response time value in msec
76
77 public:
78 bool retried; ///< whether the xaction was replaced by another
79 };
80
81 typedef Vector<Entry> Entries;
82 Entries theEntries; ///< historical record, in the order of xact starts
83
84 // theXx* will become a map<string,string>, but we only support one record
85 String theXxName; ///< name part of the cross-transactional database record
86 String theXxValue; ///< value part of the cross-xactional database record
87
88 String theNextServices; ///< services Adaptation::Iterator must use next
89 DynamicGroupCfg theFutureServices; ///< services AccessCheck must use
90 };
91
92 } // namespace Adaptation
93
94 #endif