]>
Commit | Line | Data |
---|---|---|
a68cf076 | 1 | /* |
b510f3a1 | 2 | * DEBUG: section 93 Adaptation |
a68cf076 AR |
3 | */ |
4 | ||
582c2af2 | 5 | #include "squid.h" |
a68cf076 | 6 | #include "adaptation/Service.h" |
602d9612 A |
7 | #include "adaptation/ServiceFilter.h" |
8 | #include "HttpRequest.h" | |
a68cf076 | 9 | |
6666da11 | 10 | Adaptation::Service::Service(const ServiceConfigPointer &aConfig): theConfig(aConfig) |
a5c0ca41 | 11 | { |
e1e90d26 AR |
12 | Must(theConfig != NULL); |
13 | debugs(93,3, HERE << "creating adaptation service " << cfg().key); | |
a5c0ca41 | 14 | } |
a68cf076 AR |
15 | |
16 | Adaptation::Service::~Service() | |
17 | {} | |
18 | ||
62c7f90e | 19 | void |
d81a31f1 | 20 | Adaptation::Service::finalize() |
a68cf076 | 21 | { |
62c7f90e AR |
22 | } |
23 | ||
201438ac AR |
24 | bool Adaptation::Service::broken() const |
25 | { | |
26 | return probed() && !up(); | |
27 | } | |
28 | ||
a22e6cd3 AR |
29 | bool |
30 | Adaptation::Service::wants(const ServiceFilter &filter) const | |
31 | { | |
32 | if (cfg().method != filter.method) | |
33 | return false; | |
34 | ||
35 | if (cfg().point != filter.point) | |
36 | return false; | |
37 | ||
38 | // sending a message to a broken service is likely to cause errors | |
39 | if (cfg().bypass && broken()) | |
40 | return false; | |
41 | ||
42 | if (up()) { | |
43 | // Sending a message to a service that does not want it is useless. | |
44 | // note that we cannot check wantsUrl for service that is not "up" | |
45 | // note that even essential services are skipped on unwanted URLs! | |
46 | return wantsUrl(filter.request->urlpath); | |
47 | } | |
48 | ||
49 | // The service is down and is either not bypassable or not probed due | |
50 | // to the bypass && broken() test above. Thus, we want to use it! | |
51 | return true; | |
52 | } | |
53 | ||
62c7f90e AR |
54 | Adaptation::Services & |
55 | Adaptation::AllServices() | |
56 | { | |
28b58ffc CT |
57 | static Services *TheServices = new Services; |
58 | return *TheServices; | |
62c7f90e AR |
59 | } |
60 | ||
61 | Adaptation::ServicePointer | |
62 | Adaptation::FindService(const Service::Id& key) | |
63 | { | |
64 | typedef Services::iterator SI; | |
65 | for (SI i = AllServices().begin(); i != AllServices().end(); ++i) { | |
66 | if ((*i)->cfg().key == key) | |
67 | return *i; | |
26ac0430 | 68 | } |
62c7f90e | 69 | return NULL; |
a68cf076 | 70 | } |
76fc7e57 AJ |
71 | |
72 | void Adaptation::DetachServices() | |
73 | { | |
38c22baf FC |
74 | while (!AllServices().empty()) { |
75 | AllServices().back()->detach(); | |
76 | AllServices().pop_back(); | |
77 | } | |
76fc7e57 | 78 | } |