From 01396d316226edb918c69e0848bb14803a52c88b Mon Sep 17 00:00:00 2001 From: Evgeny Malygin Date: Wed, 12 Jun 2024 14:43:21 +0100 Subject: [PATCH] Less code Signed-off-by: Evgeny Malygin --- .../mqb/mqbs/mqbs_filebackedstorage.cpp | 135 +++--------------- src/groups/mqb/mqbs/mqbs_inmemorystorage.cpp | 105 +++----------- .../mqb/mqbs/mqbs_virtualstoragecatalog.h | 25 ++-- src/groups/mqb/mqbstat/mqbstat_queuestats.cpp | 17 +++ src/groups/mqb/mqbstat/mqbstat_queuestats.h | 8 +- 5 files changed, 77 insertions(+), 213 deletions(-) diff --git a/src/groups/mqb/mqbs/mqbs_filebackedstorage.cpp b/src/groups/mqb/mqbs/mqbs_filebackedstorage.cpp index 90a1c06b18..42c62f714e 100644 --- a/src/groups/mqb/mqbs/mqbs_filebackedstorage.cpp +++ b/src/groups/mqb/mqbs/mqbs_filebackedstorage.cpp @@ -73,19 +73,8 @@ void FileBackedStorage::purgeCommon(const mqbu::StorageKey& appKey) mqbs::VirtualStorageCatalog::OnStorageUpdateCb cb; if (d_queue_p) { - // disambiguate mqbstat::QueueStatsDomain::onEvent - bdlf::MemFn - f(&mqbstat::QueueStatsDomain::onEvent); - - cb = bdlf::BindUtil::bind( - f, - d_queue_p->stats(), - mqbstat::QueueStatsDomain::EventType::e_PURGE, - bdlf::PlaceHolders::_1, // value - bdlf::PlaceHolders::_2); // appId + cb = d_queue_p->stats()->buildEventCallback( + mqbstat::QueueStatsDomain::EventType::e_PURGE); } d_virtualStorageCatalog.removeAll(appKey, cb); @@ -357,20 +346,9 @@ FileBackedStorage::put(mqbi::StorageMessageAttributes* attributes, // if we keep `irc` (like we keep 'DataStoreRecordHandle'). BSLS_ASSERT_SAFE(d_queue_p); - // disambiguate mqbstat::QueueStatsDomain::onEvent - bdlf::MemFn - f(&mqbstat::QueueStatsDomain::onEvent); - mqbs::VirtualStorageCatalog::OnStorageUpdateCb cb = - bdlf::BindUtil::bind( - f, - d_queue_p->stats(), - mqbstat::QueueStatsDomain::EventType::e_ADD_MESSAGE, - bdlf::PlaceHolders::_1, // value - bdlf::PlaceHolders::_2); // appId + d_queue_p->stats()->buildEventCallback( + mqbstat::QueueStatsDomain::EventType::e_ADD_MESSAGE); d_virtualStorageCatalog.put(msgGUID, msgSize, @@ -404,15 +382,12 @@ FileBackedStorage::put(mqbi::StorageMessageAttributes* attributes, BSLS_ASSERT(hasMessage(msgGUID)); for (size_t i = 0; i < storageKeys.size(); ++i) { - d_virtualStorageCatalog.put( - msgGUID, - msgSize, - d_defaultRdaInfo, - bmqp::Protocol::k_DEFAULT_SUBSCRIPTION_ID, - storageKeys[i], - mqbs::VirtualStorageCatalog:: - OnStorageUpdateCb()); // empty callback, do not track metrics - // in proxy + // No callback, do not track metrics in proxy + d_virtualStorageCatalog.put(msgGUID, + msgSize, + d_defaultRdaInfo, + bmqp::Protocol::k_DEFAULT_SUBSCRIPTION_ID, + storageKeys[i]); } // Note that unlike 'InMemoryStorage', we don't add the message to the @@ -472,19 +447,8 @@ FileBackedStorage::releaseRef(const bmqt::MessageGUID& msgGUID, if (!appKey.isNull()) { mqbs::VirtualStorageCatalog::OnStorageUpdateCb cb; if (d_queue_p) { - // disambiguate mqbstat::QueueStatsDomain::onEvent - bdlf::MemFn - f(&mqbstat::QueueStatsDomain::onEvent); - - cb = bdlf::BindUtil::bind( - f, - d_queue_p->stats(), - mqbstat::QueueStatsDomain::EventType::e_DEL_MESSAGE, - bdlf::PlaceHolders::_1, // value - bdlf::PlaceHolders::_2); // appId + cb = d_queue_p->stats()->buildEventCallback( + mqbstat::QueueStatsDomain::EventType::e_DEL_MESSAGE); } const mqbi::StorageResult::Enum rc = @@ -535,19 +499,8 @@ FileBackedStorage::remove(const bmqt::MessageGUID& msgGUID, if (clearAll) { mqbs::VirtualStorageCatalog::OnStorageUpdateCb cb; if (d_queue_p) { - // disambiguate mqbstat::QueueStatsDomain::onEvent - bdlf::MemFn - f(&mqbstat::QueueStatsDomain::onEvent); - - cb = bdlf::BindUtil::bind( - f, - d_queue_p->stats(), - mqbstat::QueueStatsDomain::EventType::e_DEL_MESSAGE, - bdlf::PlaceHolders::_1, // value - bdlf::PlaceHolders::_2); // appId + cb = d_queue_p->stats()->buildEventCallback( + mqbstat::QueueStatsDomain::EventType::e_DEL_MESSAGE); } d_virtualStorageCatalog.remove(msgGUID, @@ -818,19 +771,8 @@ int FileBackedStorage::gcExpiredMessages( mqbs::VirtualStorageCatalog::OnStorageUpdateCb cb; if (d_queue_p) { - // disambiguate mqbstat::QueueStatsDomain::onEvent - bdlf::MemFn - f(&mqbstat::QueueStatsDomain::onEvent); - - cb = bdlf::BindUtil::bind( - f, - d_queue_p->stats(), - mqbstat::QueueStatsDomain::EventType::e_DEL_MESSAGE, - bdlf::PlaceHolders::_1, // value - bdlf::PlaceHolders::_2); // appId + cb = d_queue_p->stats()->buildEventCallback( + mqbstat::QueueStatsDomain::EventType::e_DEL_MESSAGE); } // Remove message from all virtual storages. @@ -894,19 +836,8 @@ void FileBackedStorage::processMessageRecord( mqbs::VirtualStorageCatalog::OnStorageUpdateCb cb; if (d_queue_p) { - // disambiguate mqbstat::QueueStatsDomain::onEvent - bdlf::MemFn - f(&mqbstat::QueueStatsDomain::onEvent); - - cb = bdlf::BindUtil::bind( - f, - d_queue_p->stats(), - mqbstat::QueueStatsDomain::EventType::e_ADD_MESSAGE, - bdlf::PlaceHolders::_1, // value - bdlf::PlaceHolders::_2); // appId + cb = d_queue_p->stats()->buildEventCallback( + mqbstat::QueueStatsDomain::EventType::e_ADD_MESSAGE); } // Add 'guid' to all virtual storages, if any. @@ -1009,19 +940,8 @@ void FileBackedStorage::processConfirmRecord( if (!appKey.isNull()) { mqbs::VirtualStorageCatalog::OnStorageUpdateCb cb; if (d_queue_p) { - // disambiguate mqbstat::QueueStatsDomain::onEvent - bdlf::MemFn - f(&mqbstat::QueueStatsDomain::onEvent); - - cb = bdlf::BindUtil::bind( - f, - d_queue_p->stats(), - mqbstat::QueueStatsDomain::EventType::e_DEL_MESSAGE, - bdlf::PlaceHolders::_1, // value - bdlf::PlaceHolders::_2); // appId + cb = d_queue_p->stats()->buildEventCallback( + mqbstat::QueueStatsDomain::EventType::e_DEL_MESSAGE); } const mqbi::StorageResult::Enum rc = @@ -1077,19 +997,8 @@ void FileBackedStorage::processDeletionRecord(const bmqt::MessageGUID& guid) mqbs::VirtualStorageCatalog::OnStorageUpdateCb cb; if (d_queue_p) { - // disambiguate mqbstat::QueueStatsDomain::onEvent - bdlf::MemFn - f(&mqbstat::QueueStatsDomain::onEvent); - - cb = bdlf::BindUtil::bind( - f, - d_queue_p->stats(), - mqbstat::QueueStatsDomain::EventType::e_DEL_MESSAGE, - bdlf::PlaceHolders::_1, // value - bdlf::PlaceHolders::_2); // appId + cb = d_queue_p->stats()->buildEventCallback( + mqbstat::QueueStatsDomain::EventType::e_DEL_MESSAGE); } // Delete 'guid' from all virtual storages, if any. Note that 'guid' diff --git a/src/groups/mqb/mqbs/mqbs_inmemorystorage.cpp b/src/groups/mqb/mqbs/mqbs_inmemorystorage.cpp index 5542f6bd79..7e5969715e 100644 --- a/src/groups/mqb/mqbs/mqbs_inmemorystorage.cpp +++ b/src/groups/mqb/mqbs/mqbs_inmemorystorage.cpp @@ -207,19 +207,8 @@ InMemoryStorage::put(mqbi::StorageMessageAttributes* attributes, mqbs::VirtualStorageCatalog::OnStorageUpdateCb cb; if (d_queue_p) { - // disambiguate mqbstat::QueueStatsDomain::onEvent - bdlf::MemFn - f(&mqbstat::QueueStatsDomain::onEvent); - - cb = bdlf::BindUtil::bind( - f, - d_queue_p->stats(), - mqbstat::QueueStatsDomain::EventType::e_ADD_MESSAGE, - bdlf::PlaceHolders::_1, // value - bdlf::PlaceHolders::_2); // appId + cb = d_queue_p->stats()->buildEventCallback( + mqbstat::QueueStatsDomain::EventType::e_ADD_MESSAGE); } d_virtualStorageCatalog.put(msgGUID, @@ -252,15 +241,12 @@ InMemoryStorage::put(mqbi::StorageMessageAttributes* attributes, // corresponding virtual storages. for (size_t i = 0; i < storageKeys.size(); ++i) { - d_virtualStorageCatalog.put( - msgGUID, - msgSize, - d_defaultRdaInfo, - bmqp::Protocol::k_DEFAULT_SUBSCRIPTION_ID, - storageKeys[i], - mqbs::VirtualStorageCatalog:: - OnStorageUpdateCb()); // empty callback, do not track metrics - // in proxy + // No callback, do not track metrics in proxy + d_virtualStorageCatalog.put(msgGUID, + msgSize, + d_defaultRdaInfo, + bmqp::Protocol::k_DEFAULT_SUBSCRIPTION_ID, + storageKeys[i]); } // If the guid also exists in the 'physical' storage, bump up its reference @@ -297,19 +283,8 @@ mqbi::StorageResult::Enum InMemoryStorage::releaseRef( if (!appKey.isNull()) { mqbs::VirtualStorageCatalog::OnStorageUpdateCb cb; if (d_queue_p) { - // disambiguate mqbstat::QueueStatsDomain::onEvent - bdlf::MemFn - f(&mqbstat::QueueStatsDomain::onEvent); - - cb = bdlf::BindUtil::bind( - f, - d_queue_p->stats(), - mqbstat::QueueStatsDomain::EventType::e_DEL_MESSAGE, - bdlf::PlaceHolders::_1, // value - bdlf::PlaceHolders::_2); // appId + cb = d_queue_p->stats()->buildEventCallback( + mqbstat::QueueStatsDomain::EventType::e_DEL_MESSAGE); } const mqbi::StorageResult::Enum rc = @@ -342,19 +317,8 @@ InMemoryStorage::remove(const bmqt::MessageGUID& msgGUID, if (clearAll) { mqbs::VirtualStorageCatalog::OnStorageUpdateCb cb; if (d_queue_p) { - // disambiguate mqbstat::QueueStatsDomain::onEvent - bdlf::MemFn - f(&mqbstat::QueueStatsDomain::onEvent); - - cb = bdlf::BindUtil::bind( - f, - d_queue_p->stats(), - mqbstat::QueueStatsDomain::EventType::e_DEL_MESSAGE, - bdlf::PlaceHolders::_1, // value - bdlf::PlaceHolders::_2); // appId + cb = d_queue_p->stats()->buildEventCallback( + mqbstat::QueueStatsDomain::EventType::e_DEL_MESSAGE); } d_virtualStorageCatalog.remove(msgGUID, @@ -396,19 +360,8 @@ InMemoryStorage::removeAll(const mqbu::StorageKey& appKey) mqbs::VirtualStorageCatalog::OnStorageUpdateCb cb; if (d_queue_p) { - // disambiguate mqbstat::QueueStatsDomain::onEvent - bdlf::MemFn - f(&mqbstat::QueueStatsDomain::onEvent); - - cb = bdlf::BindUtil::bind( - f, - d_queue_p->stats(), - mqbstat::QueueStatsDomain::EventType::e_PURGE, - bdlf::PlaceHolders::_1, // value - bdlf::PlaceHolders::_2); // appId + cb = d_queue_p->stats()->buildEventCallback( + mqbstat::QueueStatsDomain::EventType::e_PURGE); } d_virtualStorageCatalog.removeAll(mqbu::StorageKey::k_NULL_KEY, cb); @@ -495,19 +448,8 @@ InMemoryStorage::removeAll(const mqbu::StorageKey& appKey) mqbs::VirtualStorageCatalog::OnStorageUpdateCb cb; if (d_queue_p) { - // disambiguate mqbstat::QueueStatsDomain::onEvent - bdlf::MemFn - f(&mqbstat::QueueStatsDomain::onEvent); - - cb = bdlf::BindUtil::bind( - f, - d_queue_p->stats(), - mqbstat::QueueStatsDomain::EventType::e_PURGE, - bdlf::PlaceHolders::_1, // value - bdlf::PlaceHolders::_2); // appId + cb = d_queue_p->stats()->buildEventCallback( + mqbstat::QueueStatsDomain::EventType::e_PURGE); } // Clear out the virtual storage associated with the specified 'appKey'. @@ -562,19 +504,8 @@ int InMemoryStorage::gcExpiredMessages( mqbs::VirtualStorageCatalog::OnStorageUpdateCb cb; if (d_queue_p) { - // disambiguate mqbstat::QueueStatsDomain::onEvent - bdlf::MemFn - f(&mqbstat::QueueStatsDomain::onEvent); - - cb = bdlf::BindUtil::bind( - f, - d_queue_p->stats(), - mqbstat::QueueStatsDomain::EventType::e_DEL_MESSAGE, - bdlf::PlaceHolders::_1, // value - bdlf::PlaceHolders::_2); // appId + cb = d_queue_p->stats()->buildEventCallback( + mqbstat::QueueStatsDomain::EventType::e_DEL_MESSAGE); } // Remove message from all virtual storages and the physical (this) diff --git a/src/groups/mqb/mqbs/mqbs_virtualstoragecatalog.h b/src/groups/mqb/mqbs/mqbs_virtualstoragecatalog.h index 507d0eca87..a4f29a778f 100644 --- a/src/groups/mqb/mqbs/mqbs_virtualstoragecatalog.h +++ b/src/groups/mqb/mqbs/mqbs_virtualstoragecatalog.h @@ -119,12 +119,13 @@ class VirtualStorageCatalog { /// `rdaInfo` to the virtual storage associated with the specified /// `appKey`. Note that if `appKey` is null, the message will be added /// to all virtual storages maintained by this instance. - mqbi::StorageResult::Enum put(const bmqt::MessageGUID& msgGUID, - int msgSize, - const bmqp::RdaInfo& rdaInfo, - unsigned int subScriptionId, - const mqbu::StorageKey& appKey, - const OnStorageUpdateCb& putCb); + mqbi::StorageResult::Enum + put(const bmqt::MessageGUID& msgGUID, + int msgSize, + const bmqp::RdaInfo& rdaInfo, + unsigned int subScriptionId, + const mqbu::StorageKey& appKey, + const OnStorageUpdateCb& putCb = OnStorageUpdateCb()); /// Get an iterator for items stored in the virtual storage identified /// by the specified `appKey`. Iterator will point to point to the @@ -157,17 +158,19 @@ class VirtualStorageCatalog { /// null, then remove the message from the storages for all clients. /// Return 0 on success, or a non-zero return code if the `msgGUID` was /// not found or the `appKey` is invalid. - mqbi::StorageResult::Enum remove(const bmqt::MessageGUID& msgGUID, - const mqbu::StorageKey& appKey, - const OnStorageUpdateCb& removeCb); + mqbi::StorageResult::Enum + remove(const bmqt::MessageGUID& msgGUID, + const mqbu::StorageKey& appKey, + const OnStorageUpdateCb& removeCb = OnStorageUpdateCb()); /// Remove all messages from the storage for the client identified by /// the specified `appKey`. If `appKey` is null, then remove messages /// for all clients. Return one of the return codes from: /// * **e_SUCCESS** : `msgGUID` was not found /// * **e_APPKEY_NOT_FOUND** : Invalid `appKey` specified - mqbi::StorageResult::Enum removeAll(const mqbu::StorageKey& appKey, - const OnStorageUpdateCb& purgeCb); + mqbi::StorageResult::Enum + removeAll(const mqbu::StorageKey& appKey, + const OnStorageUpdateCb& purgeCb = OnStorageUpdateCb()); /// Create, if it doesn't exist already, a virtual storage instance with /// the specified `appId` and `appKey`. Return zero upon success and a diff --git a/src/groups/mqb/mqbstat/mqbstat_queuestats.cpp b/src/groups/mqb/mqbstat/mqbstat_queuestats.cpp index 79184a2bbd..266e54c7a3 100644 --- a/src/groups/mqb/mqbstat/mqbstat_queuestats.cpp +++ b/src/groups/mqb/mqbstat/mqbstat_queuestats.cpp @@ -661,6 +661,23 @@ void QueueStatsDomain::updateDomainAppIds( } } +QueueStatsDomain::EventCb +QueueStatsDomain::buildEventCallback(EventType::Enum type) +{ + // disambiguate mqbstat::QueueStatsDomain::onEvent + bdlf::MemFn + f(&mqbstat::QueueStatsDomain::onEvent); + + return bdlf::BindUtil::bind(f, + this, + type, + bdlf::PlaceHolders::_1, // value + bdlf::PlaceHolders::_2); // appId +} + // ----------------------------- // struct QueueStatsDomain::Role // ----------------------------- diff --git a/src/groups/mqb/mqbstat/mqbstat_queuestats.h b/src/groups/mqb/mqbstat/mqbstat_queuestats.h index e3f42a59b9..9238f8f82f 100644 --- a/src/groups/mqb/mqbstat/mqbstat_queuestats.h +++ b/src/groups/mqb/mqbstat/mqbstat_queuestats.h @@ -31,8 +31,6 @@ // 'mqbstat::QueueStatsUtil' is a utility namespace exposing methods to // initialize the stat contexts and associated objects. -// MQB - // BMQ #include @@ -42,6 +40,7 @@ #include // BDE +#include #include #include #include @@ -72,6 +71,9 @@ class QueueStatsDomain { public: // TYPES + typedef bsl::function + EventCb; + /// Enum representing the various type of events for which statistics /// are monitored. struct EventType { @@ -251,6 +253,8 @@ class QueueStatsDomain { /// Return a pointer to the statcontext. mwcst::StatContext* statContext(); + + EventCb buildEventCallback(EventType::Enum type); }; // FREE OPERATORS