Inquirer.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 1996-2017 The Squid Software Foundation and contributors
3  *
4  * Squid software is distributed under GPLv2+ license and includes
5  * contributions from numerous individuals and organizations.
6  * Please see the COPYING and CONTRIBUTORS files for details.
7  */
8 
9 /* DEBUG: section 54 Interprocess Communication */
10 
11 #ifndef SQUID_IPC_INQUIRER_H
12 #define SQUID_IPC_INQUIRER_H
13 
14 #include "base/AsyncJob.h"
15 #include "base/AsyncJobCalls.h"
16 #include "ipc/forward.h"
17 #include "ipc/Request.h"
18 #include "ipc/Response.h"
19 #include "ipc/StrandCoords.h"
20 #include <map>
21 
22 namespace Ipc
23 {
24 
27 class Inquirer: public AsyncJob
28 {
30 
31 public:
32  Inquirer(Request::Pointer aRequest, const Ipc::StrandCoords& coords, double aTimeout);
33  virtual ~Inquirer();
34 
36  static void HandleRemoteAck(const Response& response);
37 
38  /* has-to-be-public AsyncJob API */
39  virtual void callException(const std::exception& e);
40 
41 protected:
42  /* AsyncJob API */
43  virtual void start();
44  virtual void swanSong();
45  virtual bool doneAll() const;
46  virtual const char *status() const;
47 
49  virtual void inquire();
51  virtual void cleanup();
53  virtual void handleException(const std::exception& e);
55  virtual void sendResponse() = 0;
57  virtual bool aggregate(Response::Pointer aResponse) = 0;
58 
59 private:
61 
62  void handleRemoteAck(Response::Pointer response);
63 
64  static AsyncCall::Pointer DequeueRequest(unsigned int requestId);
65 
66  static void RequestTimedOut(void* param);
67  void requestTimedOut();
68  void removeTimeoutEvent();
69 
70 protected:
72 
74  Ipc::StrandCoords::const_iterator pos;
75 
76  const double timeout;
77 
79  typedef std::map<unsigned int, AsyncCall::Pointer> RequestsMap;
81 
82  static unsigned int LastRequestId;
83 };
84 
85 } // namespace Ipc
86 
87 #endif /* SQUID_IPC_INQUIRER_H */
88 
static void RequestTimedOut(void *param)
Ipc::Inquirer::requestTimedOut wrapper.
Definition: Inquirer.cc:178
UnaryMemFunT< Inquirer, Response::Pointer, Response::Pointer > HandleAckDialer
Definition: Inquirer.h:60
void removeTimeoutEvent()
called when we are no longer waiting for the strand to respond
Definition: Inquirer.cc:170
std::map< unsigned int, AsyncCall::Pointer > RequestsMap
maps request->id to Inquirer::handleRemoteAck callback
Definition: Inquirer.h:79
const double timeout
number of seconds to wait for strand response
Definition: Inquirer.h:76
static void HandleRemoteAck(const Response &response)
finds and calls the right Inquirer upon strand's response
Definition: Inquirer.cc:156
Ipc::StrandCoords strands
all strands we want to query, in order
Definition: Inquirer.h:73
virtual void handleException(const std::exception &e)
do specific exception handling
Definition: Inquirer.cc:121
virtual void callException(const std::exception &e)
called when the job throws during an async call
Definition: Inquirer.cc:128
virtual void cleanup()
perform cleanup actions on completion of job
Definition: Inquirer.cc:51
void handleRemoteAck(Response::Pointer response)
called when a strand is done writing its output
Definition: Inquirer.cc:87
void requestTimedOut()
called when the strand failed to respond (or finish responding) in time
Definition: Inquirer.cc:189
virtual const char * status() const
internal cleanup; do not call directly
Definition: Inquirer.cc:202
std::vector< StrandCoord > StrandCoords
a collection of strand coordinates; the order, if any, is owner-dependent
Definition: StrandCoords.h:19
virtual void inquire()
inquire the next strand
Definition: Inquirer.cc:62
virtual bool aggregate(Response::Pointer aResponse)=0
perform aggregating of responses and returns true if need to continue
Inquirer(Request::Pointer aRequest, const Ipc::StrandCoords &coords, double aTimeout)
Definition: Inquirer.cc:33
Request::Pointer request
cache manager request received from client
Definition: Inquirer.h:71
virtual ~Inquirer()
Definition: Inquirer.cc:44
Ipc::StrandCoords::const_iterator pos
strand we should query now
Definition: Inquirer.h:74
static unsigned int LastRequestId
last requestId used
Definition: Inquirer.h:82
virtual void sendResponse()=0
send response to client
static AsyncCall::Pointer DequeueRequest(unsigned int requestId)
returns and forgets the right Inquirer callback for strand request
Definition: Inquirer.cc:141
virtual void start()
called by AsyncStart; do not call directly
Definition: Inquirer.cc:56
A response to Ipc::Request.
Definition: Response.h:21
virtual void swanSong()
Definition: Inquirer.cc:102
virtual bool doneAll() const
whether positive goal has been reached
Definition: Inquirer.cc:115
CBDATA_CLASS(Inquirer)
static RequestsMap TheRequestsMap
pending strand requests
Definition: Inquirer.h:80

 

Introduction

Documentation

Support

Miscellaneous

Web Site Translations

Mirrors