]> git.proxmox.com Git - ceph.git/blob - ceph/src/msg/SimplePolicyMessenger.h
update sources to ceph Nautilus 14.2.1
[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 Mutex policy_lock;
27 // entity_name_t::type -> Policy
28 ceph::net::PolicySet<Throttle> policy_set;
29
30 public:
31
32 SimplePolicyMessenger(CephContext *cct, entity_name_t name,
33 string mname, uint64_t _nonce)
34 : Messenger(cct, name),
35 policy_lock("SimplePolicyMessenger::policy_lock")
36 {
37 }
38
39 /**
40 * Get the Policy associated with a type of peer.
41 * @param t The peer type to get the default policy for.
42 *
43 * @return A const Policy reference.
44 */
45 Policy get_policy(int t) override {
46 Mutex::Locker l(policy_lock);
47 return policy_set.get(t);
48 }
49
50 Policy get_default_policy() override {
51 Mutex::Locker l(policy_lock);
52 return policy_set.get_default();
53 }
54
55 /**
56 * Set a policy which is applied to all peers who do not have a type-specific
57 * Policy.
58 * This is an init-time function and cannot be called after calling
59 * start() or bind().
60 *
61 * @param p The Policy to apply.
62 */
63 void set_default_policy(Policy p) override {
64 Mutex::Locker l(policy_lock);
65 policy_set.set_default(p);
66 }
67 /**
68 * Set a policy which is applied to all peers of the given type.
69 * This is an init-time function and cannot be called after calling
70 * start() or bind().
71 *
72 * @param type The peer type this policy applies to.
73 * @param p The policy to apply.
74 */
75 void set_policy(int type, Policy p) override {
76 Mutex::Locker l(policy_lock);
77 policy_set.set(type, p);
78 }
79
80 /**
81 * Set a Throttler which is applied to all Messages from the given
82 * type of peer.
83 * This is an init-time function and cannot be called after calling
84 * start() or bind().
85 *
86 * @param type The peer type this Throttler will apply to.
87 * @param t The Throttler to apply. SimpleMessenger does not take
88 * ownership of this pointer, but you must not destroy it before
89 * you destroy SimpleMessenger.
90 */
91 void set_policy_throttlers(int type,
92 Throttle* byte_throttle,
93 Throttle* msg_throttle) override {
94 Mutex::Locker l(policy_lock);
95 policy_set.set_throttlers(type, byte_throttle, msg_throttle);
96 }
97
98 }; /* SimplePolicyMessenger */
99
100 #endif /* SIMPLE_POLICY_MESSENGER_H */