本文整理汇总了C++中Metadata::addMetadata方法的典型用法代码示例。如果您正苦于以下问题:C++ Metadata::addMetadata方法的具体用法?C++ Metadata::addMetadata怎么用?C++ Metadata::addMetadata使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Metadata
的用法示例。
在下文中一共展示了Metadata::addMetadata方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: createRoutingInformationDataObject
DataObjectRef Forwarder::createRoutingInformationDataObject()
{
// No need to have a reference in this function because it won't be
// visible outside until this function is done with it.
DataObjectRef dObj = DataObject::create();
if (!dObj)
return NULL;
HAGGLE_DBG2("Creating routing info data object\n");
dObj->setPersistent(false);
dObj->addAttribute("Forwarding", getName());
// Add the metric data to the forwarding section:
Metadata *md = dObj->getMetadata()->addMetadata(getManager()->getName());
md = md->addMetadata(getName());
md->setParameter("node_id", getKernel()->getThisNode()->getIdStr());
if (!addRoutingInformation(dObj, md)) {
// SW: ERR->DBG, this is not fatal, we return false when we don't want
// to add routing data.
// HAGGLE_DBG("Could not add routing information\n");
return NULL;
}
return dObj;
}
示例2: onSendDataObject
/*
On send events, the security manager
*/
void SecurityManager::onSendDataObject(Event *e)
{
if (!e || !e->hasData())
return;
DataObjectRef dObj = e->getDataObject();
if (dObj->isThisNodeDescription()) {
// This is our node description. Piggy-back our certificate.
if (myCert) {
Metadata *m;
m = dObj->getMetadata()->getMetadata("Security");
if (m) {
HAGGLE_ERR("Node description already has a Security tag!\n");
} else {
m = dObj->getMetadata()->addMetadata("Security");
if (m) {
m->addMetadata(myCert->toMetadata());
}
}
}
}
// In most cases the data object is already signed here (e.g., if it is generated by a local
// application, or was received from another node). The only reason to check if we should
// sign the data object here, is if a data object was generated internally by Haggle -- in
// which case the data object might not have a signature (e.g., the data object is a node
// description).
InterfaceRef iface = dObj->getRemoteInterface();
if (dObj->shouldSign() && !(iface && iface->getType() == Interface::TYPE_APPLICATION_PORT)) {
// FIXME: data objects should really be signed in the SecurityHelper thread since
// it is a potentially CPU intensive operation. But it is currently not possible
// to ensure that the signing operation has finished in the helper thread before
// the data object is actually sent on the wire by the protocol manager.
// To handle this situation, we probably need to add a new public event for
// security related operations, after which the security manager generates the
// real send event.
if (helper->signDataObject(dObj, privKey)) {
HAGGLE_DBG("Successfully signed data object %s\n", dObj->getIdStr());
} else {
HAGGLE_DBG("Signing of data object %s failed!\n", dObj->getIdStr());
}
}
}
示例3: log_eventQueue
void HaggleKernel::log_eventQueue(Metadata *m) {
HashMap<string, size_t> counts;
HashMap<string, size_t>::iterator cit;
Heap theHeap;
Metadata *dm = m->addMetadata("Events");
if (!dm) {
return;
}
List<Event *> list = getEventList();
for (List<Event *>::iterator it = list.begin(); it != list.end(); it++) {
Event *e = *it;
theHeap.insert(*it);
cit = counts.find(e->getName());
if (cit == counts.end()) {
counts.insert(make_pair(e->getName(), 1));
} else {
size_t count = (*cit).second;
counts.erase(cit);
counts.insert(make_pair(e->getName(), count+1));
}
}
for (size_t i = 0; i < list.size(); i++) {
Event *e = static_cast<Event *>(theHeap.extractFirst());
if (e) {
if (i < 200) {
Metadata *dmm = dm->addMetadata("Event");
dmm->setParameter("name", e->getName());
dmm->setParameter("time", e->getTimeout().getAsString());
dmm->setParameter("canceled", e->isCanceled() ? "true" : "false");
if (e->getDataObject()) {
dmm->setParameter("dObj", e->getDataObject()->getIdStr());
}
if (e->getNode()) {
dmm->setParameter("node", e->getNode()->getIdStr());
}
if (e->getInterface()) {
dmm->setParameter("iface", e->getInterface()->getIdentifierStr());
}
if (e->getNodeList().size() > 0) {
dmm->setParameter("nodeListSize", e->getNodeList().size());
}
if (e->getDataObjectList().size() > 0) {
dmm->setParameter("dataObjectListSize", e->getDataObjectList().size());
}
if (strcmp(e->getName(), "BFRemoveDelay") == 0) {
const DataObjectId_t *id = (DataObjectId_t *) e->getData();
if (id) {
dmm->setParameter("dObj", DataObject::idString(*id));
}
}
}
delete e;
}
}
dm = m->addMetadata("Counts");
if (!dm) {
return;
}
for (cit = counts.begin(); cit != counts.end(); cit++) {
Metadata *dmm = dm->addMetadata("Event");
if (dmm) {
dmm->setParameter("name", (*cit).first);
dmm->setParameter("count", (*cit).second);
}
}
}
示例4: main
int main(void){
Metadata metadata;
metadata.addMetadata("key1", "val1");
vector<string> values;
values.push_back("val1");
values.push_back("val2");
values.push_back("val3");
metadata.addMetadata("key2", values);
cout << "Checking the value of key1: Value: " << metadata.getMetadata("key1") << endl;
cout << "Checking the value of key2: Value: " << metadata.getMetadata("key2") << endl;
vector<string> key2Vals = metadata.getAllMetadata("key2");
cout << "Checking all values for key2: Values: " << endl;
for(int i=0; i < key2Vals.size(); i++){
cout << "Value: " << key2Vals[i] << endl;
}
if(metadata.getAllMetadata("key3") == cas::Metadata::EMPTY_VEC){
cout << "No multiple values for key3!" << endl;
}
if(metadata.getMetadata("key3") == cas::Metadata::EMPTY_STR){
cout << "No singular value for key3!" << endl;
}
metadata.addMetadata("key3", "val3");
if(metadata.getMetadata("key3") != cas::Metadata::EMPTY_STR){
cout << "New value for key3: " << metadata.getMetadata("key3") << endl;
}
if(!metadata.containsKey("blah")){
cout << "Metadata doesn't contain key blah: correct!" << endl;
}
if(metadata.containsKey("key3")){
cout << "Metadata contains key key3: correct!" << endl;
}
if(metadata.isMultiValued("key2")){
cout << "Key2 is correctly multi-valued: correct!" << endl;
}
if(!metadata.isMultiValued("key3")){
cout << "Key3 is correctly NOT multi-valued: correct!" << endl;
}
metadata.addMetadata("key4", "val99");
if(metadata.getMetadata("key4") != cas::Metadata::EMPTY_STR){
cout << "Metadata exists for key4, now deleting key4 and retesting" << endl;
metadata.removeMetadata("key4");
if(metadata.getMetadata("key4") == cas::Metadata::EMPTY_STR){
cout << "Metadata successfully removed for key4! " << endl;
}
}
vector<string> key5vals;
key5vals.push_back("key5val1");
key5vals.push_back("key5val2");
metadata.addMetadata("key5", key5vals);
vector<string> key5replvals;
key5replvals.push_back("key5_replaced_val1");
key5replvals.push_back("key5_replaced_val2");
metadata.replaceMetadata("key5", key5replvals);
for(int i=0; i < metadata.getAllMetadata("key5").size(); i++){
cout << "Value: " << metadata.getAllMetadata("key5")[i] << endl;
}
metadata.addMetadata("key6", "key6val1");
if(metadata.getMetadata("key6") == "key6val1"){
cout << "key6: value = key6val1, as appropriate" << endl;
}
metadata.replaceMetadata("key6", "key6_replaced_val1");
if(metadata.getMetadata("key6") == "key6_replaced_val1"){
cout << "key6: value = key6_replaced_val1, as appropriate" << endl;
}
cout << "XML is: " << endl;
DOMDocument* doc = metadata.toXML();
XMLCh tempStr[100];
//.........这里部分代码省略.........
示例5: getKnapsackOptimizer
// CBMEN, HL, Begin
void
CacheStrategyUtility::_handleGetCacheStrategyAsMetadata(Metadata *m)
{
Metadata *dm = m->addMetadata("CacheStrategyUtility");
if (!dm) {
return;
}
dm->setParameter("knapsack_optimizer", getKnapsackOptimizer()->getName());
dm->setParameter("global_optimizer", getGlobalOptimizer()->getPrettyName());
dm->setParameter("utility_function", getUtilityFunction()->getPrettyName());
dm->setParameter("utility_compute_period_ms", computePeriodMs);
dm->setParameter("poll_period_ms", pollPeriodMs);
dm->setParameter("event_based_purging", purgeOnInsert ? "enabled" : "disabled");
dm->setParameter("keep_in_bloomfilter", keep_in_bloomfilter ? "enabled" : "disabled");
dm->setParameter("bloomfilter_remove_delay_ms", bloomfilter_remove_delay_ms);
dm->setParameter("handle_zero_size", handle_zero_size ? "enabled" : "disabled");
dm->setParameter("manage_only_remote_files", manage_only_remote_files ? "enabled" : "disabled");
dm->setParameter("manage_locally_sent_files", manage_locally_sent_files ? "enabled" : "disabled");
dm->setParameter("allow_db_purging", allow_db_purging ? "enabled" : "disabled");
dm->setParameter("db_size_threshold", db_size_threshold);
dm->setParameter("current_size_kb", current_size / (long long) 1024);
dm->setParameter("max_capacity_kb", max_capacity_kb);
dm->setParameter("current_capacity_ratio", 100*current_size/((double)max_capacity_kb * 1024));
dm->setParameter("watermark_capacity_kb", watermark_capacity_kb);
dm->setParameter("watermark_capacity_ratio", 100*current_size/((double)watermark_capacity_kb * 1024));
dm->setParameter("current_num_do", current_num_do);
dm->setParameter("total_db_evicted", total_db_evicted);
dm->setParameter("current_dupe_do_recv", current_dupe_do_recv);
dm->setParameter("current_drop_on_insert", current_drop_on_insert);
dm->setParameter("total_do_inserted", total_do_inserted);
dm->setParameter("total_do_inserted_bytes", total_do_inserted_bytes);
dm->setParameter("total_do_evicted", total_do_evicted);
dm->setParameter("total_do_evicted_bytes", total_do_evicted_bytes);
dm->setParameter("total_do_hard_evicted", total_do_hard_evicted);
dm->setParameter("total_do_hard_evicted_bytes", total_do_hard_evicted_bytes);
PrintHelperHeapItem::PrinterHelperType_t types[] = {PrintHelperHeapItem::HIGH_UTIL, PrintHelperHeapItem::LOW_UTIL, PrintHelperHeapItem::HIGH_COST, PrintHelperHeapItem::OLD_CREATION};
string names[] = {"Top10Utility", "Bottom10Utility", "Top10Largest", "Top10Oldest"};
do_util_metadata_list_t metadata_list;
for (size_t i = 0; i < 4; i++)
{
Metadata *dmm = dm->addMetadata(names[i]);
if (!dmm) {
continue;
}
PrintHelperHeapItem::getTopKHelper(10, types[i], utilMetadata, &metadata_list);
for (do_util_metadata_list_t::iterator it = metadata_list.begin(); it != metadata_list.end(); it++) {
Metadata *dmmm = dmm->addMetadata("DataObject");
if (!dmmm) {
break;
}
DataObjectUtilityMetadata *do_metadata = *it;
dmmm->setParameter("id", do_metadata->getId());
dmmm->setParameter("create_time", do_metadata->getCreateTime().getAsString());
dmmm->setParameter("computed_time", do_metadata->getComputedTime().getAsString());
dmmm->setParameter("cost", do_metadata->getCost());
dmmm->setParameter("utility", do_metadata->getUtility());
}
metadata_list.clear();
}
kernel->addEvent(new Event(EVENT_TYPE_SEND_OBSERVER_DATAOBJECT, m->copy()));
}