]> git.ipfire.org Git - thirdparty/squid.git/blob - src/mgr/Inquirer.h
apply the initial Phase3 of the SMP Cache Manager patch
[thirdparty/squid.git] / src / mgr / Inquirer.h
1 /*
2 * $Id$
3 *
4 * DEBUG: section 16 Cache Manager API
5 *
6 */
7
8 #ifndef SQUID_MGR_INQUIRER_H
9 #define SQUID_MGR_INQUIRER_H
10
11 #include "base/AsyncJobCalls.h"
12 #include "base/AsyncJob.h"
13 #include "ipc/StrandCoords.h"
14 #include "MemBuf.h"
15 #include "mgr/Action.h"
16 #include "mgr/Request.h"
17 #include <map>
18
19 class CommIoCbParams;
20 class CommCloseCbParams;
21
22 namespace Mgr
23 {
24
25 /// Coordinator's job that sends a cache manage request to each strand,
26 /// aggregating individual strand responses and dumping the result if needed
27 class Inquirer: public AsyncJob
28 {
29 public:
30 Inquirer(Action::Pointer anAction, int aFd, const Request &aCause,
31 const Ipc::StrandCoords &coords);
32 virtual ~Inquirer();
33
34 /// finds and calls the right Inquirer upon strand's response
35 static void HandleRemoteAck(const Mgr::Response& response);
36
37 protected:
38 /* AsyncJob API */
39 virtual void start();
40 virtual void swanSong();
41 virtual bool doneAll() const;
42 virtual const char *status() const;
43
44 private:
45 typedef UnaryMemFunT<Inquirer, Response, const Response&> HandleAckDialer;
46
47 void inquire();
48 void noteWroteHeader(const CommIoCbParams& params);
49 void noteCommClosed(const CommCloseCbParams& params);
50
51 void handleRemoteAck(const Response& response);
52
53 static AsyncCall::Pointer DequeueRequest(unsigned int requestId);
54
55 static void RequestTimedOut(void* param);
56 void requestTimedOut();
57 void removeTimeoutEvent();
58
59 void close();
60 void removeCloseHandler();
61 Ipc::StrandCoords applyQueryParams(const Ipc::StrandCoords& aStrands,
62 const QueryParams& aParams);
63
64 private:
65 Action::Pointer aggrAction; //< action to aggregate
66
67 Request cause; ///< cache manager request received from HTTP client
68 int fd; ///< HTTP client socket descriptor
69
70 Ipc::StrandCoords strands; ///< all strands we want to query, in order
71 Ipc::StrandCoords::const_iterator pos; ///< strand we should query now
72
73 unsigned int requestId; ///< ID of our outstanding request to strand
74 AsyncCall::Pointer writer; ///< comm_write callback
75 AsyncCall::Pointer closer; ///< comm_close handler
76 const double timeout; ///< number of seconds to wait for strand response
77
78 /// maps requestId to Inquirer::handleRemoteAck callback
79 typedef std::map<unsigned int, AsyncCall::Pointer> RequestsMap;
80 static RequestsMap TheRequestsMap; ///< pending strand requests
81
82 static unsigned int LastRequestId; ///< last requestId used
83
84 CBDATA_CLASS2(Inquirer);
85 };
86
87 } // namespace Mgr
88
89 #endif /* SQUID_MGR_INQUIRER_H */