2828
2929#include < bdlmt_threadpool.h>
3030#include < bsl_memory.h>
31+ #include < bsl_optional.h>
3132#include < bsl_set.h>
33+ #include < bsl_variant.h>
3234#include < bsls_timeinterval.h>
3335
3436namespace BloombergLP {
@@ -44,6 +46,30 @@ class RabbitContextOptions {
4446 public:
4547 typedef bsl::set<bsl::string> Tunables;
4648
49+ // / \brief Tag type expressing no host health preference: it neither opts in
50+ // / nor opts out, leaving the choice to enclosing configuration layers. This
51+ // / is the alternative held by a default-constructed \c HostHealthSelection
52+ // / (the default). See \c setHostHealthSelection.
53+ struct HostHealthAwarenessUnset {};
54+
55+ // / \brief Tag type selecting an explicit opt-out from host health
56+ // / awareness; see \c setHostHealthSelection. Selecting it is distinct from
57+ // / leaving the host health selection unset (\c HostHealthAwarenessUnset),
58+ // / which expresses no preference and lets enclosing configuration layers
59+ // / apply their own policy.
60+ struct HostHealthAwarenessOff {};
61+
62+ // / \brief A caller's host health selection: exactly one of three mutually
63+ // / exclusive alternatives -- \c HostHealthAwarenessUnset (no preference;
64+ // / the default), \c rmqt::HostHealthConfig (opt-in; monitoring runs), or
65+ // / \c HostHealthAwarenessOff (explicit opt-out). A default-constructed
66+ // / selection holds \c HostHealthAwarenessUnset. See
67+ // / \c setHostHealthSelection.
68+ typedef bsl::variant<HostHealthAwarenessUnset,
69+ rmqt::HostHealthConfig,
70+ HostHealthAwarenessOff>
71+ HostHealthSelection;
72+
4773 // / \brief By Default RabbitContext will
4874 // / 1) Create it's own threadpool for
4975 // / calling back to client code e.g. consuming messages, confirming
@@ -177,9 +203,25 @@ class RabbitContextOptions {
177203 // / config is not set, \c consumeOnlyFromHealthyHost has no effect.
178204 // /
179205 // / \param hostHealthConfig configuration for host health monitoring
206+ // /
207+ // / \note This is a convenience equivalent to \c setHostHealthSelection with
208+ // / a \c HostHealthConfig: selecting a config is what causes the monitor to
209+ // / run, and it replaces any prior opt-out selection. Leaving the selection
210+ // / unset (the default) expresses no preference.
180211 RabbitContextOptions&
181212 setHostHealthConfig (const rmqt::HostHealthConfig& hostHealthConfig);
182213
214+ // / \brief Set the caller's host health selection: a \c HostHealthConfig to
215+ // / opt in (monitoring runs) or \c HostHealthAwarenessOff to explicitly
216+ // / opt out (no monitor is created even if a config could otherwise be
217+ // / attached). The alternatives are mutually exclusive -- this replaces any
218+ // / previously set config or opt-out. Not calling this at all leaves the
219+ // / selection unset (the default), which expresses no preference and lets
220+ // / enclosing configuration layers apply their own policy.
221+ // / \param selection the host health selection
222+ RabbitContextOptions&
223+ setHostHealthSelection (const HostHealthSelection& selection);
224+
183225 bdlmt::ThreadPool* threadpool () const { return d_threadpool; }
184226
185227 const bsl::shared_ptr<rmqp::MetricPublisher>& metricPublisher () const
@@ -227,32 +269,38 @@ class RabbitContextOptions {
227269 return d_shuffleConnectionEndpoints;
228270 }
229271
230- // / \brief Get the host health config. If not set, host health monitoring is
231- // / disabled. By default, host health monitoring is disabled.
232- // / \return The host health config
233- const bsl::optional<rmqt::HostHealthConfig>& hostHealthConfig () const
272+ // / \brief Get the caller's host health selection. The returned variant
273+ // / holds \c HostHealthAwarenessUnset when no preference has been expressed
274+ // / (the default), a \c rmqt::HostHealthConfig when opted in (via
275+ // / \c setHostHealthSelection or \c setHostHealthConfig), or a
276+ // / \c HostHealthAwarenessOff when explicitly opted out.
277+ // / \return The host health selection
278+ const HostHealthSelection& hostHealthSelection () const
234279 {
235- return d_hostHealthConfig ;
280+ return d_hostHealthSelection ;
236281 }
237282
238283#ifdef USES_LIBRMQ_EXPERIMENTAL_FEATURES
239284 RabbitContextOptions& setTunable (const bsl::string& tunable);
240285#endif
241286
242287 private:
288+ // Members are ordered to minimize padding (see
289+ // clang-analyzer-optin.performance.Padding), not by logical grouping. The
290+ // constructor's initializer list mirrors this order to avoid -Wreorder.
243291 static const int DEFAULT_MESSAGE_PROCESSING_TIMEOUT = 60 ;
244- bdlmt::ThreadPool* d_threadpool;
245292 rmqt::ErrorCallback d_onError;
293+ HostHealthSelection d_hostHealthSelection;
294+ bdlmt::ThreadPool* d_threadpool;
246295 bsl::shared_ptr<rmqp::MetricPublisher> d_metricPublisher;
247- rmqt::FieldTable d_clientProperties;
248296 bsls::TimeInterval d_messageProcessingTimeout;
249- rmqt::Tunables d_tunables;
250- bsl::optional<bsls::TimeInterval> d_connectionErrorThreshold;
251- bsl::optional<bsls::TimeInterval> d_connectionEstablishmentTimeout;
252297 bsl::shared_ptr<rmqp::ConsumerTracing> d_consumerTracing;
253298 bsl::shared_ptr<rmqp::ProducerTracing> d_producerTracing;
299+ bsl::optional<bsls::TimeInterval> d_connectionErrorThreshold;
300+ bsl::optional<bsls::TimeInterval> d_connectionEstablishmentTimeout;
301+ rmqt::FieldTable d_clientProperties;
302+ rmqt::Tunables d_tunables;
254303 bsl::optional<bool > d_shuffleConnectionEndpoints;
255- bsl::optional<rmqt::HostHealthConfig> d_hostHealthConfig;
256304};
257305
258306} // namespace rmqa
0 commit comments