diff options
author | Kenneth Anthony Giusti <kgiusti@apache.org> | 2010-09-15 19:05:34 +0000 |
---|---|---|
committer | Kenneth Anthony Giusti <kgiusti@apache.org> | 2010-09-15 19:05:34 +0000 |
commit | 01fda72abf335c795df091ae6ea6a0b3a22ec72f (patch) | |
tree | 0722b5819740c5958263e1ad6b631a4c7c959cdc /cpp/src/qpid/agent | |
parent | baae1f527b493a2ad568d75c2e2dbd3ede8dbce1 (diff) | |
download | qpid-python-01fda72abf335c795df091ae6ea6a0b3a22ec72f.tar.gz |
QPID-2859: Save the agent's name to the configuration file.
git-svn-id: https://svn.apache.org/repos/asf/qpid/trunk/qpid@997453 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'cpp/src/qpid/agent')
-rw-r--r-- | cpp/src/qpid/agent/ManagementAgentImpl.cpp | 79 | ||||
-rw-r--r-- | cpp/src/qpid/agent/ManagementAgentImpl.h | 2 |
2 files changed, 61 insertions, 20 deletions
diff --git a/cpp/src/qpid/agent/ManagementAgentImpl.cpp b/cpp/src/qpid/agent/ManagementAgentImpl.cpp index d4c2933751..a015bcaba0 100644 --- a/cpp/src/qpid/agent/ManagementAgentImpl.cpp +++ b/cpp/src/qpid/agent/ManagementAgentImpl.cpp @@ -135,20 +135,12 @@ void ManagementAgentImpl::setName(const string& vendor, const string& product, c if (product.find(':') != product.npos) { throw Exception("product string cannot contain a ':' character."); } + attrMap["_vendor"] = vendor; attrMap["_product"] = product; - string inst; - if (instance.empty()) { - inst = qpid::types::Uuid(true).str(); - } else - inst = instance; - - name_address = vendor + ":" + product + ":" + inst; - vendorNameKey = keyifyNameStr(vendor); - productNameKey = keyifyNameStr(product); - instanceNameKey = keyifyNameStr(inst); - attrMap["_instance"] = inst; - attrMap["_name"] = name_address; + if (!instance.empty()) { + attrMap["_instance"] = instance; + } } @@ -192,14 +184,13 @@ void ManagementAgentImpl::init(const qpid::management::ConnectionSettings& setti bool useExternalThread, const string& _storeFile) { + std::string cfgVendor, cfgProduct, cfgInstance; + interval = intervalSeconds; extThread = useExternalThread; storeFile = _storeFile; nextObjectId = 1; - QPID_LOG(info, "QMF Agent Initialized: broker=" << settings.host << ":" << settings.port << - " interval=" << intervalSeconds << " storeFile=" << _storeFile); - // // Convert from management::ConnectionSettings to client::ConnectionSettings // @@ -220,14 +211,36 @@ void ManagementAgentImpl::init(const qpid::management::ConnectionSettings& setti connectionSettings.minSsf = settings.minSsf; connectionSettings.maxSsf = settings.maxSsf; - retrieveData(); + retrieveData(cfgVendor, cfgProduct, cfgInstance); + bootSequence++; if ((bootSequence & 0xF000) != 0) bootSequence = 1; + + // setup the agent's name. The name may be set via a call to setName(). If setName() + // has not been called, the name can be read from the configuration file. If there is + // no name in the configuration file, a unique default name is provided. + if (attrMap.empty()) { + // setName() never called by application, so use names retrieved from config, otherwise defaults. + setName(cfgVendor.empty() ? defaultVendorName : cfgVendor, + cfgProduct.empty() ? defaultProductName : cfgProduct, + cfgInstance.empty() ? qpid::types::Uuid(true).str() : cfgInstance); + } else if (attrMap.find("_instance") == attrMap.end()) { + // setName() called, but instance was not specified, use config or generate a uuid + setName(attrMap["_vendor"].asString(), attrMap["_product"].asString(), + cfgInstance.empty() ? qpid::types::Uuid(true).str() : cfgInstance); + } + + name_address = attrMap["_vendor"].asString() + ":" + attrMap["_product"].asString() + ":" + attrMap["_instance"].asString(); + vendorNameKey = keyifyNameStr(attrMap["_vendor"].asString()); + productNameKey = keyifyNameStr(attrMap["_product"].asString()); + instanceNameKey = keyifyNameStr(attrMap["_instance"].asString()); + attrMap["_name"] = name_address; + storeData(true); - if (attrMap.empty()) - setName(defaultVendorName, defaultProductName); + QPID_LOG(info, "QMF Agent Initialized: broker=" << settings.host << ":" << settings.port << + " interval=" << intervalSeconds << " storeFile=" << _storeFile << " name=" << name_address); initialized = true; } @@ -398,13 +411,25 @@ void ManagementAgentImpl::storeData(bool requested) if (outFile.good()) { outFile << storeMagicNumber << " " << brokerBankToWrite << " " << agentBankToWrite << " " << bootSequence << endl; + + if (attrMap.find("_vendor") != attrMap.end()) + outFile << "vendor=" << attrMap["_vendor"] << endl; + if (attrMap.find("_product") != attrMap.end()) + outFile << "product=" << attrMap["_product"] << endl; + if (attrMap.find("_instance") != attrMap.end()) + outFile << "instance=" << attrMap["_instance"] << endl; + outFile.close(); } } } -void ManagementAgentImpl::retrieveData() +void ManagementAgentImpl::retrieveData(std::string& vendor, std::string& product, std::string& inst) { + vendor.clear(); + product.clear(); + inst.clear(); + if (!storeFile.empty()) { ifstream inFile(storeFile.c_str()); string mn; @@ -412,9 +437,25 @@ void ManagementAgentImpl::retrieveData() if (inFile.good()) { inFile >> mn; if (mn == storeMagicNumber) { + std::string inText; + inFile >> requestedBrokerBank; inFile >> requestedAgentBank; inFile >> bootSequence; + + while (inFile.good()) { + std::getline(inFile, inText); + if (!inText.compare(0, 7, "vendor=")) { + vendor = inText.substr(7); + QPID_LOG(debug, "read vendor name [" << vendor << "] from configuration file."); + } else if (!inText.compare(0, 8, "product=")) { + product = inText.substr(8); + QPID_LOG(debug, "read product name [" << product << "] from configuration file."); + } else if (!inText.compare(0, 9, "instance=")) { + inst = inText.substr(9); + QPID_LOG(debug, "read instance name [" << inst << "] from configuration file."); + } + } } inFile.close(); } diff --git a/cpp/src/qpid/agent/ManagementAgentImpl.h b/cpp/src/qpid/agent/ManagementAgentImpl.h index c2d490c7ba..be90640ec7 100644 --- a/cpp/src/qpid/agent/ManagementAgentImpl.h +++ b/cpp/src/qpid/agent/ManagementAgentImpl.h @@ -257,7 +257,7 @@ class ManagementAgentImpl : public ManagementAgent, public client::MessageListen void startProtocol(); void storeData(bool requested=false); - void retrieveData(); + void retrieveData(std::string& vendor, std::string& product, std::string& inst); PackageMap::iterator findOrAddPackage(const std::string& name); void moveNewObjectsLH(); void addClassLocal (uint8_t classKind, |