Util.cpp
Go to the documentation of this file.
1// **********************************************************************
2//
3// Copyright (c) 2003-2017 ZeroC, Inc. All rights reserved.
4//
5// This copy of Ice is licensed to you under the terms described in the
6// ICE_LICENSE file included in this distribution.
7//
8// **********************************************************************
9
10#include <IceStorm/Instance.h>
12#include <IceStorm/Util.h>
13
14using namespace IceStorm;
15using namespace std;
16
17namespace IceStormInternal
18{
20}
21
22string
24{
25 //
26 // Work out the topic name. If the category is empty then we're in
27 // backwards compatibility mode and the name is just
28 // identity.name. Otherwise identity.name is topic.<topicname>.
29 //
30 if (id.category.empty())
31 {
32 return id.name;
33 }
34
35 assert(id.name.length() > 6 && id.name.compare(0, 6, "topic.") == 0);
36 return id.name.substr(6);
37}
38
39Ice::Identity
40IceStormInternal::nameToIdentity(const InstancePtr& instance, const string& name)
41{
42 // Identity is instanceName>/topic.<topicname>
43 Ice::Identity id;
44 id.category = instance->instanceName();
45 id.name = "topic." + name;
46
47 return id;
48}
49
50string
51IceStormInternal::describeEndpoints(const Ice::ObjectPrx& proxy)
52{
53 ostringstream os;
54 if (proxy)
55 {
56 Ice::EndpointSeq endpoints = proxy->ice_getEndpoints();
57 for (Ice::EndpointSeq::const_iterator i = endpoints.begin(); i != endpoints.end(); ++i)
58 {
59 if (i != endpoints.begin())
60 {
61 os << ", ";
62 }
63 os << "\"" << (*i)->toString() << "\"";
64 }
65 }
66 else
67 {
68 os << "subscriber proxy is null";
69 }
70 return os.str();
71}
72
73int
74IceStormInternal::compareSubscriberRecordKey(const MDB_val* v1, const MDB_val* v2)
75{
78 k1, *v1, dbContext);
80 k2, *v2, dbContext);
81 if (k1 < k2)
82 {
83 return -1;
84 }
85 else if (k1 == k2)
86 {
87 return 0;
88 }
89 else
90 {
91 return 1;
92 }
93}
94
97{
99 lluMap.get(txn, lluDbKey, llu);
100 llu.iteration++;
101 lluMap.put(txn, lluDbKey, llu);
102 return llu;
103}
void put(const ReadWriteTxn &txn, const K &key, const D &data, unsigned int flags=0)
Definition IceDB.h:261
bool get(const Txn &txn, const K &key, D &data) const
Definition IceDB.h:243
int compareSubscriberRecordKey(const MDB_val *v1, const MDB_val *v2)
Definition Util.cpp:74
std::string identityToTopicName(const Ice::Identity &)
Definition Util.cpp:23
IceDB::IceContext dbContext
Definition Util.cpp:19
Ice::Identity nameToIdentity(const IceStorm::InstancePtr &, const std::string &)
IceStormElection::LogUpdate getIncrementedLLU(const IceDB::ReadWriteTxn &, IceStorm::LLUMap &)
Definition Util.cpp:96
std::string describeEndpoints(const Ice::ObjectPrx &)
Definition Util.cpp:51
const std::string lluDbKey
Definition Util.h:36
IceUtil::Handle< Instance > InstancePtr
Definition Instance.h:128
IceDB::Dbi< std::string, IceStormElection::LogUpdate, IceDB::IceContext, Ice::OutputStream > LLUMap
Definition Util.h:34
A struct used for marking the last log update.
Definition LLURecord.h:103
The key for persistent subscribers, or topics.