Hazelcast C++ Client
Hazelcast C++ Client Library
lifecycle_listener.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 <functional>
19 
20 #include "hazelcast/util/export.h"
21 #include "hazelcast/util/noop.h"
22 #include "hazelcast/util/type_traits.h"
23 
24 #if defined(WIN32) || defined(_WIN32) || defined(WIN64) || defined(_WIN64)
25 #pragma warning(push)
26 #pragma warning(disable: 4251) //for dll export
27 #endif
28 
29 namespace hazelcast {
30  namespace client {
31  class lifecycle_event;
32  namespace spi {
33  class lifecycle_service;
34  }
35 
48  class HAZELCAST_API lifecycle_listener final {
49  public:
55  template<typename Handler,
56  typename = util::enable_if_rvalue_ref_t<Handler &&>>
57  lifecycle_listener &on_starting(Handler &&h) & {
58  starting_ = std::forward<Handler>(h);
59  return *this;
60  }
61 
65  template<typename Handler,
66  typename = util::enable_if_rvalue_ref_t<Handler &&>>
67  lifecycle_listener &&on_starting(Handler &&h) && {
68  on_starting(std::forward<Handler>(h));
69  return std::move(*this);
70  }
71 
77  template<typename Handler,
78  typename = util::enable_if_rvalue_ref_t<Handler &&>>
79  lifecycle_listener &on_started(Handler &&h) & {
80  started_ = std::forward<Handler>(h);
81  return *this;
82  }
83 
87  template<typename Handler,
88  typename = util::enable_if_rvalue_ref_t<Handler &&>>
89  lifecycle_listener &&on_started(Handler &&h) && {
90  on_started(std::forward<Handler>(h));
91  return std::move(*this);
92  }
93 
99  template<typename Handler,
100  typename = util::enable_if_rvalue_ref_t<Handler &&>>
102  shutting_down_ = std::forward<Handler>(h);
103  return *this;
104  }
105 
109  template<typename Handler,
110  typename = util::enable_if_rvalue_ref_t<Handler &&>>
112  on_shutting_down(std::forward<Handler>(h));
113  return std::move(*this);
114  }
115 
121  template<typename Handler,
122  typename = util::enable_if_rvalue_ref_t<Handler &&>>
123  lifecycle_listener &on_shutdown(Handler &&h) & {
124  shutdown_ = std::forward<Handler>(h);
125  return *this;
126  }
127 
131  template<typename Handler,
132  typename = util::enable_if_rvalue_ref_t<Handler &&>>
133  lifecycle_listener &&on_shutdown(Handler &&h) && {
134  on_shutdown(std::forward<Handler>(h));
135  return std::move(*this);
136  }
137 
143  template<typename Handler,
144  typename = util::enable_if_rvalue_ref_t<Handler &&>>
146  connected_ = std::forward<Handler>(h);
147  return *this;
148  }
149 
153  template<typename Handler,
154  typename = util::enable_if_rvalue_ref_t<Handler &&>>
155  lifecycle_listener &&on_connected(Handler &&h) && {
156  on_connected(std::forward<Handler>(h));
157  return std::move(*this);
158  }
159 
165  template<typename Handler,
166  typename = util::enable_if_rvalue_ref_t<Handler &&>>
168  disconnected_ = std::forward<Handler>(h);
169  return *this;
170  }
171 
175  template<typename Handler,
176  typename = util::enable_if_rvalue_ref_t<Handler &&>>
178  on_disconnected(std::forward<Handler>(h));
179  return std::move(*this);
180  }
181 
182  private:
183  using HandlerType = std::function<void()>;
184  HandlerType starting_{ util::noop<> },
185  started_{ util::noop<> },
186  shutting_down_{ util::noop<> },
187  shutdown_{ util::noop<> },
188  connected_{ util::noop<> },
189  disconnected_{ util::noop<> };
190 
191  friend class spi::lifecycle_service;
192  };
193  }
194 }
195 
196 #if defined(WIN32) || defined(_WIN32) || defined(WIN64) || defined(_WIN64)
197 #pragma warning(pop)
198 #endif
199 
200 
201 
Listener object for listening lifecycle events of hazelcast instance.
lifecycle_listener & on_shutdown(Handler &&h) &
Set an handler function to be invoked when the client's shutdown has completed.
lifecycle_listener && on_disconnected(Handler &&h) &&
Set an handler function to be invoked when client is disconnected from the cluster.
lifecycle_listener & on_started(Handler &&h) &
Set an handler function to be invoked when the client has started.
lifecycle_listener && on_connected(Handler &&h) &&
Set an handler function to be invoked when the client is connected to the cluster.
lifecycle_listener && on_shutdown(Handler &&h) &&
Set an handler function to be invoked when the client's shutdown has completed.
lifecycle_listener && on_shutting_down(Handler &&h) &&
Set an handler function to be invoked when the client is shutting down.
lifecycle_listener && on_started(Handler &&h) &&
Set an handler function to be invoked when the client has started.
lifecycle_listener & on_connected(Handler &&h) &
Set an handler function to be invoked when the client is connected to the cluster.
lifecycle_listener & on_starting(Handler &&h) &
Set an handler function to be invoked when the client is starting.
lifecycle_listener & on_disconnected(Handler &&h) &
Set an handler function to be invoked when client is disconnected from the cluster.
lifecycle_listener && on_starting(Handler &&h) &&
Set an handler function to be invoked when the client is starting.
lifecycle_listener & on_shutting_down(Handler &&h) &
Set an handler function to be invoked when the client is shutting down.