]> git.ipfire.org Git - thirdparty/squid.git/blob - src/adaptation/icap/Launcher.cc
Use newly added CBDATA_NAMESPACED_CLASS_INIT.
[thirdparty/squid.git] / src / adaptation / icap / Launcher.cc
1 /*
2 * DEBUG: section 93 ICAP (RFC 3507) Client
3 */
4
5 #include "squid.h"
6 #include "TextException.h"
7 #include "HttpMsg.h"
8 #include "adaptation/icap/Launcher.h"
9 #include "adaptation/icap/Xaction.h"
10 #include "adaptation/icap/ServiceRep.h"
11
12
13 Adaptation::Icap::Launcher::Launcher(const char *aTypeName,
14 Adaptation::Initiator *anInitiator, Adaptation::ServicePointer &aService):
15 AsyncJob(aTypeName),
16 Adaptation::Initiate(aTypeName, anInitiator, aService),
17 theXaction(0), theLaunches(0)
18 {
19 }
20
21 Adaptation::Icap::Launcher::~Launcher()
22 {
23 assert(!theXaction);
24 }
25
26 void Adaptation::Icap::Launcher::start()
27 {
28 Adaptation::Initiate::start();
29
30 Must(theInitiator);
31 launchXaction(false);
32 }
33
34 void Adaptation::Icap::Launcher::launchXaction(bool final)
35 {
36 Must(!theXaction);
37 ++theLaunches;
38 debugs(93,4, HERE << "launching xaction #" << theLaunches);
39 Adaptation::Icap::Xaction *x = createXaction();
40 if (final)
41 x->disableRetries();
42 theXaction = initiateAdaptation(x);
43 Must(theXaction);
44 }
45
46 void Adaptation::Icap::Launcher::noteAdaptationAnswer(HttpMsg *message)
47 {
48 sendAnswer(message);
49 clearAdaptation(theXaction);
50 Must(done());
51 debugs(93,3, HERE << "Adaptation::Icap::Launcher::noteAdaptationAnswer exiting ");
52 }
53
54 void Adaptation::Icap::Launcher::noteInitiatorAborted()
55 {
56
57 announceInitiatorAbort(theXaction); // propogate to the transaction
58 clearInitiator();
59 Must(done()); // should be nothing else to do
60
61 }
62
63 void Adaptation::Icap::Launcher::noteAdaptationQueryAbort(bool final)
64 {
65 clearAdaptation(theXaction);
66
67 // TODO: add more checks from FwdState::checkRetry()?
68 if (!final && theLaunches < 2 && !shutting_down) {
69 launchXaction(true);
70 } else {
71 debugs(93,3, HERE << "cannot retry the failed ICAP xaction; tries: " <<
72 theLaunches << "; final: " << final);
73 Must(done()); // swanSong will notify the initiator
74 }
75
76 }
77
78 bool Adaptation::Icap::Launcher::doneAll() const
79 {
80 return (!theInitiator || !theXaction) && Adaptation::Initiate::doneAll();
81 }
82
83 void Adaptation::Icap::Launcher::swanSong()
84 {
85 if (theInitiator)
86 tellQueryAborted(!service().cfg().bypass);
87
88 if (theXaction)
89 clearAdaptation(theXaction);
90
91 Adaptation::Initiate::swanSong();
92 }