Hazelcast C++ Client
Hazelcast C++ Client Library
load_balancer.h
1 /*
2  * Copyright (c) 2008-2022, 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 {
27 class ClientConnectionManagerImpl;
28 }
29 
40 class HAZELCAST_API load_balancer final
41 {
42 public:
50  template<typename Handler,
51  typename = util::enable_if_rvalue_ref_trait<Handler&&>>
52  load_balancer& init(Handler&& h) &
53  {
54  init_ = std::forward<Handler>(h);
55  return *this;
56  }
57 
58  template<typename Handler,
59  typename = util::enable_if_rvalue_ref_trait<Handler&&>>
60  load_balancer&& init(Handler&& h) &&
61  {
62  init_ = std::forward<Handler>(h);
63  return std::move(*this);
64  }
65 
71  template<typename Handler,
72  typename = util::enable_if_rvalue_ref_trait<Handler&&>>
73  load_balancer& next(Handler&& h) &
74  {
75  next_ = std::forward<Handler>(h);
76  return *this;
77  }
78 
79  template<typename Handler,
80  typename = util::enable_if_rvalue_ref_trait<Handler&&>>
81  load_balancer&& next(Handler&& h) &&
82  {
83  next_ = std::forward<Handler>(h);
84  return std::move(*this);
85  }
86 
87 private:
92  std::function<void(cluster&)> init_ = util::noop<cluster&>;
93  std::function<boost::optional<member>(cluster&)> next_ = [](cluster&) {
94  return boost::none;
95  };
96 
97  friend class connection::ClientConnectionManagerImpl;
98 };
99 } // namespace client
100 } // namespace hazelcast
load_balancer allows you to send operations to one of a number of endpoints(Members).
Definition: load_balancer.h:41
load_balancer & init(Handler &&h) &
Sets the function to be called when load balancer is initialized.
Definition: load_balancer.h:52
load_balancer & next(Handler &&h) &
The function returns the next member to route to.
Definition: load_balancer.h:73