]> git.proxmox.com Git - ceph.git/blob - ceph/src/msg/SimplePolicyMessenger.h
import quincy beta 17.1.0
[ceph.git] / ceph / src / msg / SimplePolicyMessenger.h
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"
20 #include "Policy.h"
21
22 class SimplePolicyMessenger : public Messenger
23 {
24 private:
25 /// lock protecting policy
26 ceph::mutex policy_lock =
27 ceph::make_mutex("SimplePolicyMessenger::policy_lock");
28 // entity_name_t::type -> Policy
29 ceph::net::PolicySet<Throttle> policy_set;
30
31 public:
32
33 SimplePolicyMessenger(CephContext *cct, entity_name_t name)
34 : Messenger(cct, name)
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 {
45 std::lock_guard l{policy_lock};
46 return policy_set.get(t);
47 }
48
49 Policy get_default_policy() override {
50 std::lock_guard l{policy_lock};
51 return policy_set.get_default();
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 {
63 std::lock_guard l{policy_lock};
64 policy_set.set_default(p);
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 {
75 std::lock_guard l{policy_lock};
76 policy_set.set(type, p);
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.
86 * @param t The Throttler to apply. The messenger does not take
87 * ownership of this pointer, but you must not destroy it before
88 * you destroy messenger.
89 */
90 void set_policy_throttlers(int type,
91 Throttle* byte_throttle,
92 Throttle* msg_throttle) override {
93 std::lock_guard l{policy_lock};
94 policy_set.set_throttlers(type, byte_throttle, msg_throttle);
95 }
96
97 }; /* SimplePolicyMessenger */
98
99 #endif /* SIMPLE_POLICY_MESSENGER_H */