]>
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
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
;
33 SimplePolicyMessenger(CephContext
*cct
, entity_name_t name
)
34 : Messenger(cct
, name
)
39 * Get the Policy associated with a type of peer.
40 * @param t The peer type to get the default policy for.
42 * @return A const Policy reference.
44 Policy
get_policy(int t
) override
{
45 std::lock_guard l
{policy_lock
};
46 return policy_set
.get(t
);
49 Policy
get_default_policy() override
{
50 std::lock_guard l
{policy_lock
};
51 return policy_set
.get_default();
55 * Set a policy which is applied to all peers who do not have a type-specific
57 * This is an init-time function and cannot be called after calling
60 * @param p The Policy to apply.
62 void set_default_policy(Policy p
) override
{
63 std::lock_guard l
{policy_lock
};
64 policy_set
.set_default(p
);
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
71 * @param type The peer type this policy applies to.
72 * @param p The policy to apply.
74 void set_policy(int type
, Policy p
) override
{
75 std::lock_guard l
{policy_lock
};
76 policy_set
.set(type
, p
);
80 * Set a Throttler which is applied to all Messages from the given
82 * This is an init-time function and cannot be called after calling
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.
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
);
97 }; /* SimplePolicyMessenger */
99 #endif /* SIMPLE_POLICY_MESSENGER_H */