From 74c7fd429f8de320ceb58218c901eb86008c0494 Mon Sep 17 00:00:00 2001 From: Emelia Lei Date: Fri, 20 Dec 2024 17:32:49 -0500 Subject: [PATCH] update DOMAINS REMOVE command with an optional keyword 'finalize' Signed-off-by: Emelia Lei --- src/groups/mqb/mqbcmd/mqbcmd.xsd | 7 +- src/groups/mqb/mqbcmd/mqbcmd_commandlist.cpp | 14 +- src/groups/mqb/mqbcmd/mqbcmd_messages.cpp | 209 ++++-------- src/groups/mqb/mqbcmd/mqbcmd_messages.h | 319 ++++++++++--------- src/groups/mqb/mqbcmd/mqbcmd_parseutil.cpp | 15 +- 5 files changed, 259 insertions(+), 305 deletions(-) diff --git a/src/groups/mqb/mqbcmd/mqbcmd.xsd b/src/groups/mqb/mqbcmd/mqbcmd.xsd index 27e883b45..90c51ad20 100644 --- a/src/groups/mqb/mqbcmd/mqbcmd.xsd +++ b/src/groups/mqb/mqbcmd/mqbcmd.xsd @@ -783,9 +783,10 @@ - - - + + + + diff --git a/src/groups/mqb/mqbcmd/mqbcmd_commandlist.cpp b/src/groups/mqb/mqbcmd/mqbcmd_commandlist.cpp index 7fae3cbc4..6943fad82 100644 --- a/src/groups/mqb/mqbcmd/mqbcmd_commandlist.cpp +++ b/src/groups/mqb/mqbcmd/mqbcmd_commandlist.cpp @@ -65,9 +65,6 @@ struct CommandDefinition { "'count' is 'negative', print '-count' messages *preceding* the " "specified starting position. If 'count' is 'UNLIMITED', print all " "the messages starting at and after the specified position."}, - {"DOMAINS REMOVE ", - "Reject all incoming connections to all queues in domain 'name'", - "and purge them from the domain"}, {"DOMAINS RECONFIGURE ", "Reconfigure 'domain' by reloading its configuration from disk", "Reconfigure 'domain' by reloading its configuration from disk"}, @@ -76,9 +73,14 @@ struct CommandDefinition { "Clear the domain resolution cache entry of the optionally specified " "'domain', or clear all domain resolution cache entries if 'ALL' is " "specified."}, - {"DOMAINS REMOVE ", - "Reject all incoming connections to all queues in domain 'name'", - "and purge them from the domain"}, + {"DOMAINS REMOVE [finalize]", + "Remove a domain with an optional keyword 'finalize'", + "If the keyword 'finalize' is not supplied, fail the command if there's " + "any open queue; block any incoming open queue request after the command " + "is issued; clean DomainResolver cache; " + "purge and force GC all queues in this domain. If the keyword 'finalize' " + "is supplied, which must happen after the first pass and remove the " + "configuration file, remove the domain object."}, // ConfigProvider {"CONFIGPROVIDER CACHE_CLEAR (|ALL)", "Clear domain's cached configuration.", diff --git a/src/groups/mqb/mqbcmd/mqbcmd_messages.cpp b/src/groups/mqb/mqbcmd/mqbcmd_messages.cpp index e03dbfce6..db001647f 100644 --- a/src/groups/mqb/mqbcmd/mqbcmd_messages.cpp +++ b/src/groups/mqb/mqbcmd/mqbcmd_messages.cpp @@ -1,3 +1,18 @@ +// Copyright 2019-2024 Bloomberg Finance L.P. +// SPDX-License-Identifier: Apache-2.0 +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + // mqbcmd_messages.cpp *DO NOT EDIT* @generated -*-C++-*- #include @@ -1575,99 +1590,89 @@ const char* DomainReconfigure::selectionName() const const char DomainRemove::CLASS_NAME[] = "DomainRemove"; -const bdlat_SelectionInfo DomainRemove::SELECTION_INFO_ARRAY[] = { - {SELECTION_ID_DOMAIN, +const bdlat_AttributeInfo DomainRemove::ATTRIBUTE_INFO_ARRAY[] = { + {ATTRIBUTE_ID_DOMAIN, "domain", sizeof("domain") - 1, "", + bdlat_FormattingMode::e_TEXT}, + {ATTRIBUTE_ID_FINALIZE, + "finalize", + sizeof("finalize") - 1, + "", bdlat_FormattingMode::e_TEXT}}; // CLASS METHODS -const bdlat_SelectionInfo* DomainRemove::lookupSelectionInfo(const char* name, +const bdlat_AttributeInfo* DomainRemove::lookupAttributeInfo(const char* name, int nameLength) { - for (int i = 0; i < 1; ++i) { - const bdlat_SelectionInfo& selectionInfo = - DomainRemove::SELECTION_INFO_ARRAY[i]; + for (int i = 0; i < 2; ++i) { + const bdlat_AttributeInfo& attributeInfo = + DomainRemove::ATTRIBUTE_INFO_ARRAY[i]; - if (nameLength == selectionInfo.d_nameLength && - 0 == bsl::memcmp(selectionInfo.d_name_p, name, nameLength)) { - return &selectionInfo; + if (nameLength == attributeInfo.d_nameLength && + 0 == bsl::memcmp(attributeInfo.d_name_p, name, nameLength)) { + return &attributeInfo; } } return 0; } -const bdlat_SelectionInfo* DomainRemove::lookupSelectionInfo(int id) +const bdlat_AttributeInfo* DomainRemove::lookupAttributeInfo(int id) { switch (id) { - case SELECTION_ID_DOMAIN: - return &SELECTION_INFO_ARRAY[SELECTION_INDEX_DOMAIN]; + case ATTRIBUTE_ID_DOMAIN: + return &ATTRIBUTE_INFO_ARRAY[ATTRIBUTE_INDEX_DOMAIN]; + case ATTRIBUTE_ID_FINALIZE: + return &ATTRIBUTE_INFO_ARRAY[ATTRIBUTE_INDEX_FINALIZE]; default: return 0; } } // CREATORS +DomainRemove::DomainRemove(bslma::Allocator* basicAllocator) +: d_domain(basicAllocator) +, d_finalize() +{ +} + DomainRemove::DomainRemove(const DomainRemove& original, bslma::Allocator* basicAllocator) -: d_selectionId(original.d_selectionId) -, d_allocator_p(bslma::Default::allocator(basicAllocator)) +: d_domain(original.d_domain, basicAllocator) +, d_finalize(original.d_finalize) { - switch (d_selectionId) { - case SELECTION_ID_DOMAIN: { - new (d_domain.buffer()) - bsl::string(original.d_domain.object(), d_allocator_p); - } break; - default: BSLS_ASSERT(SELECTION_ID_UNDEFINED == d_selectionId); - } } #if defined(BSLS_COMPILERFEATURES_SUPPORT_RVALUE_REFERENCES) && \ defined(BSLS_COMPILERFEATURES_SUPPORT_NOEXCEPT) DomainRemove::DomainRemove(DomainRemove&& original) noexcept -: d_selectionId(original.d_selectionId), - d_allocator_p(original.d_allocator_p) +: d_domain(bsl::move(original.d_domain)), + d_finalize(bsl::move(original.d_finalize)) { - switch (d_selectionId) { - case SELECTION_ID_DOMAIN: { - new (d_domain.buffer()) - bsl::string(bsl::move(original.d_domain.object()), d_allocator_p); - } break; - default: BSLS_ASSERT(SELECTION_ID_UNDEFINED == d_selectionId); - } } DomainRemove::DomainRemove(DomainRemove&& original, bslma::Allocator* basicAllocator) -: d_selectionId(original.d_selectionId) -, d_allocator_p(bslma::Default::allocator(basicAllocator)) +: d_domain(bsl::move(original.d_domain), basicAllocator) +, d_finalize(bsl::move(original.d_finalize)) { - switch (d_selectionId) { - case SELECTION_ID_DOMAIN: { - new (d_domain.buffer()) - bsl::string(bsl::move(original.d_domain.object()), d_allocator_p); - } break; - default: BSLS_ASSERT(SELECTION_ID_UNDEFINED == d_selectionId); - } } #endif +DomainRemove::~DomainRemove() +{ +} + // MANIPULATORS DomainRemove& DomainRemove::operator=(const DomainRemove& rhs) { if (this != &rhs) { - switch (rhs.d_selectionId) { - case SELECTION_ID_DOMAIN: { - makeDomain(rhs.d_domain.object()); - } break; - default: - BSLS_ASSERT(SELECTION_ID_UNDEFINED == rhs.d_selectionId); - reset(); - } + d_domain = rhs.d_domain; + d_finalize = rhs.d_finalize; } return *this; @@ -1678,14 +1683,8 @@ DomainRemove& DomainRemove::operator=(const DomainRemove& rhs) DomainRemove& DomainRemove::operator=(DomainRemove&& rhs) { if (this != &rhs) { - switch (rhs.d_selectionId) { - case SELECTION_ID_DOMAIN: { - makeDomain(bsl::move(rhs.d_domain.object())); - } break; - default: - BSLS_ASSERT(SELECTION_ID_UNDEFINED == rhs.d_selectionId); - reset(); - } + d_domain = bsl::move(rhs.d_domain); + d_finalize = bsl::move(rhs.d_finalize); } return *this; @@ -1694,87 +1693,10 @@ DomainRemove& DomainRemove::operator=(DomainRemove&& rhs) void DomainRemove::reset() { - switch (d_selectionId) { - case SELECTION_ID_DOMAIN: { - typedef bsl::string Type; - d_domain.object().~Type(); - } break; - default: BSLS_ASSERT(SELECTION_ID_UNDEFINED == d_selectionId); - } - - d_selectionId = SELECTION_ID_UNDEFINED; + bdlat_ValueTypeFunctions::reset(&d_domain); + bdlat_ValueTypeFunctions::reset(&d_finalize); } -int DomainRemove::makeSelection(int selectionId) -{ - switch (selectionId) { - case SELECTION_ID_DOMAIN: { - makeDomain(); - } break; - case SELECTION_ID_UNDEFINED: { - reset(); - } break; - default: return -1; - } - return 0; -} - -int DomainRemove::makeSelection(const char* name, int nameLength) -{ - const bdlat_SelectionInfo* selectionInfo = lookupSelectionInfo(name, - nameLength); - if (0 == selectionInfo) { - return -1; - } - - return makeSelection(selectionInfo->d_id); -} - -bsl::string& DomainRemove::makeDomain() -{ - if (SELECTION_ID_DOMAIN == d_selectionId) { - bdlat_ValueTypeFunctions::reset(&d_domain.object()); - } - else { - reset(); - new (d_domain.buffer()) bsl::string(d_allocator_p); - d_selectionId = SELECTION_ID_DOMAIN; - } - - return d_domain.object(); -} - -bsl::string& DomainRemove::makeDomain(const bsl::string& value) -{ - if (SELECTION_ID_DOMAIN == d_selectionId) { - d_domain.object() = value; - } - else { - reset(); - new (d_domain.buffer()) bsl::string(value, d_allocator_p); - d_selectionId = SELECTION_ID_DOMAIN; - } - - return d_domain.object(); -} - -#if defined(BSLS_COMPILERFEATURES_SUPPORT_RVALUE_REFERENCES) && \ - defined(BSLS_COMPILERFEATURES_SUPPORT_NOEXCEPT) -bsl::string& DomainRemove::makeDomain(bsl::string&& value) -{ - if (SELECTION_ID_DOMAIN == d_selectionId) { - d_domain.object() = bsl::move(value); - } - else { - reset(); - new (d_domain.buffer()) bsl::string(bsl::move(value), d_allocator_p); - d_selectionId = SELECTION_ID_DOMAIN; - } - - return d_domain.object(); -} -#endif - // ACCESSORS bsl::ostream& @@ -1782,27 +1704,12 @@ DomainRemove::print(bsl::ostream& stream, int level, int spacesPerLevel) const { bslim::Printer printer(&stream, level, spacesPerLevel); printer.start(); - switch (d_selectionId) { - case SELECTION_ID_DOMAIN: { - printer.printAttribute("domain", d_domain.object()); - } break; - default: stream << "SELECTION UNDEFINED\n"; - } + printer.printAttribute("domain", this->domain()); + printer.printAttribute("finalize", this->finalize()); printer.end(); return stream; } -const char* DomainRemove::selectionName() const -{ - switch (d_selectionId) { - case SELECTION_ID_DOMAIN: - return SELECTION_INFO_ARRAY[SELECTION_INDEX_DOMAIN].name(); - default: - BSLS_ASSERT(SELECTION_ID_UNDEFINED == d_selectionId); - return "(* UNDEFINED *)"; - } -} - // ------------------ // class ElectorState // ------------------ diff --git a/src/groups/mqb/mqbcmd/mqbcmd_messages.h b/src/groups/mqb/mqbcmd/mqbcmd_messages.h index c7817ac9b..9031ebf7d 100644 --- a/src/groups/mqb/mqbcmd/mqbcmd_messages.h +++ b/src/groups/mqb/mqbcmd/mqbcmd_messages.h @@ -2767,42 +2767,32 @@ namespace mqbcmd { class DomainRemove { // INSTANCE DATA - union { - bsls::ObjectBuffer d_domain; - }; - - int d_selectionId; - bslma::Allocator* d_allocator_p; - - // PRIVATE ACCESSORS - template - void hashAppendImpl(t_HASH_ALGORITHM& hashAlgorithm) const; - - bool isEqualTo(const DomainRemove& rhs) const; + bsl::string d_domain; + bdlb::NullableValue d_finalize; public: // TYPES + enum { ATTRIBUTE_ID_DOMAIN = 0, ATTRIBUTE_ID_FINALIZE = 1 }; - enum { SELECTION_ID_UNDEFINED = -1, SELECTION_ID_DOMAIN = 0 }; - - enum { NUM_SELECTIONS = 1 }; + enum { NUM_ATTRIBUTES = 2 }; - enum { SELECTION_INDEX_DOMAIN = 0 }; + enum { ATTRIBUTE_INDEX_DOMAIN = 0, ATTRIBUTE_INDEX_FINALIZE = 1 }; // CONSTANTS static const char CLASS_NAME[]; - static const bdlat_SelectionInfo SELECTION_INFO_ARRAY[]; + static const bdlat_AttributeInfo ATTRIBUTE_INFO_ARRAY[]; + public: // CLASS METHODS - static const bdlat_SelectionInfo* lookupSelectionInfo(int id); - // Return selection information for the selection indicated by the - // specified 'id' if the selection exists, and 0 otherwise. + static const bdlat_AttributeInfo* lookupAttributeInfo(int id); + // Return attribute information for the attribute indicated by the + // specified 'id' if the attribute exists, and 0 otherwise. - static const bdlat_SelectionInfo* lookupSelectionInfo(const char* name, + static const bdlat_AttributeInfo* lookupAttributeInfo(const char* name, int nameLength); - // Return selection information for the selection indicated by the - // specified 'name' of the specified 'nameLength' if the selection + // Return attribute information for the attribute indicated by the + // specified 'name' of the specified 'nameLength' if the attribute // exists, and 0 otherwise. // CREATORS @@ -2851,42 +2841,45 @@ class DomainRemove { #endif void reset(); - // Reset this object to the default value (i.e., its value upon default - // construction). - - int makeSelection(int selectionId); - // Set the value of this object to be the default for the selection - // indicated by the specified 'selectionId'. Return 0 on success, and - // non-zero value otherwise (i.e., the selection is not found). - - int makeSelection(const char* name, int nameLength); - // Set the value of this object to be the default for the selection - // indicated by the specified 'name' of the specified 'nameLength'. - // Return 0 on success, and non-zero value otherwise (i.e., the - // selection is not found). + // Reset this object to the default value (i.e., its value upon + // default construction). - bsl::string& makeDomain(); - bsl::string& makeDomain(const bsl::string& value); -#if defined(BSLS_COMPILERFEATURES_SUPPORT_RVALUE_REFERENCES) && \ - defined(BSLS_COMPILERFEATURES_SUPPORT_NOEXCEPT) - bsl::string& makeDomain(bsl::string&& value); -#endif - // Set the value of this object to be a "Domain" value. Optionally - // specify the 'value' of the "Domain". If 'value' is not specified, - // the default "Domain" value is used. + template + int manipulateAttributes(t_MANIPULATOR& manipulator); + // Invoke the specified 'manipulator' sequentially on the address of + // each (modifiable) attribute of this object, supplying 'manipulator' + // with the corresponding attribute information structure until such + // invocation returns a non-zero value. Return the value from the + // last invocation of 'manipulator' (i.e., the invocation that + // terminated the sequence). template - int manipulateSelection(t_MANIPULATOR& manipulator); - // Invoke the specified 'manipulator' on the address of the modifiable - // selection, supplying 'manipulator' with the corresponding selection + int manipulateAttribute(t_MANIPULATOR& manipulator, int id); + // Invoke the specified 'manipulator' on the address of + // the (modifiable) attribute indicated by the specified 'id', + // supplying 'manipulator' with the corresponding attribute // information structure. Return the value returned from the - // invocation of 'manipulator' if this object has a defined selection, - // and -1 otherwise. + // invocation of 'manipulator' if 'id' identifies an attribute of this + // class, and -1 otherwise. + + template + int manipulateAttribute(t_MANIPULATOR& manipulator, + const char* name, + int nameLength); + // Invoke the specified 'manipulator' on the address of + // the (modifiable) attribute indicated by the specified 'name' of the + // specified 'nameLength', supplying 'manipulator' with the + // corresponding attribute information structure. Return the value + // returned from the invocation of 'manipulator' if 'name' identifies + // an attribute of this class, and -1 otherwise. bsl::string& domain(); - // Return a reference to the modifiable "Domain" selection of this - // object if "Domain" is the current selection. The behavior is - // undefined unless "Domain" is the selection of this object. + // Return a reference to the modifiable "Domain" attribute of this + // object. + + bdlb::NullableValue& finalize(); + // Return a reference to the modifiable "Finalize" attribute of this + // object. // ACCESSORS bsl::ostream& @@ -2903,47 +2896,54 @@ class DomainRemove { // operation has no effect. Note that a trailing newline is provided // in multiline mode only. - int selectionId() const; - // Return the id of the current selection if the selection is defined, - // and -1 otherwise. - template - int accessSelection(t_ACCESSOR& accessor) const; - // Invoke the specified 'accessor' on the non-modifiable selection, - // supplying 'accessor' with the corresponding selection information - // structure. Return the value returned from the invocation of - // 'accessor' if this object has a defined selection, and -1 otherwise. + int accessAttributes(t_ACCESSOR& accessor) const; + // Invoke the specified 'accessor' sequentially on each + // (non-modifiable) attribute of this object, supplying 'accessor' + // with the corresponding attribute information structure until such + // invocation returns a non-zero value. Return the value from the + // last invocation of 'accessor' (i.e., the invocation that terminated + // the sequence). - const bsl::string& domain() const; - // Return a reference to the non-modifiable "Domain" selection of this - // object if "Domain" is the current selection. The behavior is - // undefined unless "Domain" is the selection of this object. + template + int accessAttribute(t_ACCESSOR& accessor, int id) const; + // Invoke the specified 'accessor' on the (non-modifiable) attribute + // of this object indicated by the specified 'id', supplying 'accessor' + // with the corresponding attribute information structure. Return the + // value returned from the invocation of 'accessor' if 'id' identifies + // an attribute of this class, and -1 otherwise. - bool isDomainValue() const; - // Return 'true' if the value of this object is a "Domain" value, and - // return 'false' otherwise. + template + int accessAttribute(t_ACCESSOR& accessor, + const char* name, + int nameLength) const; + // Invoke the specified 'accessor' on the (non-modifiable) attribute + // of this object indicated by the specified 'name' of the specified + // 'nameLength', supplying 'accessor' with the corresponding attribute + // information structure. Return the value returned from the + // invocation of 'accessor' if 'name' identifies an attribute of this + // class, and -1 otherwise. - bool isUndefinedValue() const; - // Return 'true' if the value of this object is undefined, and 'false' - // otherwise. + const bsl::string& domain() const; + // Return a reference offering non-modifiable access to the "Domain" + // attribute of this object. - const char* selectionName() const; - // Return the symbolic name of the current selection of this object. + const bdlb::NullableValue& finalize() const; + // Return a reference offering non-modifiable access to the "Finalize" + // attribute of this object. // HIDDEN FRIENDS friend bool operator==(const DomainRemove& lhs, const DomainRemove& rhs) - // Return 'true' if the specified 'lhs' and 'rhs' objects have the same - // value, and 'false' otherwise. Two 'DomainRemove' objects have the - // same value if either the selections in both objects have the same - // ids and the same values, or both selections are undefined. + // Return 'true' if the specified 'lhs' and 'rhs' attribute objects + // have the same value, and 'false' otherwise. Two attribute objects + // have the same value if each respective attribute has the same value. { - return lhs.isEqualTo(rhs); + return lhs.domain() == rhs.domain() && + lhs.finalize() == rhs.finalize(); } friend bool operator!=(const DomainRemove& lhs, const DomainRemove& rhs) - // Return 'true' if the specified 'lhs' and 'rhs' objects do not have - // the same values, as determined by 'operator==', and 'false' - // otherwise. + // Returns '!(lhs == rhs)' { return !(lhs == rhs); } @@ -2964,7 +2964,9 @@ class DomainRemove { // effectively provides a 'bsl::hash' specialization for // 'DomainRemove'. { - return object.hashAppendImpl(hashAlg); + using bslh::hashAppend; + hashAppend(hashAlg, object.domain()); + hashAppend(hashAlg, object.finalize()); } }; @@ -2972,7 +2974,7 @@ class DomainRemove { // TRAITS -BDLAT_DECL_CHOICE_WITH_ALLOCATOR_BITWISEMOVEABLE_TRAITS(mqbcmd::DomainRemove) +BDLAT_DECL_SEQUENCE_WITH_ALLOCATOR_BITWISEMOVEABLE_TRAITS(mqbcmd::DomainRemove) namespace mqbcmd { @@ -33459,100 +33461,131 @@ inline bool DomainReconfigure::isUndefinedValue() const // ------------------ // CLASS METHODS -// PRIVATE ACCESSORS -template -void DomainRemove::hashAppendImpl(t_HASH_ALGORITHM& hashAlgorithm) const +// MANIPULATORS +template +int DomainRemove::manipulateAttributes(t_MANIPULATOR& manipulator) { - typedef DomainRemove Class; - using bslh::hashAppend; - hashAppend(hashAlgorithm, this->selectionId()); - switch (this->selectionId()) { - case Class::SELECTION_ID_DOMAIN: - hashAppend(hashAlgorithm, this->domain()); - break; - default: BSLS_ASSERT(this->selectionId() == Class::SELECTION_ID_UNDEFINED); - } -} + int ret; -inline bool DomainRemove::isEqualTo(const DomainRemove& rhs) const -{ - typedef DomainRemove Class; - if (this->selectionId() == rhs.selectionId()) { - switch (rhs.selectionId()) { - case Class::SELECTION_ID_DOMAIN: return this->domain() == rhs.domain(); - default: - BSLS_ASSERT(Class::SELECTION_ID_UNDEFINED == rhs.selectionId()); - return true; - } + ret = manipulator(&d_domain, ATTRIBUTE_INFO_ARRAY[ATTRIBUTE_INDEX_DOMAIN]); + if (ret) { + return ret; } - else { - return false; + + ret = manipulator(&d_finalize, + ATTRIBUTE_INFO_ARRAY[ATTRIBUTE_INDEX_FINALIZE]); + if (ret) { + return ret; } -} -// CREATORS -inline DomainRemove::DomainRemove(bslma::Allocator* basicAllocator) -: d_selectionId(SELECTION_ID_UNDEFINED) -, d_allocator_p(bslma::Default::allocator(basicAllocator)) -{ + return 0; } -inline DomainRemove::~DomainRemove() +template +int DomainRemove::manipulateAttribute(t_MANIPULATOR& manipulator, int id) { - reset(); + enum { NOT_FOUND = -1 }; + + switch (id) { + case ATTRIBUTE_ID_DOMAIN: { + return manipulator(&d_domain, + ATTRIBUTE_INFO_ARRAY[ATTRIBUTE_INDEX_DOMAIN]); + } + case ATTRIBUTE_ID_FINALIZE: { + return manipulator(&d_finalize, + ATTRIBUTE_INFO_ARRAY[ATTRIBUTE_INDEX_FINALIZE]); + } + default: return NOT_FOUND; + } } -// MANIPULATORS template -int DomainRemove::manipulateSelection(t_MANIPULATOR& manipulator) +int DomainRemove::manipulateAttribute(t_MANIPULATOR& manipulator, + const char* name, + int nameLength) { - switch (d_selectionId) { - case DomainRemove::SELECTION_ID_DOMAIN: - return manipulator(&d_domain.object(), - SELECTION_INFO_ARRAY[SELECTION_INDEX_DOMAIN]); - default: - BSLS_ASSERT(DomainRemove::SELECTION_ID_UNDEFINED == d_selectionId); - return -1; + enum { NOT_FOUND = -1 }; + + const bdlat_AttributeInfo* attributeInfo = lookupAttributeInfo(name, + nameLength); + if (0 == attributeInfo) { + return NOT_FOUND; } + + return manipulateAttribute(manipulator, attributeInfo->d_id); } inline bsl::string& DomainRemove::domain() { - BSLS_ASSERT(SELECTION_ID_DOMAIN == d_selectionId); - return d_domain.object(); + return d_domain; +} + +inline bdlb::NullableValue& DomainRemove::finalize() +{ + return d_finalize; } // ACCESSORS -inline int DomainRemove::selectionId() const +template +int DomainRemove::accessAttributes(t_ACCESSOR& accessor) const { - return d_selectionId; + int ret; + + ret = accessor(d_domain, ATTRIBUTE_INFO_ARRAY[ATTRIBUTE_INDEX_DOMAIN]); + if (ret) { + return ret; + } + + ret = accessor(d_finalize, ATTRIBUTE_INFO_ARRAY[ATTRIBUTE_INDEX_FINALIZE]); + if (ret) { + return ret; + } + + return 0; } template -int DomainRemove::accessSelection(t_ACCESSOR& accessor) const +int DomainRemove::accessAttribute(t_ACCESSOR& accessor, int id) const { - switch (d_selectionId) { - case SELECTION_ID_DOMAIN: - return accessor(d_domain.object(), - SELECTION_INFO_ARRAY[SELECTION_INDEX_DOMAIN]); - default: BSLS_ASSERT(SELECTION_ID_UNDEFINED == d_selectionId); return -1; + enum { NOT_FOUND = -1 }; + + switch (id) { + case ATTRIBUTE_ID_DOMAIN: { + return accessor(d_domain, + ATTRIBUTE_INFO_ARRAY[ATTRIBUTE_INDEX_DOMAIN]); + } + case ATTRIBUTE_ID_FINALIZE: { + return accessor(d_finalize, + ATTRIBUTE_INFO_ARRAY[ATTRIBUTE_INDEX_FINALIZE]); + } + default: return NOT_FOUND; } } -inline const bsl::string& DomainRemove::domain() const +template +int DomainRemove::accessAttribute(t_ACCESSOR& accessor, + const char* name, + int nameLength) const { - BSLS_ASSERT(SELECTION_ID_DOMAIN == d_selectionId); - return d_domain.object(); + enum { NOT_FOUND = -1 }; + + const bdlat_AttributeInfo* attributeInfo = lookupAttributeInfo(name, + nameLength); + if (0 == attributeInfo) { + return NOT_FOUND; + } + + return accessAttribute(accessor, attributeInfo->d_id); } -inline bool DomainRemove::isDomainValue() const +inline const bsl::string& DomainRemove::domain() const { - return SELECTION_ID_DOMAIN == d_selectionId; + return d_domain; } -inline bool DomainRemove::isUndefinedValue() const +inline const bdlb::NullableValue& DomainRemove::finalize() const { - return SELECTION_ID_UNDEFINED == d_selectionId; + return d_finalize; } // ------------------ diff --git a/src/groups/mqb/mqbcmd/mqbcmd_parseutil.cpp b/src/groups/mqb/mqbcmd/mqbcmd_parseutil.cpp index 4e90c9e02..174aff239 100644 --- a/src/groups/mqb/mqbcmd/mqbcmd_parseutil.cpp +++ b/src/groups/mqb/mqbcmd/mqbcmd_parseutil.cpp @@ -575,14 +575,25 @@ int parseDomainRemove(DomainRemove* remove, bsl::string* error, WordGenerator next) { - const bslstl::StringRef domain = next(); + const bslstl::StringRef domain = next(); + const bslstl::StringRef finalize = next(); if (domain.empty()) { *error = "DOMAINS REMOVE command must be followed by a " "domain name."; return -1; // RETURN } - remove->makeDomain(domain); + + remove->domain() = domain; + + if (equalCaseless(finalize, "finalize")) { + remove->finalize().makeValue(true); + } + else if (!finalize.empty()) { + *error = "Invalid optional key word '" + finalize + + "' for DOMAINS REMOVE [finalize]"; + return -1; + } return expectEnd(error, next); }