libbmq b6028b29b733bc7541593d2905a5f79a9f0192fc
Loading...
Searching...
No Matches
bmqt_queueoptions.h
Go to the documentation of this file.
1// Copyright 2015-2023 Bloomberg Finance L.P.
2// SPDX-License-Identifier: Apache-2.0
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// bmqt_queueoptions.h -*-C++-*-
17#ifndef INCLUDED_BMQT_QUEUEOPTIONS
18#define INCLUDED_BMQT_QUEUEOPTIONS
19
43
44// BMQ
45
46#include <bmqt_subscription.h>
47
48// BDE
49#include <bsl_iosfwd.h>
50#include <bsl_optional.h>
51#include <bsl_unordered_map.h>
52#include <bsl_utility.h>
53#include <bsl_vector.h>
54#include <bslma_allocator.h>
55#include <bslma_usesbslmaallocator.h>
56#include <bslmf_nestedtraitdeclaration.h>
57
58namespace BloombergLP {
59
60namespace bmqt {
61
62// ==================
63// class QueueOptions
64// ==================
65
68 public:
69 // PUBLIC CONSTANTS
70
72 static const int k_CONSUMER_PRIORITY_MIN;
73
75 static const int k_CONSUMER_PRIORITY_MAX;
76
81
82 private:
83 // PRIVATE TYPES
84 typedef bsl::unordered_map<SubscriptionHandle, Subscription> Subscriptions;
85
86 private:
87 // DATA
88 Subscription d_info;
89
91 bsl::optional<bool> d_suspendsOnBadHostHealth;
92
93 Subscriptions d_subscriptions;
94
97 bool d_hadSubscriptions;
98
100 bslma::Allocator* d_allocator_p;
101
102 public:
103 // PUBLIC TYPES
104
105 typedef bsl::pair<SubscriptionHandle, Subscription> HandleAndSubscription;
106
110 typedef bsl::vector<HandleAndSubscription> SubscriptionsSnapshot;
111
112 public:
113 // TRAITS
114 BSLMF_NESTED_TRAIT_DECLARATION(QueueOptions, bslma::UsesBslmaAllocator)
115
116 // CREATORS
117
118
120 explicit QueueOptions(bslma::Allocator* allocator = 0);
121
124 QueueOptions(const QueueOptions& other, bslma::Allocator* allocator = 0);
125
126 // MANIPULATORS
127
129 QueueOptions& operator=(const QueueOptions& rhs);
130
138
142
147
150
156
165 bool addOrUpdateSubscription(bsl::string* errorDescription,
166 const SubscriptionHandle& handle,
167 const Subscription& subscription);
168
173
178
179 // ACCESSORS
180
182 int maxUnconfirmedMessages() const;
183
185 int maxUnconfirmedBytes() const;
186
188 int consumerPriority() const;
189
191 bool suspendsOnBadHostHealth() const;
192
196 bool hasMaxUnconfirmedMessages() const;
197
200 bool hasMaxUnconfirmedBytes() const;
201
204 bool hasConsumerPriority() const;
205
209 bool hasSuspendsOnBadHostHealth() const;
210
214 bool loadSubscription(Subscription* subscription,
215 const SubscriptionHandle& handle) const;
216
221
231 bsl::ostream&
232 print(bsl::ostream& stream, int level = 0, int spacesPerLevel = 4) const;
233};
234
235// FREE OPERATORS
236
240bool operator==(const QueueOptions& lhs, const QueueOptions& rhs);
241
245bool operator!=(const QueueOptions& lhs, const QueueOptions& rhs);
246
249bsl::ostream& operator<<(bsl::ostream& stream, const QueueOptions& rhs);
250
251// ============================================================================
252// INLINE DEFINITIONS
253// ============================================================================
254
255// ------------------
256// class QueueOptions
257// ------------------
258
259// MANIPULATORS
260
261inline QueueOptions& QueueOptions::operator=(const QueueOptions& rhs)
262{
263 if (this != &rhs) {
264 d_info = rhs.d_info;
265 d_suspendsOnBadHostHealth = rhs.d_suspendsOnBadHostHealth;
266 d_hadSubscriptions = rhs.d_hadSubscriptions;
267 d_subscriptions = Subscriptions(rhs.d_subscriptions,
268 this->d_allocator_p);
269 }
270
271 return *this;
272}
273
275{
276 d_info.setMaxUnconfirmedMessages(value);
277 return *this;
278}
279
281{
282 d_info.setMaxUnconfirmedBytes(value);
283 return *this;
284}
285
287{
288 d_info.setConsumerPriority(value);
289 return *this;
290}
291
293{
294 d_suspendsOnBadHostHealth.emplace(value);
295 return *this;
296}
297
298// ACCESSORS
300{
301 return d_info.maxUnconfirmedMessages();
302}
303
305{
306 return d_info.maxUnconfirmedBytes();
307}
308
310{
311 return d_info.consumerPriority();
312}
313
315{
316 return d_suspendsOnBadHostHealth.value_or(
318}
319
321{
322 return d_info.hasMaxUnconfirmedMessages();
323}
324
326{
327 return d_info.hasMaxUnconfirmedBytes();
328}
329
331{
332 return d_info.hasConsumerPriority();
333}
334
336{
337 return d_suspendsOnBadHostHealth.has_value();
338}
339
340} // close package namespace
341
342// ------------------
343// class QueueOptions
344// ------------------
345
347 const bmqt::QueueOptions& rhs)
348{
349 return lhs.maxUnconfirmedMessages() == rhs.maxUnconfirmedMessages() &&
351 lhs.consumerPriority() == rhs.consumerPriority() &&
353}
354
356 const bmqt::QueueOptions& rhs)
357{
358 return lhs.maxUnconfirmedMessages() != rhs.maxUnconfirmedMessages() ||
360 lhs.consumerPriority() != rhs.consumerPriority() ||
362}
363
364inline bsl::ostream& bmqt::operator<<(bsl::ostream& stream,
365 const bmqt::QueueOptions& rhs)
366{
367 return rhs.print(stream, 0, -1);
368}
369
370} // close enterprise namespace
371
372#endif
Provide a value-semantic types for subscription related API.
Value-semantic type for options related to a queue.
Definition bmqt_queueoptions.h:67
bsl::ostream & print(bsl::ostream &stream, int level=0, int spacesPerLevel=4) const
static const bool k_DEFAULT_SUSPENDS_ON_BAD_HOST_HEALTH
Definition bmqt_queueoptions.h:80
QueueOptions & setMaxUnconfirmedBytes(int value)
Definition bmqt_queueoptions.h:280
int maxUnconfirmedMessages() const
Get the number for the maxUnconfirmedMessages parameter.
Definition bmqt_queueoptions.h:299
bool hasConsumerPriority() const
Definition bmqt_queueoptions.h:330
int maxUnconfirmedBytes() const
Get the number for the maxUnconfirmedBytes parameter.
Definition bmqt_queueoptions.h:304
QueueOptions & setConsumerPriority(int value)
Definition bmqt_queueoptions.h:286
bool suspendsOnBadHostHealth() const
Get whether the queue suspends operation while host is unhealthy.
Definition bmqt_queueoptions.h:314
QueueOptions & setSuspendsOnBadHostHealth(bool value)
Set whether the queue suspends operation while host is unhealthy.
Definition bmqt_queueoptions.h:292
bool loadSubscription(Subscription *subscription, const SubscriptionHandle &handle) const
bool hasMaxUnconfirmedMessages() const
Definition bmqt_queueoptions.h:320
QueueOptions & setMaxUnconfirmedMessages(int value)
Definition bmqt_queueoptions.h:274
bsl::pair< SubscriptionHandle, Subscription > HandleAndSubscription
Definition bmqt_queueoptions.h:105
static const int k_CONSUMER_PRIORITY_MIN
Constant representing the minimum valid consumer priority.
Definition bmqt_queueoptions.h:72
static const int k_CONSUMER_PRIORITY_MAX
Constant representing the maximum valid consumer priority.
Definition bmqt_queueoptions.h:75
static const int k_DEFAULT_MAX_UNCONFIRMED_MESSAGES
Definition bmqt_queueoptions.h:77
void loadSubscriptions(SubscriptionsSnapshot *snapshot) const
bool removeSubscription(const SubscriptionHandle &handle)
int consumerPriority() const
Get the number for the consumerPriority parameter.
Definition bmqt_queueoptions.h:309
QueueOptions & merge(const QueueOptions &other)
bool addOrUpdateSubscription(bsl::string *errorDescription, const SubscriptionHandle &handle, const Subscription &subscription)
bool hasMaxUnconfirmedBytes() const
Definition bmqt_queueoptions.h:325
bool hasSuspendsOnBadHostHealth() const
Definition bmqt_queueoptions.h:335
bsl::vector< HandleAndSubscription > SubscriptionsSnapshot
Definition bmqt_queueoptions.h:110
static const int k_DEFAULT_CONSUMER_PRIORITY
Definition bmqt_queueoptions.h:79
static const int k_DEFAULT_MAX_UNCONFIRMED_BYTES
Definition bmqt_queueoptions.h:78
Value-semantic type for unique Subscription id.
Definition bmqt_subscription.h:59
Value-semantic type to carry Subscription parameters.
Definition bmqt_subscription.h:169
bool hasMaxUnconfirmedBytes() const
Definition bmqt_subscription.h:469
bool hasMaxUnconfirmedMessages() const
Definition bmqt_subscription.h:464
Subscription & setConsumerPriority(int value)
Definition bmqt_subscription.h:429
int consumerPriority() const
Get the number for the consumerPriority parameter.
Definition bmqt_subscription.h:454
Subscription & setMaxUnconfirmedBytes(int value)
Definition bmqt_subscription.h:423
Subscription & setMaxUnconfirmedMessages(int value)
Definition bmqt_subscription.h:417
int maxUnconfirmedMessages() const
Get the number for the maxUnconfirmedMessages parameter.
Definition bmqt_subscription.h:443
int maxUnconfirmedBytes() const
Get the number for the maxUnconfirmedBytes parameter.
Definition bmqt_subscription.h:449
bool hasConsumerPriority() const
Definition bmqt_subscription.h:474
bsl::ostream & operator<<(bsl::ostream &stream, CompressionAlgorithmType::Enum value)
Definition bmqt_compressionalgorithmtype.h:141
bool operator!=(const CorrelationId &lhs, const CorrelationId &rhs)
Definition bmqt_correlationid.h:582
bool operator==(const CorrelationId &lhs, const CorrelationId &rhs)
Definition bmqt_correlationid.h:576
Definition bmqa_abstractsession.h:42