]>
git.proxmox.com Git - ceph.git/blob - 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
4 * Ceph - scalable distributed file system
6 * Copyright (C) 2004-2006 Sage Weil <sage@newdream.net>
7 * Portions Copyright (C) 2013 CohortFS, LLC
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.
16 #ifndef SIMPLE_POLICY_MESSENGER_H
17 #define SIMPLE_POLICY_MESSENGER_H
19 #include "Messenger.h"
22 class SimplePolicyMessenger
: public Messenger
25 /// lock protecting policy
27 // entity_name_t::type -> Policy
28 ceph::net::PolicySet
<Throttle
> policy_set
;
32 SimplePolicyMessenger(CephContext
*cct
, entity_name_t name
,
33 string mname
, uint64_t _nonce
)
34 : Messenger(cct
, name
),
35 policy_lock("SimplePolicyMessenger::policy_lock")
40 * Get the Policy associated with a type of peer.
41 * @param t The peer type to get the default policy for.
43 * @return A const Policy reference.
45 Policy
get_policy(int t
) override
{
46 Mutex::Locker
l(policy_lock
);
47 return policy_set
.get(t
);
50 Policy
get_default_policy() override
{
51 Mutex::Locker
l(policy_lock
);
52 return policy_set
.get_default();
56 * Set a policy which is applied to all peers who do not have a type-specific
58 * This is an init-time function and cannot be called after calling
61 * @param p The Policy to apply.
63 void set_default_policy(Policy p
) override
{
64 Mutex::Locker
l(policy_lock
);
65 policy_set
.set_default(p
);
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
72 * @param type The peer type this policy applies to.
73 * @param p The policy to apply.
75 void set_policy(int type
, Policy p
) override
{
76 Mutex::Locker
l(policy_lock
);
77 policy_set
.set(type
, p
);
81 * Set a Throttler which is applied to all Messages from the given
83 * This is an init-time function and cannot be called after calling
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.
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
);
98 }; /* SimplePolicyMessenger */
100 #endif /* SIMPLE_POLICY_MESSENGER_H */