]>
Commit | Line | Data |
---|---|---|
7c673cae FG |
1 | // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*- |
2 | // vim: ts=8 sw=2 smarttab | |
3 | /* | |
4 | * Ceph - scalable distributed file system | |
5 | * | |
6 | * Copyright (C) 2004-2006 Sage Weil <sage@newdream.net> | |
7 | * Portions Copyright (C) 2013 CohortFS, LLC | |
8 | * | |
9 | * This is free software; you can redistribute it and/or | |
10 | * modify it under the terms of the GNU Lesser General Public | |
11 | * License version 2.1, as published by the Free Software | |
12 | * Foundation. See file COPYING. | |
13 | * | |
14 | */ | |
15 | ||
16 | #ifndef SIMPLE_POLICY_MESSENGER_H | |
17 | #define SIMPLE_POLICY_MESSENGER_H | |
18 | ||
19 | #include "Messenger.h" | |
11fdf7f2 | 20 | #include "Policy.h" |
7c673cae FG |
21 | |
22 | class SimplePolicyMessenger : public Messenger | |
23 | { | |
24 | private: | |
25 | /// lock protecting policy | |
9f95a23c TL |
26 | ceph::mutex policy_lock = |
27 | ceph::make_mutex("SimplePolicyMessenger::policy_lock"); | |
11fdf7f2 TL |
28 | // entity_name_t::type -> Policy |
29 | ceph::net::PolicySet<Throttle> policy_set; | |
7c673cae FG |
30 | |
31 | public: | |
32 | ||
9f95a23c TL |
33 | SimplePolicyMessenger(CephContext *cct, entity_name_t name) |
34 | : Messenger(cct, name) | |
7c673cae FG |
35 | { |
36 | } | |
37 | ||
38 | /** | |
39 | * Get the Policy associated with a type of peer. | |
40 | * @param t The peer type to get the default policy for. | |
41 | * | |
42 | * @return A const Policy reference. | |
43 | */ | |
44 | Policy get_policy(int t) override { | |
9f95a23c | 45 | std::lock_guard l{policy_lock}; |
11fdf7f2 | 46 | return policy_set.get(t); |
7c673cae FG |
47 | } |
48 | ||
49 | Policy get_default_policy() override { | |
9f95a23c | 50 | std::lock_guard l{policy_lock}; |
11fdf7f2 | 51 | return policy_set.get_default(); |
7c673cae FG |
52 | } |
53 | ||
54 | /** | |
55 | * Set a policy which is applied to all peers who do not have a type-specific | |
56 | * Policy. | |
57 | * This is an init-time function and cannot be called after calling | |
58 | * start() or bind(). | |
59 | * | |
60 | * @param p The Policy to apply. | |
61 | */ | |
62 | void set_default_policy(Policy p) override { | |
9f95a23c | 63 | std::lock_guard l{policy_lock}; |
11fdf7f2 | 64 | policy_set.set_default(p); |
7c673cae FG |
65 | } |
66 | /** | |
67 | * Set a policy which is applied to all peers of the given type. | |
68 | * This is an init-time function and cannot be called after calling | |
69 | * start() or bind(). | |
70 | * | |
71 | * @param type The peer type this policy applies to. | |
72 | * @param p The policy to apply. | |
73 | */ | |
74 | void set_policy(int type, Policy p) override { | |
9f95a23c | 75 | std::lock_guard l{policy_lock}; |
11fdf7f2 | 76 | policy_set.set(type, p); |
7c673cae FG |
77 | } |
78 | ||
79 | /** | |
80 | * Set a Throttler which is applied to all Messages from the given | |
81 | * type of peer. | |
82 | * This is an init-time function and cannot be called after calling | |
83 | * start() or bind(). | |
84 | * | |
85 | * @param type The peer type this Throttler will apply to. | |
9f95a23c | 86 | * @param t The Throttler to apply. The messenger does not take |
7c673cae | 87 | * ownership of this pointer, but you must not destroy it before |
9f95a23c | 88 | * you destroy messenger. |
7c673cae FG |
89 | */ |
90 | void set_policy_throttlers(int type, | |
11fdf7f2 TL |
91 | Throttle* byte_throttle, |
92 | Throttle* msg_throttle) override { | |
9f95a23c | 93 | std::lock_guard l{policy_lock}; |
11fdf7f2 | 94 | policy_set.set_throttlers(type, byte_throttle, msg_throttle); |
7c673cae FG |
95 | } |
96 | ||
97 | }; /* SimplePolicyMessenger */ | |
98 | ||
99 | #endif /* SIMPLE_POLICY_MESSENGER_H */ |