libbmq c4a007c57a1a5adffde5d4555e9831b318cfb97d
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
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_vector.h>
53#include <bslma_allocator.h>
54#include <bslma_usesbslmaallocator.h>
55#include <bslmf_nestedtraitdeclaration.h>
56
57namespace BloombergLP {
58
59namespace bmqt {
60
61// ==================
62// class QueueOptions
63// ==================
64
67 public:
68 // PUBLIC CONSTANTS
69
71 static const int k_CONSUMER_PRIORITY_MIN;
72
74 static const int k_CONSUMER_PRIORITY_MAX;
75
80
81 private:
82 // PRIVATE TYPES
83 typedef bsl::unordered_map<SubscriptionHandle, Subscription> Subscriptions;
84
85 private:
86 // DATA
87 Subscription d_info;
88
90 bsl::optional<bool> d_suspendsOnBadHostHealth;
91
92 Subscriptions d_subscriptions;
93
96 bool d_hadSubscriptions;
97
99 bslma::Allocator* d_allocator_p;
100
101 public:
102 // PUBLIC TYPES
103
104 typedef bsl::pair<SubscriptionHandle, Subscription> HandleAndSubscription;
105
109 typedef bsl::vector<HandleAndSubscription> SubscriptionsSnapshot;
110
111 public:
112 // TRAITS
113 BSLMF_NESTED_TRAIT_DECLARATION(QueueOptions, bslma::UsesBslmaAllocator)
114
115 // CREATORS
116
117
119 explicit QueueOptions(bslma::Allocator* allocator = 0);
120
123 QueueOptions(const QueueOptions& other, bslma::Allocator* allocator = 0);
124
125 // MANIPULATORS
126
128 QueueOptions& operator=(const QueueOptions& rhs);
129
137
141
146
149
155
164 bool addOrUpdateSubscription(bsl::string* errorDescription,
165 const SubscriptionHandle& handle,
166 const Subscription& subscription);
167
172
177
178 // ACCESSORS
179
181 int maxUnconfirmedMessages() const;
182
184 int maxUnconfirmedBytes() const;
185
187 int consumerPriority() const;
188
190 bool suspendsOnBadHostHealth() const;
191
195 bool hasMaxUnconfirmedMessages() const;
196
199 bool hasMaxUnconfirmedBytes() const;
200
203 bool hasConsumerPriority() const;
204
208 bool hasSuspendsOnBadHostHealth() const;
209
213 bool loadSubscription(Subscription* subscription,
214 const SubscriptionHandle& handle) const;
215
220
230 bsl::ostream&
231 print(bsl::ostream& stream, int level = 0, int spacesPerLevel = 4) const;
232};
233
234// FREE OPERATORS
235
239bool operator==(const QueueOptions& lhs, const QueueOptions& rhs);
240
244bool operator!=(const QueueOptions& lhs, const QueueOptions& rhs);
245
248bsl::ostream& operator<<(bsl::ostream& stream, const QueueOptions& rhs);
249
250// ============================================================================
251// INLINE DEFINITIONS
252// ============================================================================
253
254// ------------------
255// class QueueOptions
256// ------------------
257
258// MANIPULATORS
259
260inline QueueOptions& QueueOptions::operator=(const QueueOptions& rhs)
261{
262 if (this != &rhs) {
263 d_info = rhs.d_info;
264 d_suspendsOnBadHostHealth = rhs.d_suspendsOnBadHostHealth;
265 d_hadSubscriptions = rhs.d_hadSubscriptions;
266 d_subscriptions = Subscriptions(rhs.d_subscriptions,
267 this->d_allocator_p);
268 }
269
270 return *this;
271}
272
274{
275 d_info.setMaxUnconfirmedMessages(value);
276 return *this;
277}
278
280{
281 d_info.setMaxUnconfirmedBytes(value);
282 return *this;
283}
284
286{
287 d_info.setConsumerPriority(value);
288 return *this;
289}
290
292{
293 d_suspendsOnBadHostHealth.emplace(value);
294 return *this;
295}
296
297// ACCESSORS
299{
300 return d_info.maxUnconfirmedMessages();
301}
302
304{
305 return d_info.maxUnconfirmedBytes();
306}
307
309{
310 return d_info.consumerPriority();
311}
312
314{
315 return d_suspendsOnBadHostHealth.value_or(
317}
318
320{
321 return d_info.hasMaxUnconfirmedMessages();
322}
323
325{
326 return d_info.hasMaxUnconfirmedBytes();
327}
328
330{
331 return d_info.hasConsumerPriority();
332}
333
335{
336 return d_suspendsOnBadHostHealth.has_value();
337}
338
339} // close package namespace
340
341// ------------------
342// class QueueOptions
343// ------------------
344
346 const bmqt::QueueOptions& rhs)
347{
348 return lhs.maxUnconfirmedMessages() == rhs.maxUnconfirmedMessages() &&
350 lhs.consumerPriority() == rhs.consumerPriority() &&
352}
353
355 const bmqt::QueueOptions& rhs)
356{
357 return lhs.maxUnconfirmedMessages() != rhs.maxUnconfirmedMessages() ||
359 lhs.consumerPriority() != rhs.consumerPriority() ||
361}
362
363inline bsl::ostream& bmqt::operator<<(bsl::ostream& stream,
364 const bmqt::QueueOptions& rhs)
365{
366 return rhs.print(stream, 0, -1);
367}
368
369} // close enterprise namespace
370
371#endif
Provide a value-semantic types for subscription related API.
Value-semantic type for options related to a queue.
Definition bmqt_queueoptions.h:66
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:79
QueueOptions & setMaxUnconfirmedBytes(int value)
Definition bmqt_queueoptions.h:279
int maxUnconfirmedMessages() const
Get the number for the maxUnconfirmedMessages parameter.
Definition bmqt_queueoptions.h:298
bool hasConsumerPriority() const
Definition bmqt_queueoptions.h:329
int maxUnconfirmedBytes() const
Get the number for the maxUnconfirmedBytes parameter.
Definition bmqt_queueoptions.h:303
QueueOptions & setConsumerPriority(int value)
Definition bmqt_queueoptions.h:285
bool suspendsOnBadHostHealth() const
Get whether the queue suspends operation while host is unhealthy.
Definition bmqt_queueoptions.h:313
QueueOptions & setSuspendsOnBadHostHealth(bool value)
Set whether the queue suspends operation while host is unhealthy.
Definition bmqt_queueoptions.h:291
bool loadSubscription(Subscription *subscription, const SubscriptionHandle &handle) const
bool hasMaxUnconfirmedMessages() const
Definition bmqt_queueoptions.h:319
QueueOptions & setMaxUnconfirmedMessages(int value)
Definition bmqt_queueoptions.h:273
bsl::pair< SubscriptionHandle, Subscription > HandleAndSubscription
Definition bmqt_queueoptions.h:104
static const int k_CONSUMER_PRIORITY_MIN
Constant representing the minimum valid consumer priority.
Definition bmqt_queueoptions.h:71
static const int k_CONSUMER_PRIORITY_MAX
Constant representing the maximum valid consumer priority.
Definition bmqt_queueoptions.h:74
static const int k_DEFAULT_MAX_UNCONFIRMED_MESSAGES
Definition bmqt_queueoptions.h:76
void loadSubscriptions(SubscriptionsSnapshot *snapshot) const
bool removeSubscription(const SubscriptionHandle &handle)
int consumerPriority() const
Get the number for the consumerPriority parameter.
Definition bmqt_queueoptions.h:308
QueueOptions & merge(const QueueOptions &other)
bool addOrUpdateSubscription(bsl::string *errorDescription, const SubscriptionHandle &handle, const Subscription &subscription)
bool hasMaxUnconfirmedBytes() const
Definition bmqt_queueoptions.h:324
bool hasSuspendsOnBadHostHealth() const
Definition bmqt_queueoptions.h:334
bsl::vector< HandleAndSubscription > SubscriptionsSnapshot
Definition bmqt_queueoptions.h:109
static const int k_DEFAULT_CONSUMER_PRIORITY
Definition bmqt_queueoptions.h:78
static const int k_DEFAULT_MAX_UNCONFIRMED_BYTES
Definition bmqt_queueoptions.h:77
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