Hazelcast C++ Client
Hazelcast C++ Client Library
load_balancer.h
1 /*
2  * Copyright (c) 2008-2021, Hazelcast, Inc. All Rights Reserved.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 #pragma once
17 
18 #include "hazelcast/util/export.h"
19 #include "hazelcast/client/member.h"
20 
21 namespace hazelcast {
22  namespace client {
23 
24  class cluster;
25 
26  namespace connection { class ClientConnectionManagerImpl; }
27 
37  class HAZELCAST_API load_balancer final {
38  public:
45  template<typename Handler,
46  typename = util::enable_if_rvalue_ref_t<Handler &&>>
47  load_balancer &init(Handler &&h) & {
48  init_ = std::forward<Handler>(h);
49  return *this;
50  }
51 
52  template<typename Handler,
53  typename = util::enable_if_rvalue_ref_t<Handler &&>>
54  load_balancer &&init(Handler &&h) && {
55  init_ = std::forward<Handler>(h);
56  return std::move(*this);
57  }
58 
64  template<typename Handler,
65  typename = util::enable_if_rvalue_ref_t<Handler &&>>
66  load_balancer &next(Handler &&h) & {
67  next_ = std::forward<Handler>(h);
68  return *this;
69  }
70 
71  template<typename Handler,
72  typename = util::enable_if_rvalue_ref_t<Handler &&>>
73  load_balancer &&next(Handler &&h) && {
74  next_ = std::forward<Handler>(h);
75  return std::move(*this);
76  }
77 
78  private:
83  std::function<void(cluster &)> init_ = util::noop<cluster &>;
84  std::function<boost::optional<member>(cluster &)> next_ = [](cluster &) { return boost::none; };
85 
86  friend class connection::ClientConnectionManagerImpl;
87  };
88  }
89 }
90 
91 
92 
load_balancer allows you to send operations to one of a number of endpoints(Members).
Definition: load_balancer.h:37
load_balancer & init(Handler &&h) &
Sets the function to be called when load balancer is initialized.
Definition: load_balancer.h:47
load_balancer & next(Handler &&h) &
The function returns the next member to route to.
Definition: load_balancer.h:66