void TransientTopicImpl::link(const TopicPrx& topic, Ice::Int cost, const Ice::Current&) { TopicInternalPrx internal = TopicInternalPrx::uncheckedCast(topic); TopicLinkPrx link = internal->getLinkProxy(); TraceLevelsPtr traceLevels = _instance->traceLevels(); if(traceLevels->topic > 0) { Ice::Trace out(traceLevels->logger, traceLevels->topicCat); out << _name << ": link " << _instance->communicator()->identityToString(topic->ice_getIdentity()) << " cost " << cost; } Lock sync(*this); Ice::Identity id = topic->ice_getIdentity(); SubscriberRecord record; record.id = id; record.obj = link; record.theTopic = topic; record.topicName = _name; record.link = true; record.cost = cost; vector<SubscriberPtr>::iterator p = find(_subscribers.begin(), _subscribers.end(), record.id); if(p != _subscribers.end()) { throw LinkExists(IceStormInternal::identityToTopicName(id)); } SubscriberPtr subscriber = Subscriber::create(_instance, record); _subscribers.push_back(subscriber); }
void Parser::subscribers(const list<string>& args) { if(args.empty()) { error("subscribers' requires at least one argument (type `help' for more info) "); return; } try { for(list<string>::const_iterator i = args.begin(); i != args.end() ; ++i) { TopicPrx topic = _defaultManager->retrieve(*i); cout << (*i) << ": subscribers:" << endl; IdentitySeq subscribers = topic->getSubscribers(); for(IdentitySeq::const_iterator j = subscribers.begin(); j != subscribers.end(); ++j) { cout << "\t" << _communicator->identityToString(*j) << endl; } } } catch(const Exception& ex) { exception(ex); } }
void Client::run(int argc, char** argv) { Ice::CommunicatorHolder communicator = initialize(argc, argv); ObjectPrx base = communicator->stringToProxy("Test.IceStorm/TopicManager"); IceStorm::TopicManagerPrx manager = IceStorm::TopicManagerPrx::checkedCast(base); if(!manager) { ostringstream os; os << argv[0] << ": `Test.IceStorm/TopicManager' is not running"; throw invalid_argument(os.str()); } ObjectAdapterPtr adapter = communicator->createObjectAdapterWithEndpoints("SingleAdapter", "default:udp"); TopicPrx topic = manager->create("single"); // // Create subscribers with different QoS. // SingleIPtr sub = new SingleI; topic->subscribeAndGetPublisher(IceStorm::QoS(), adapter->addWithUUID(sub)); adapter->activate(); // Ensure that getPublisher & getNonReplicatedPublisher work // correctly. Ice::ObjectPrx p1 = topic->getPublisher(); Ice::ObjectPrx p2 = topic->getNonReplicatedPublisher(); test(p1->ice_getAdapterId() == "PublishReplicaGroup"); test(p2->ice_getAdapterId() == "Test.IceStorm1.Publish" || p2->ice_getAdapterId() == "Test.IceStorm2.Publish" || p2->ice_getAdapterId() == "Test.IceStorm3.Publish"); // // Get a publisher object, create a twoway proxy and then cast to // a Single object. // SinglePrx single = SinglePrx::uncheckedCast(topic->getPublisher()->ice_twoway()); for(int i = 0; i < 1000; ++i) { single->event(i); } sub->waitForEvents(); }
int run(int, char* argv[], const CommunicatorPtr& communicator) { PropertiesPtr properties = communicator->getProperties(); const char* managerProxyProperty = "IceStormAdmin.TopicManager.Default"; string managerProxy = properties->getProperty(managerProxyProperty); if(managerProxy.empty()) { cerr << argv[0] << ": property `" << managerProxyProperty << "' is not set" << endl; return EXIT_FAILURE; } IceStorm::TopicManagerPrx manager = IceStorm::TopicManagerPrx::checkedCast( communicator->stringToProxy(managerProxy)); if(!manager) { cerr << argv[0] << ": `" << managerProxy << "' is not running" << endl; return EXIT_FAILURE; } TopicPrx topic; try { topic = manager->retrieve("single"); } catch(const NoSuchTopic& e) { cerr << argv[0] << ": NoSuchTopic: " << e.name << endl; return EXIT_FAILURE; } assert(topic); // // Get a publisher object, create a twoway proxy and then cast to // a Single object. // SinglePrx single = SinglePrx::uncheckedCast(topic->getPublisher()->ice_twoway()); for(int i = 0; i < 1000; ++i) { single->event(i); } return EXIT_SUCCESS; }
void Parser::unlink(const list<string>& args) { if(args.size() != 2) { error("`unlink' requires exactly two arguments (type `help' for more info)"); return; } try { list<string>::const_iterator p = args.begin(); TopicPrx fromTopic = findTopic(*p++); TopicPrx toTopic = findTopic(*p++); fromTopic->unlink(toTopic); } catch(const Exception& ex) { exception(ex); } }
void Parser::link(const list<string>& args) { if(args.size() != 2 && args.size() != 3) { error("`link' requires two or three arguments (type `help' for more info)"); return; } try { list<string>::const_iterator p = args.begin(); TopicPrx fromTopic = findTopic(*p++); TopicPrx toTopic = findTopic(*p++); Ice::Int cost = p != args.end() ? atoi(p->c_str()) : 0; fromTopic->link(toTopic, cost); } catch(const Exception& ex) { exception(ex); } }
void TransientTopicImpl::unlink(const TopicPrx& topic, const Ice::Current&) { Lock sync(*this); if(_destroyed) { throw Ice::ObjectNotExistException(__FILE__, __LINE__); } Ice::Identity id = topic->ice_getIdentity(); vector<SubscriberPtr>::iterator p = find(_subscribers.begin(), _subscribers.end(), id); if(p == _subscribers.end()) { string name = IceStormInternal::identityToTopicName(id); TraceLevelsPtr traceLevels = _instance->traceLevels(); if(traceLevels->topic > 0) { Ice::Trace out(traceLevels->logger, traceLevels->topicCat); out << _name << ": unlink " << name << " failed - not linked"; } throw NoSuchLink(name); } TraceLevelsPtr traceLevels = _instance->traceLevels(); if(traceLevels->topic > 0) { Ice::Trace out(traceLevels->logger, traceLevels->topicCat); out << _name << " unlink " << _instance->communicator()->identityToString(id); } // Remove the subscriber from the subscribers list. Note // that its possible that the subscriber isn't in the list, but is // in the database if the subscriber was locally reaped. p = find(_subscribers.begin(), _subscribers.end(), id); if(p != _subscribers.end()) { (*p)->destroy(); _subscribers.erase(p); } }
void TopicImpl::unlink(const TopicPrx& topic) { IceUtil::Mutex::Lock sync(_subscribersMutex); if(_destroyed) { throw Ice::ObjectNotExistException(__FILE__, __LINE__); } Ice::Identity id = topic->ice_getIdentity(); vector<SubscriberPtr>::const_iterator p = find(_subscribers.begin(), _subscribers.end(), id); if(p == _subscribers.end()) { string name = identityToTopicName(id); TraceLevelsPtr traceLevels = _instance->traceLevels(); if(traceLevels->topic > 0) { Ice::Trace out(traceLevels->logger, traceLevels->topicCat); out << _name << ": unlink " << name << " failed - not linked"; } NoSuchLink ex; ex.name = name; throw ex; } TraceLevelsPtr traceLevels = _instance->traceLevels(); if(traceLevels->topic > 0) { Ice::Trace out(traceLevels->logger, traceLevels->topicCat); out << _name << " unlink " << _instance->communicator()->identityToString(id); } Ice::IdentitySeq ids; ids.push_back(id); removeSubscribers(ids); }
void TopicImpl::link(const TopicPrx& topic, Ice::Int cost) { TopicInternalPrx internal = TopicInternalPrx::uncheckedCast(topic); TopicLinkPrx link = internal->getLinkProxy(); TraceLevelsPtr traceLevels = _instance->traceLevels(); if(traceLevels->topic > 0) { Ice::Trace out(traceLevels->logger, traceLevels->topicCat); out << _name << ": link " << _instance->communicator()->identityToString(topic->ice_getIdentity()) << " cost " << cost; } IceUtil::Mutex::Lock sync(_subscribersMutex); Ice::Identity id = topic->ice_getIdentity(); SubscriberRecord record; record.id = id; record.obj = link; record.theTopic = topic; record.topicName = _name; record.link = true; record.cost = cost; vector<SubscriberPtr>::iterator p = find(_subscribers.begin(), _subscribers.end(), record.id); if(p != _subscribers.end()) { string name = identityToTopicName(id); LinkExists ex; ex.name = name; throw ex; } LogUpdate llu; SubscriberPtr subscriber = Subscriber::create(_instance, record); for(;;) { try { DatabaseConnectionPtr connection = _connectionPool->newConnection(); TransactionHolder txn(connection); SubscriberRecordKey key; key.topic = _id; key.id = id; SubscribersWrapperPtr subscribersWrapper = _connectionPool->getSubscribers(connection); subscribersWrapper->put(key, record); LLUWrapperPtr lluWrapper = _connectionPool->getLLU(connection); llu = lluWrapper->get(); llu.iteration++; lluWrapper->put(llu); txn.commit(); break; } catch(const DeadlockException&) { continue; } catch(const DatabaseException& ex) { halt(_instance->communicator(), ex); } } _subscribers.push_back(subscriber); _instance->observers()->addSubscriber(llu, _name, record); }
int run(int argc, char* argv[], const CommunicatorPtr& communicator) { IceUtilInternal::Options opts; opts.addOpt("", "cycle"); try { opts.parse(argc, (const char**)argv); } catch(const IceUtilInternal::BadOptException& e) { cerr << argv[0] << ": " << e.reason << endl; return EXIT_FAILURE; } PropertiesPtr properties = communicator->getProperties(); const char* managerProxyProperty = "IceStormAdmin.TopicManager.Default"; string managerProxy = properties->getProperty(managerProxyProperty); if(managerProxy.empty()) { cerr << argv[0] << ": property `" << managerProxyProperty << "' is not set" << endl; return EXIT_FAILURE; } IceStorm::TopicManagerPrx manager = IceStorm::TopicManagerPrx::checkedCast( communicator->stringToProxy(managerProxy)); if(!manager) { cerr << argv[0] << ": `" << managerProxy << "' is not running" << endl; return EXIT_FAILURE; } TopicPrx topic; while(true) { try { topic = manager->retrieve("single"); break; } // This can happen if the replica group loses the majority // during retrieve. In this case we retry. catch(const Ice::UnknownException&) { continue; } catch(const IceStorm::NoSuchTopic& e) { cerr << argv[0] << ": NoSuchTopic: " << e.name << endl; return EXIT_FAILURE; } } assert(topic); // // Get a publisher object, create a twoway proxy and then cast to // a Single object. // if(opts.isSet("cycle")) { Ice::ObjectPrx prx = topic->getPublisher()->ice_twoway(); vector<SinglePrx> single; Ice::EndpointSeq endpoints = prx->ice_getEndpoints(); for(Ice::EndpointSeq::const_iterator p = endpoints.begin(); p != endpoints.end(); ++p) { if((*p)->toString().substr(0, 3) != "udp") { Ice::EndpointSeq e; e.push_back(*p); single.push_back(SinglePrx::uncheckedCast(prx->ice_endpoints(e))); } } if(single.size() <= 1) { cerr << argv[0] << ": Not enough endpoints in publisher proxy" << endl; return EXIT_FAILURE; } int which = 0; for(int i = 0; i < 1000; ++i) { single[which]->event(i); which = (which + 1) % static_cast<int>(single.size()); } } else { SinglePrx single = SinglePrx::uncheckedCast(topic->getPublisher()->ice_twoway()); for(int i = 0; i < 1000; ++i) { single->event(i); } } return EXIT_SUCCESS; }
void TopicImpl::link(const TopicPrx& topic, Ice::Int cost) { TopicInternalPrx internal = TopicInternalPrx::uncheckedCast(topic); TopicLinkPrx link = internal->getLinkProxy(); TraceLevelsPtr traceLevels = _instance->traceLevels(); if(traceLevels->topic > 0) { Ice::Trace out(traceLevels->logger, traceLevels->topicCat); out << _name << ": link " << _instance->communicator()->identityToString(topic->ice_getIdentity()) << " cost " << cost; } IceUtil::Mutex::Lock sync(_subscribersMutex); Ice::Identity id = topic->ice_getIdentity(); SubscriberRecord record; record.id = id; record.obj = link; record.theTopic = topic; record.topicName = _name; record.link = true; record.cost = cost; vector<SubscriberPtr>::iterator p = find(_subscribers.begin(), _subscribers.end(), record.id); if(p != _subscribers.end()) { string name = IceStormInternal::identityToTopicName(id); LinkExists ex; ex.name = name; throw ex; } LogUpdate llu; SubscriberPtr subscriber = Subscriber::create(_instance, record); try { IceDB::ReadWriteTxn txn(_instance->dbEnv()); SubscriberRecordKey key; key.topic = _id; key.id = id; _subscriberMap.put(txn, key, record); llu = getIncrementedLLU(txn, _lluMap); txn.commit(); } catch(const IceDB::LMDBException& ex) { logError(_instance->communicator(), ex); throw; // will become UnknownException in caller } _subscribers.push_back(subscriber); _instance->observers()->addSubscriber(llu, _name, record); }
int run(int argc, char* argv[], const CommunicatorPtr& communicator) { IceUtilInternal::Options opts; opts.addOpt("", "ordered"); opts.addOpt("", "twoway"); opts.addOpt("", "events", IceUtilInternal::Options::NeedArg); try { opts.parse(argc, (const char**)argv); } catch(const IceUtilInternal::BadOptException& e) { cerr << argv[0] << ": " << e.reason << endl; return EXIT_FAILURE; } PropertiesPtr properties = communicator->getProperties(); const char* managerProxyProperty = "IceStormAdmin.TopicManager.Default"; string managerProxy = properties->getProperty(managerProxyProperty); if(managerProxy.empty()) { cerr << argv[0] << ": property `" << managerProxyProperty << "' is not set" << endl; return EXIT_FAILURE; } ObjectPrx base = communicator->stringToProxy(managerProxy); IceStorm::TopicManagerPrx manager = IceStorm::TopicManagerPrx::checkedCast(base); if(!manager) { cerr << argv[0] << ": `" << managerProxy << "' is not running" << endl; return EXIT_FAILURE; } ObjectAdapterPtr adapter = communicator->createObjectAdapterWithEndpoints("SingleAdapter", "default"); TopicPrx topic; while(true) { try { topic = manager->retrieve("single"); break; } // This can happen if the replica group loses the majority // during retrieve. In this case we retry. catch(const Ice::UnknownException&) { continue; } catch(const IceStorm::NoSuchTopic& e) { cerr << argv[0] << ": NoSuchTopic: " << e.name << endl; return EXIT_FAILURE; } } int events = 1000; if(opts.isSet("events")) { events = atoi(opts.optArg("events").c_str()); } // // Create subscribers with different QoS. // SingleIPtr sub; IceStorm::QoS qos; if(opts.isSet("ordered")) { sub = new SingleI(communicator, "twoway ordered", events); qos["reliability"] = "ordered"; } else { sub = new SingleI(communicator, "twoway", events); } Ice::ObjectPrx prx = adapter->addWithUUID(sub); while(true) { try { topic->subscribeAndGetPublisher(qos, prx); break; } // If we're already subscribed then we're done (previously we // got an UnknownException which succeeded). catch(const IceStorm::AlreadySubscribed&) { break; } // This can happen if the replica group loses the majority // during subscription. In this case we retry. catch(const Ice::UnknownException&) { } } adapter->activate(); sub->waitForEvents(); topic->unsubscribe(prx); return EXIT_SUCCESS; }
int run(int argc, char* argv[], const CommunicatorPtr& communicator) { IceUtilInternal::Options opts; opts.addOpt("", "id", IceUtilInternal::Options::NeedArg); opts.addOpt("", "unsub"); try { opts.parse(argc, (const char**)argv); } catch(const IceUtilInternal::BadOptException& e) { cerr << argv[0] << ": " << e.reason << endl; return EXIT_FAILURE; } PropertiesPtr properties = communicator->getProperties(); const char* managerProxyProperty = "IceStormAdmin.TopicManager.Default"; string managerProxy = properties->getProperty(managerProxyProperty); if(managerProxy.empty()) { cerr << argv[0] << ": property `" << managerProxyProperty << "' is not set" << endl; return EXIT_FAILURE; } ObjectPrx base = communicator->stringToProxy(managerProxy); IceStorm::TopicManagerPrx manager = IceStorm::TopicManagerPrx::checkedCast(base); if(!manager) { cerr << argv[0] << ": `" << managerProxy << "' is not running" << endl; return EXIT_FAILURE; } ObjectAdapterPtr adapter = communicator->createObjectAdapterWithEndpoints("SingleAdapter", "default"); TopicPrx topic; try { topic = manager->retrieve("single"); } catch(const IceStorm::NoSuchTopic& e) { cerr << argv[0] << ": NoSuchTopic: " << e.name << endl; return EXIT_FAILURE; } Ice::ObjectPrx prx = adapter->add(new SingleI(), communicator->stringToIdentity(opts.optArg("id"))); if(opts.isSet("unsub")) { topic->unsubscribe(prx); } else { IceStorm::QoS qos; qos["persistent"] = "true"; topic->subscribeAndGetPublisher(qos, prx); } return EXIT_SUCCESS; }
int run(int argc, char* argv[], const CommunicatorPtr& communicator) { IceUtilInternal::Options opts; opts.addOpt("", "events", IceUtilInternal::Options::NeedArg); opts.addOpt("", "qos", IceUtilInternal::Options::NeedArg, "", IceUtilInternal::Options::Repeat); opts.addOpt("", "slow"); opts.addOpt("", "erratic", IceUtilInternal::Options::NeedArg); try { opts.parse(argc, (const char**)argv); } catch(const IceUtilInternal::BadOptException& e) { cerr << argv[0] << ": " << e.reason << endl; return EXIT_FAILURE; } int events = 1000; string s = opts.optArg("events"); if(!s.empty()) { events = atoi(s.c_str()); } if(events <= 0) { cerr << argv[0] << ": events must be > 0." << endl; return EXIT_FAILURE; } IceStorm::QoS cmdLineQos; vector<string> sqos = opts.argVec("qos"); for(vector<string>::const_iterator q = sqos.begin(); q != sqos.end(); ++q) { string::size_type off = q->find(","); if(off == string::npos) { cerr << argv[0] << ": parse error: no , in QoS" << endl; return EXIT_FAILURE; } cmdLineQos[q->substr(0, off)] = q->substr(off+1); } bool slow = opts.isSet("slow"); bool erratic = false; int erraticNum = 0; s = opts.optArg("erratic"); if(!s.empty()) { erratic = true; erraticNum = atoi(s.c_str()); } if(events <= 0) { cerr << argv[0] << ": events must be > 0." << endl; return EXIT_FAILURE; } PropertiesPtr properties = communicator->getProperties(); const char* managerProxyProperty = "IceStormAdmin.TopicManager.Default"; string managerProxy = properties->getProperty(managerProxyProperty); if(managerProxy.empty()) { cerr << argv[0] << ": property `" << managerProxyProperty << "' is not set" << endl; return EXIT_FAILURE; } IceStorm::TopicManagerPrx manager = IceStorm::TopicManagerPrx::checkedCast( communicator->stringToProxy(managerProxy)); if(!manager) { cerr << argv[0] << ": `" << managerProxy << "' is not running" << endl; return EXIT_FAILURE; } vector<Subscription> subs; if(erratic) { for(int i = 0 ; i < erraticNum; ++i) { ostringstream os; os << "SubscriberAdapter" << i; Subscription item; item.adapter = communicator->createObjectAdapterWithEndpoints(os.str(), "default"); item.servant = new ErraticEventI(communicator, events); item.qos["reliability"] = "twoway"; subs.push_back(item); } } else if(slow) { Subscription item; item.adapter = communicator->createObjectAdapterWithEndpoints("SubscriberAdapter", "default"); item.servant = new SlowEventI(communicator, events); item.qos = cmdLineQos; subs.push_back(item); } else { Subscription item; item.adapter = communicator->createObjectAdapterWithEndpoints("SubscriberAdapter", "default"); item.qos = cmdLineQos; map<string, string>::const_iterator p = item.qos.find("reliability"); if(p != item.qos.end() && p->second == "ordered") { item.servant = new OrderEventI(communicator, events); } else { item.servant = new CountEventI(communicator, events); } subs.push_back(item); } TopicPrx topic; try { topic = manager->retrieve("fed1"); } catch(const IceStorm::NoSuchTopic& e) { cerr << argv[0] << ": NoSuchTopic: " << e.name << endl; return EXIT_FAILURE; } { for(vector<Subscription>::iterator p = subs.begin(); p != subs.end(); ++p) { p->obj = p->adapter->addWithUUID(p->servant); IceStorm::QoS qos; string reliability = ""; IceStorm::QoS::const_iterator q = p->qos.find("reliability"); if(q != p->qos.end()) { reliability = q->second; } if(reliability == "twoway") { // Do nothing. } else if(reliability == "ordered") { qos["reliability"] = "ordered"; } else if(reliability == "batch") { p->obj = p->obj->ice_batchOneway(); } else //if(reliability == "oneway") { p->obj = p->obj->ice_oneway(); } topic->subscribeAndGetPublisher(qos, p->obj); } } { for(vector<Subscription>::iterator p = subs.begin(); p != subs.end(); ++p) { p->adapter->activate(); } } communicator->waitForShutdown(); { for(vector<Subscription>::const_iterator p = subs.begin(); p != subs.end(); ++p) { topic->unsubscribe(p->obj); if(p->servant->count() != events) { cerr << "expected " << events << " events but got " << p->servant->count() << " events." << endl; return EXIT_FAILURE; } } } return EXIT_SUCCESS; }
int run(int, char* argv[], const CommunicatorPtr& communicator) { PropertiesPtr properties = communicator->getProperties(); const char* managerProxyProperty = "IceStormAdmin.TopicManager.Default"; string managerProxy = properties->getProperty(managerProxyProperty); if(managerProxy.empty()) { cerr << argv[0] << ": property `" << managerProxyProperty << "' is not set" << endl; return EXIT_FAILURE; } ObjectPrx base = communicator->stringToProxy(managerProxy); IceStorm::TopicManagerPrx manager = IceStorm::TopicManagerPrx::checkedCast(base); if(!manager) { cerr << argv[0] << ": `" << managerProxy << "' is not running" << endl; return EXIT_FAILURE; } ObjectAdapterPtr adapter = communicator->createObjectAdapterWithEndpoints("SingleAdapter", "default:udp"); // // Test topic name that is too long // if(string(argv[1]) != "transient") { try { manager->create(string(512, 'A')); test(false); } catch(const Ice::UnknownException&) { } } TopicPrx topic; try { topic = manager->retrieve("single"); } catch(const IceStorm::NoSuchTopic& e) { cerr << argv[0] << ": NoSuchTopic: " << e.name << endl; return EXIT_FAILURE; } // // Test subscriber identity that is too long // if(string(argv[1]) != "transient") { try { Ice::ObjectPrx object = communicator->stringToProxy(string(512, 'A') + ":default -p 10000"); topic->subscribeAndGetPublisher(IceStorm::QoS(), object); test(false); } catch(const Ice::UnknownException&) { } } // // Create subscribers with different QoS. // vector<SingleIPtr> subscribers; vector<Ice::Identity> subscriberIdentities; { subscribers.push_back(new SingleI(communicator, "default")); Ice::ObjectPrx object = adapter->addWithUUID(subscribers.back())->ice_oneway(); subscriberIdentities.push_back(object->ice_getIdentity()); topic->subscribeAndGetPublisher(IceStorm::QoS(), object); } { subscribers.push_back(new SingleI(communicator, "oneway")); Ice::ObjectPrx object = adapter->addWithUUID(subscribers.back())->ice_oneway(); subscriberIdentities.push_back(object->ice_getIdentity()); topic->subscribeAndGetPublisher(IceStorm::QoS(), object); } { subscribers.push_back(new SingleI(communicator, "twoway")); Ice::ObjectPrx object = adapter->addWithUUID(subscribers.back()); subscriberIdentities.push_back(object->ice_getIdentity()); topic->subscribeAndGetPublisher(IceStorm::QoS(), object); } { subscribers.push_back(new SingleI(communicator, "batch")); Ice::ObjectPrx object = adapter->addWithUUID(subscribers.back())->ice_batchOneway(); subscriberIdentities.push_back(object->ice_getIdentity()); topic->subscribeAndGetPublisher(IceStorm::QoS(), object); } { subscribers.push_back(new SingleI(communicator, "twoway ordered")); // Ordered IceStorm::QoS qos; qos["reliability"] = "ordered"; Ice::ObjectPrx object = adapter->addWithUUID(subscribers.back()); subscriberIdentities.push_back(object->ice_getIdentity()); topic->subscribeAndGetPublisher(qos, object); } { // Use a separate adapter to ensure a separate connection is used for the subscriber // (otherwise, if multiple UDP subscribers use the same connection we might get high // packet loss, see bug 1784). ObjectAdapterPtr adpt = communicator->createObjectAdapterWithEndpoints("UdpAdapter3", "udp"); subscribers.push_back(new SingleI(communicator, "datagram")); Ice::ObjectPrx object = adpt->addWithUUID(subscribers.back())->ice_datagram(); subscriberIdentities.push_back(object->ice_getIdentity()); topic->subscribeAndGetPublisher(IceStorm::QoS(), object); adpt->activate(); } { // Use a separate adapter to ensure a separate connection is used for the subscriber // (otherwise, if multiple UDP subscribers use the same connection we might get high // packet loss, see bug 1784). ObjectAdapterPtr adpt = communicator->createObjectAdapterWithEndpoints("UdpAdapter4", "udp"); subscribers.push_back(new SingleI(communicator, "batch datagram")); Ice::ObjectPrx object = adpt->addWithUUID(subscribers.back())->ice_batchDatagram(); subscriberIdentities.push_back(object->ice_getIdentity()); topic->subscribeAndGetPublisher(IceStorm::QoS(), object); adpt->activate(); } adapter->activate(); vector<Ice::Identity> ids = topic->getSubscribers(); test(ids.size() == subscriberIdentities.size()); for(vector<Ice::Identity>::const_iterator i = ids.begin(); i != ids.end(); ++i) { test(find(subscriberIdentities.begin(), subscriberIdentities.end(), *i) != subscriberIdentities.end()); } for(vector<SingleIPtr>::const_iterator p = subscribers.begin(); p != subscribers.end(); ++p) { (*p)->waitForEvents(); } return EXIT_SUCCESS; }
int run(int, char* argv[], const CommunicatorPtr& communicator) { PropertiesPtr properties = communicator->getProperties(); const char* managerProxyProperty = "IceStormAdmin.TopicManager.Default"; string managerProxy = properties->getProperty(managerProxyProperty); if(managerProxy.empty()) { cerr << argv[0] << ": property `" << managerProxyProperty << "' is not set" << endl; return EXIT_FAILURE; } ObjectPrx base = communicator->stringToProxy(managerProxy); IceStorm::TopicManagerPrx manager = IceStorm::TopicManagerPrx::checkedCast(base); if(!manager) { cerr << argv[0] << ": `" << managerProxy << "' is not running" << endl; return EXIT_FAILURE; } ObjectAdapterPtr adapter = communicator->createObjectAdapterWithEndpoints("SingleAdapter", "default"); TopicPrx topic; try { topic = manager->retrieve("single"); } catch(const IceStorm::NoSuchTopic& e) { cerr << argv[0] << ": NoSuchTopic: " << e.name << endl; return EXIT_FAILURE; } SingleIPtr sub = new SingleI(); Ice::ObjectPrx prx = adapter->addWithUUID(sub); Ice::ObjectPrx control = adapter->addWithUUID(new ControllerI); IceStorm::QoS qos; while(true) { try { topic->subscribeAndGetPublisher(qos, prx); break; } // If we're already subscribed then we're done (previously we // got an UnknownException which succeeded). catch(const IceStorm::AlreadySubscribed&) { break; } // This can happen if the replica group loses the majority // during subscription. In this case we retry. catch(const Ice::UnknownException&) { } } adapter->activate(); cout << communicator->proxyToString(control) << endl; communicator->waitForShutdown(); cout << sub->nevents() << endl; return EXIT_SUCCESS; }