int main(int argc, char* argv[]) { int status; CommunicatorPtr communicator; try { communicator = initialize(argc, argv); status = run(argc, argv, communicator); } catch(const Exception& ex) { cerr << ex << endl; status = EXIT_FAILURE; } if(communicator) { try { communicator->destroy(); } catch(const Exception& ex) { cerr << ex << endl; status = EXIT_FAILURE; } } return status; }
void ServiceI::start(const string& name, const CommunicatorPtr& communicator, const StringSeq& args) { Ice::ObjectAdapterPtr adapter = communicator->createObjectAdapter(name + "OA"); adapter->add(new TestI(args), communicator->stringToIdentity("test")); adapter->activate(); }
void TestI::transient(const Current& current) { CommunicatorPtr communicator = current.adapter->getCommunicator(); ObjectAdapterPtr adapter = communicator->createObjectAdapterWithEndpoints("TransientTestAdapter", getTestEndpoint(communicator, 1)); adapter->activate(); adapter->destroy(); }
void ServiceI::start(const string& name, const CommunicatorPtr& communicator, const StringSeq&) { Ice::PropertiesPtr properties = communicator->getProperties(); Ice::ObjectAdapterPtr adapter = communicator->createObjectAdapter(name); Ice::ObjectPtr object = new TestI(adapter, properties); adapter->add(object, stringToIdentity(properties->getProperty(name + ".Identity"))); adapter->activate(); }
Ice::CommunicatorPtr Ice::CommunicatorHolder::release() { #ifdef ICE_CPP11_MAPPING return std::move(_communicator); #else CommunicatorPtr result; result.swap(_communicator); return result; #endif }
CommunicatorPtr Ice::initialize(int& argc, char* argv[], const InitializationData& initializationData, Int version) { checkIceVersion(version); InitializationData initData = initializationData; initData.properties = createProperties(argc, argv, initData.properties); CommunicatorPtr communicator = new Communicator(initData); communicator->finishSetup(argc, argv); return communicator; }
int main(int argc, char *argv[]) { try { if (argc < 5) { cout << "Usage:" << argv[0] << " <config file> <count> <sync:0|async:1> <fork num>" << endl; //exit(0); } TC_Config conf; //conf.parseFile(argv[1]); //_comm->setProperty(conf); _comm->setProperty("sync-invoke-timeout", "600000"); _comm->setProperty("async-invoke-timeout", "600000"); queryDataPrx pPrx = _comm->stringToProxy<queryDataPrx>(obj); int c = 1; timeval tv1, tv2; gettimeofday(&tv1, NULL); int t = 0; if (t == 0) { syncCall(pPrx, c); } else if (t == 1) { asyncCall(pPrx, c); } pid_t pid = getpid(); gettimeofday(&tv2, NULL); cout << "(pid:" << pid << ")" << "(" << (t == 0 ? "sync" : "async") << ")" << "(count:" << c << ")" << "(use ms:" << (tv2.tv_sec - tv1.tv_sec)*1000 + (tv2.tv_usec - tv1.tv_usec)/1000 << ")" << endl; ///sleep(3); } catch(exception &ex) { cout << ex.what() << endl; } cout << "main return." << endl; return 0; }
void MstcOnline::initialize(PointPtr starting_point, double tool_size, CommunicatorPtr communicator) { communicator->set_tool_size(tool_size); this->tool_size = tool_size; this->communicator = communicator; // Initialize starting_cell starting_cell = IdentifiableCellPtr( new IdentifiableCell(PointPtr(new Point(starting_point->x - tool_size / 2, starting_point->y + tool_size / 2)), 2 * tool_size, communicator->get_robot_name())); starting_cell->set_parent(IdentifiableCellPtr(new IdentifiableCell( PointPtr(new Point(starting_cell->get_center()->x, starting_cell->get_center()->y - 2 * tool_size)), 2 * tool_size, communicator->get_robot_name()))); path.insert(path.end(), starting_point); }
int main(int argc, char* argv[]) { if (argc < 3) { cerr << "tmcli <endpoint> <command> ..." << endl; return -1; } try { Ice::PropertiesPtr properties = Ice::createProperties(); properties->load("../etc/admin.cfg"); InitializationData initializationData; initializationData.properties = properties; CommunicatorPtr communicator = initialize(initializationData); ObjectPrx object = communicator->stringToProxy("TMA@"+string(argv[1])); TaskManagerAPIPrx manager = TaskManagerAPIPrx::uncheckedCast(object); if (string(argv[2]) == "clear") { if (argc != 4) { help(); return -1; } int level = boost::lexical_cast<int>(argv[3]); manager->clear(level); } else if (string(argv[2]) == "size") { if (argc != 4) { help(); return -1; } int level = boost::lexical_cast<int>(argv[3]); cout << manager->size(level) << endl; } else if (string(argv[2]) == "config") { if (argc != 7) { help(); return -1; } int level = boost::lexical_cast<int>(argv[3]); int min = boost::lexical_cast<int>(argv[4]); int max = boost::lexical_cast<int>(argv[5]); int stack = boost::lexical_cast<int>(argv[6]); manager->config(level, min, max, stack); } else { help(); } } catch (const Ice::Exception& e) { cerr << e.what() << endl; return -1; } catch (...) { cerr << "unknown exception" << endl; return -1; } return 0; }
/** * The start function called by IceBox to start this service. This * handles all the icebox interactions. We obtain the * service name from the config.icebox file as follows. Given this * entry: * IceBox.Service.BOW_Detector=bowICEServer:create --Ice.Config=config.service * ... the name of the service is BOW_Detector. */ void ServiceManagerI::start(const ::std::string& name, const CommunicatorPtr& communicator, const StringSeq&) { mServiceName = name; localAndClientMsg(VLogger::DEBUG, NULL, "starting service: %s\n", mServiceName.c_str()); mAdapter = communicator->createObjectAdapter(mServiceName); clearStop(); assert( mService ); mAdapter->add(mService, communicator->stringToIdentity(mServiceName)); mAdapter->activate(); createSandbox(); if (NULL!=mSS) mSS->starting(); localAndClientMsg(VLogger::INFO, NULL, "service started: %s\n", mServiceName.c_str()); }
// look for ServiceNamex.TrainedModel // Note that the x is significant string ServiceManagerI::getModelFileFromConfig() { CommunicatorPtr comm = mAdapter->getCommunicator(); if ( comm ) { PropertiesPtr props = comm->getProperties(); if (props==true) { string propname = mServiceName + "x.TrainedModel"; string propval = props->getProperty( propname ); return propval; } } return ""; }
CommunicatorPtr Ice::initialize(const InitializationData& initData, Int version) { // // We can't simply call the other initialize() because this one does NOT read // the config file, while the other one always does. // checkIceVersion(version); CommunicatorPtr communicator = new Communicator(initData); int argc = 0; char* argv[] = { 0 }; communicator->finishSetup(argc, argv); return communicator; }
Test::RemoteEvictorI::RemoteEvictorI(const CommunicatorPtr& communicator, const string& envName, const string& category, bool transactional) : _envName(envName), _category(category) { _evictorAdapter = communicator->createObjectAdapterWithEndpoints(Ice::generateUUID(), "default"); Initializer* initializer = new Initializer; if(transactional) { _evictor = Freeze::createTransactionalEvictor(_evictorAdapter, envName, category, Freeze::FacetTypeMap(), initializer); } else { _evictor = Freeze::createBackgroundSaveEvictor(_evictorAdapter, envName, category, initializer); } // // Check that we can get an iterator on a non-existing facet // Freeze::EvictorIteratorPtr p = _evictor->getIterator("foo", 1); test(p->hasNext() == false); initializer->init(this, _evictor); _evictorAdapter->addServantLocator(_evictor, category); _evictorAdapter->activate(); }
void ServiceI::start(const CommunicatorPtr& communicator, const ObjectAdapterPtr& topicAdapter, const ObjectAdapterPtr& publishAdapter, const string& name, const Ice::Identity& id, const string& /*dbEnv*/) { // // For IceGrid we don't validate the properties as all sorts of // non-IceStorm properties are included in the prefix. // //validateProperties(name, communicator->getProperties(), communicator->getLogger()); // This is for IceGrid only and as such we use a transient // implementation of IceStorm. string instanceName = communicator->getProperties()->getPropertyWithDefault(name + ".InstanceName", "IceStorm"); _instance = new Instance(instanceName, name, communicator, publishAdapter, topicAdapter, 0); try { TransientTopicManagerImplPtr manager = new TransientTopicManagerImpl(_instance); _managerProxy = TopicManagerPrx::uncheckedCast(topicAdapter->add(manager, id)); } catch(const Ice::Exception& ex) { _instance = 0; LoggerOutputBase s; s << "exception while starting IceStorm service " << name << ":\n"; s << ex; throw IceBox::FailureException(__FILE__, __LINE__, s.str()); } }
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 ServiceI::start(const string& name, const CommunicatorPtr& communicator, const StringSeq& args) { Ice::PropertiesPtr properties = communicator->getProperties(); Ice::ObjectAdapterPtr adapter = communicator->createObjectAdapter(name); if(properties->getPropertyAsInt(name + ".Freeze") > 0) { // // We do this to ensure the dbenv directory exists. // Freeze::createConnection(communicator, name); } Ice::ObjectPtr object = new TestI(adapter, properties); adapter->add(object, communicator->stringToIdentity(properties->getProperty(name + ".Identity"))); adapter->activate(); }
ServiceI::ServiceI(const CommunicatorPtr& serviceManagerCommunicator) { TestFacetIPtr facet = new TestFacetI; // // Install a custom admin facet. // serviceManagerCommunicator->addAdminFacet(facet, "TestFacet"); // // The TestFacetI servant also implements PropertiesAdminUpdateCallback. // Set the callback on the admin facet. // ObjectPtr propFacet = serviceManagerCommunicator->findAdminFacet("IceBox.Service.TestService.Properties"); NativePropertiesAdminPtr admin = NativePropertiesAdminPtr::dynamicCast(propFacet); assert(admin); admin->addUpdateCallback(facet); }
BOOST_AUTO_TEST_CASE_TEMPLATE( testSolveWithoutPreconditioning, T, test_types ) { typedef T ValueType; CommunicatorPtr comm = CommunicatorFactory::get(); // default one testSolveWithoutPreconditionmethod< CSRSparseMatrix<ValueType> >(); testSolveWithoutPreconditionmethod< ELLSparseMatrix<ValueType> >(); testSolveWithoutPreconditionmethod< JDSSparseMatrix<ValueType> >(); testSolveWithoutPreconditionmethod< COOSparseMatrix<ValueType> >(); // ToDo: these tests do not run with multiple processors if ( comm->getSize() <= 1 ) { testSolveWithoutPreconditionmethod< DIASparseMatrix<ValueType> >(); testSolveWithoutPreconditionmethod< DenseMatrix<ValueType> >(); } }
GeneralDistributionTestConfig() { comm = CommunicatorFactory::get( "MPI" ); rank = comm->getRank(); size = comm->getSize(); elemsPerPartition = 10; globalSize = elemsPerPartition * size; for ( IndexType k = 0; k < elemsPerPartition; ++k ) { localIndexes.push_back( k * size + rank ); } dist = DistributionPtr( new GeneralDistribution( globalSize, localIndexes, comm ) ); }
virtual void run() { CommunicatorPtr communicator = initialize(initData); ObjectPrx routerBase = communicator->stringToProxy( "Glacier2/router:" + TestHelper::getTestEndpoint(communicator->getProperties(), 50)); _router = Glacier2::RouterPrx::checkedCast(routerBase); communicator->setDefaultRouter(_router); ostringstream os; os << "userid-" << _id; Glacier2::SessionPrx session = _router->createSession(os.str(), "abc123"); communicator->getProperties()->setProperty("Ice.PrintAdapterReady", ""); ObjectAdapterPtr adapter = communicator->createObjectAdapterWithRouter("CallbackReceiverAdapter", _router); adapter->activate(); string category = _router->getCategoryForClient(); _callbackReceiver = new CallbackReceiverI; Identity ident; ident.name = "callbackReceiver"; ident.category = category; CallbackReceiverPrx receiver = CallbackReceiverPrx::uncheckedCast(adapter->add(_callbackReceiver, ident)); ObjectPrx base = communicator->stringToProxy( "c1/callback:" + TestHelper::getTestEndpoint(communicator->getProperties())); base = base->ice_oneway(); CallbackPrx callback = CallbackPrx::uncheckedCast(base); { Lock sync(*this); _initialized = true; notifyAll(); } { Lock sync(*this); while(!_notified) { wait(); } } // // Stress the router until the connection is closed. // stress(callback, receiver); communicator->destroy(); }
IcePatch2::Patcher::Patcher(const CommunicatorPtr& communicator, const PatcherFeedbackPtr& feedback) : _feedback(feedback), _dataDir(getDataDir(communicator, ".")), _thorough(getThorough(communicator, 0) > 0), _chunkSize(getChunkSize(communicator, 100)), _remove(getRemove(communicator, 1)), _log(0) { const PropertiesPtr properties = communicator->getProperties(); const char* clientProxyProperty = "IcePatch2Client.Proxy"; std::string clientProxy = properties->getProperty(clientProxyProperty); if(clientProxy.empty()) { const char* endpointsProperty = "IcePatch2.Endpoints"; string endpoints = properties->getProperty(endpointsProperty); if(endpoints.empty()) { ostringstream os; os << "No proxy to IcePatch2 server. Please set `" << clientProxyProperty << "' or `" << endpointsProperty << "'."; throw os.str(); } ostringstream os; os << "The property " << endpointsProperty << " is deprecated, use " << clientProxyProperty << " instead."; communicator->getLogger()->warning(os.str()); Identity id; id.category = properties->getPropertyWithDefault("IcePatch2.InstanceName", "IcePatch2"); id.name = "server"; clientProxy = "\"" + communicator->identityToString(id) + "\" :" + endpoints; } ObjectPrx serverBase = communicator->stringToProxy(clientProxy); FileServerPrx server = FileServerPrx::checkedCast(serverBase); if(!server) { throw "proxy `" + clientProxy + "' is not a file server."; } init(server); }
static Distribution* createDistribution( const IndexType n, CommunicatorPtr comm, int kind ) { Distribution* dist; if ( kind == 0 ) { dist = new BlockDistribution( n, comm ); } else if ( kind == 1 ) { dist = new NoDistribution( n ); } else if ( kind == 2 ) { std::vector<IndexType> localIndexes; IndexType size = comm->getSize(); IndexType rank = comm->getRank(); for ( int k = 0; k < n; k++ ) { if ( k % size == rank ) { localIndexes.push_back(k); } } dist = new GeneralDistribution( n, localIndexes, comm); } else if ( kind == 3 ) { IndexType chunkSize = comm->getSize(); dist = new CyclicDistribution( n, chunkSize, comm); } else { LAMA_THROWEXCEPTION( "kind = " << kind << " unsupported here" ) } return dist; }
int run(int argc, char* argv[], const CommunicatorPtr& communicator) { if(argc < 2) { cerr << "Usage: " << argv[0] << " proxy" << endl; return EXIT_FAILURE; } ControllerPrx control = ControllerPrx::uncheckedCast(communicator->stringToProxy(argv[1])); control->stop(); return EXIT_SUCCESS; }
BOOST_AUTO_TEST_CASE_TEMPLATE( buildTest, T, test_types ) { typedef T ValueType; PartitionId size = comm->getSize(); int numRows = 3 * size; int numCols = 5 * size; scoped_array<ValueType> values( new ValueType[ numRows * numCols ] ); for ( IndexType i = 0; i < numRows; ++i) { for ( IndexType j = 0; j < numCols; ++j ) { ValueType value = static_cast<ValueType> ( i * numCols + j + 1.0 ); values[ i * numCols + j ] = value; } } DenseMatrix<ValueType> repM; repM.setRawDenseData( numRows, numCols, values.get() ); for ( IndexType i = 0; i < numRows; ++i ) { for ( IndexType j = 0; j<numCols; ++j ) { Scalar value = repM.getValue( i , j ); Scalar expectedvalue = Scalar( static_cast<ValueType>(values[i * numCols + j]) ); LAMA_CHECK_SCALAR_SMALL( value - expectedvalue, ValueType, eps<ValueType>() ); } } shared_ptr<Distribution> dist( new BlockDistribution(numRows, comm) ); shared_ptr<Distribution> distCol( new BlockDistribution(numCols, comm) ); DenseMatrix<ValueType> distM( repM, dist, distCol ); for (IndexType i = 0; i<numRows; ++i) { for (IndexType j = 0; j<numCols; ++j) { Scalar value = distM.getValue( i, j ); Scalar expectedvalue = repM.getValue( i, j ); LAMA_CHECK_SCALAR_SMALL( value - expectedvalue , ValueType, eps<ValueType>() ); } } }
void Client::interrupted() { Lock sync(*this); if(_parser) // If there's an interactive parser, notify the parser. { _parser->interrupt(); } else { // // Otherwise, destroy the communicator. // assert(_communicator); try { _communicator->destroy(); } catch(const Exception&) { } } }
bool IceBox::ServiceManagerI::start() { try { ServiceManagerPtr obj = this; PropertiesPtr properties = _communicator->getProperties(); // // Create an object adapter. Services probably should NOT share // this object adapter, as the endpoint(s) for this object adapter // will most likely need to be firewalled for security reasons. // ObjectAdapterPtr adapter; if(properties->getProperty("IceBox.ServiceManager.Endpoints") != "") { adapter = _communicator->createObjectAdapter("IceBox.ServiceManager"); Identity identity; identity.category = properties->getPropertyWithDefault("IceBox.InstanceName", "IceBox"); identity.name = "ServiceManager"; adapter->add(obj, identity); } // // Parse the property set with the prefix "IceBox.Service.". These // properties should have the following format: // // IceBox.Service.Foo=entry_point [args] // // We parse the service properties specified in IceBox.LoadOrder // first, then the ones from remaining services. // const string prefix = "IceBox.Service."; PropertyDict services = properties->getPropertiesForPrefix(prefix); PropertyDict::iterator p; StringSeq loadOrder = properties->getPropertyAsList("IceBox.LoadOrder"); vector<StartServiceInfo> servicesInfo; for(StringSeq::const_iterator q = loadOrder.begin(); q != loadOrder.end(); ++q) { p = services.find(prefix + *q); if(p == services.end()) { FailureException ex(__FILE__, __LINE__); ex.reason = "ServiceManager: no service definition for `" + *q + "'"; throw ex; } servicesInfo.push_back(StartServiceInfo(*q, p->second, _argv)); services.erase(p); } for(p = services.begin(); p != services.end(); ++p) { servicesInfo.push_back(StartServiceInfo(p->first.substr(prefix.size()), p->second, _argv)); } // // Check if some services are using the shared communicator in which // case we create the shared communicator now with a property set which // is the union of all the service properties (services which are using // the shared communicator). // PropertyDict sharedCommunicatorServices = properties->getPropertiesForPrefix("IceBox.UseSharedCommunicator."); if(!sharedCommunicatorServices.empty()) { InitializationData initData; initData.properties = createServiceProperties("SharedCommunicator"); for(vector<StartServiceInfo>::iterator q = servicesInfo.begin(); q != servicesInfo.end(); ++q) { if(properties->getPropertyAsInt("IceBox.UseSharedCommunicator." + q->name) <= 0) { continue; } // // Load the service properties using the shared communicator properties as // the default properties. // PropertiesPtr svcProperties = createProperties(q->args, initData.properties); // // Erase properties from the shared communicator which don't exist in the // service properties (which include the shared communicator properties // overriden by the service properties). // PropertyDict allProps = initData.properties->getPropertiesForPrefix(""); for(PropertyDict::iterator p = allProps.begin(); p != allProps.end(); ++p) { if(svcProperties->getProperty(p->first) == "") { initData.properties->setProperty(p->first, ""); } } // // Add the service properties to the shared communicator properties. // PropertyDict props = svcProperties->getPropertiesForPrefix(""); for(PropertyDict::const_iterator r = props.begin(); r != props.end(); ++r) { initData.properties->setProperty(r->first, r->second); } // // Parse <service>.* command line options (the Ice command line options // were parsed by the createProperties above) // q->args = initData.properties->parseCommandLineOptions(q->name, q->args); } _sharedCommunicator = initialize(initData); } // // Start the services. // for(vector<StartServiceInfo>::const_iterator r = servicesInfo.begin(); r != servicesInfo.end(); ++r) { start(r->name, r->entryPoint, r->args); } // // We may want to notify external scripts that the services // have started. This is done by defining the property: // // IceBox.PrintServicesReady=bundleName // // Where bundleName is whatever you choose to call this set of // services. It will be echoed back as "bundleName ready". // // This must be done after start() has been invoked on the // services. // string bundleName = properties->getProperty("IceBox.PrintServicesReady"); if(!bundleName.empty()) { cout << bundleName << " ready" << endl; } // // Register "this" as a facet to the Admin object, and then create // Admin object // try { _communicator->addAdminFacet(this, "IceBox.ServiceManager"); // // Add a Properties facet for each service // for(vector<ServiceInfo>::iterator r = _services.begin(); r != _services.end(); ++r) { const ServiceInfo& info = *r; CommunicatorPtr communicator = info.communicator != 0 ? info.communicator : _sharedCommunicator; _communicator->addAdminFacet(new PropertiesAdminI(communicator->getProperties()), "IceBox.Service." + info.name + ".Properties"); } _communicator->getAdmin(); } catch(const ObjectAdapterDeactivatedException&) { // // Expected if the communicator has been shutdown. // } if(adapter) { try { adapter->activate(); } catch(const ObjectAdapterDeactivatedException&) { // // Expected if the communicator has been shutdown. // } } } catch(const FailureException& ex) { Error out(_logger); out << ex.reason; stopAll(); return false; } catch(const Exception& ex) { Error out(_logger); out << "ServiceManager: " << ex; stopAll(); return false; } return true; }
virtual void run() { CommunicatorPtr communicator = initialize(initData); ObjectPrx routerBase = communicator->stringToProxy("Glacier2/router:default -p 12347 -t 10000"); Glacier2::RouterPrx router = Glacier2::RouterPrx::checkedCast(routerBase); communicator->setDefaultRouter(router); ostringstream os; os << "userid-" << _id; Glacier2::SessionPrx session = router->createSession(os.str(), "abc123"); communicator->getProperties()->setProperty("Ice.PrintAdapterReady", ""); ObjectAdapterPtr adapter = communicator->createObjectAdapterWithRouter("CallbackReceiverAdapter", router); adapter->activate(); string category = router->getCategoryForClient(); { Lock sync(*this); _callbackReceiver = new CallbackReceiverI; notify(); } Identity ident; ident.name = "callbackReceiver"; ident.category = category; CallbackReceiverPrx receiver = CallbackReceiverPrx::uncheckedCast(adapter->add(_callbackReceiver, ident)); ObjectPrx base = communicator->stringToProxy("c1/callback:tcp -p 12010 -t 10000"); base = base->ice_oneway(); CallbackPrx callback = CallbackPrx::uncheckedCast(base); // // Block the CallbackReceiver in wait() to prevent the client from // processing other incoming calls and wait to receive the callback. // callback->initiateWaitCallback(receiver); test(_callbackReceiver->waitCallbackOK()); // // Notify the main thread that the callback was received. // { Lock sync(*this); _callback = true; notify(); } // // Callback the client with a large payload. This should cause // the Glacier2 request queue thread to block trying to send the // callback to the client because the client is currently blocked // in CallbackReceiverI::waitCallback() and can't process more // requests. // callback->initiateCallbackWithPayload(receiver); test(_callbackReceiver->callbackWithPayloadOK()); try { router->destroySession(); test(false); } catch(const Ice::ConnectionLostException&) { } catch(const Ice::LocalException&) { test(false); } communicator->destroy(); }
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; } TopicPrx fed1; try { fed1 = manager->retrieve("fed1"); } catch(const NoSuchTopic& e) { cerr << argv[0] << ": NoSuchTopic: " << e.name << endl; return EXIT_FAILURE; } TopicPrx fed2; try { fed2 = manager->retrieve("fed2"); } catch(const NoSuchTopic& e) { cerr << argv[0] << ": NoSuchTopic: " << e.name << endl; return EXIT_FAILURE; } TopicPrx fed3; try { fed3 = manager->retrieve("fed3"); } catch(const NoSuchTopic& e) { cerr << argv[0] << ": NoSuchTopic: " << e.name << endl; return EXIT_FAILURE; } EventPrx eventFed1 = EventPrx::uncheckedCast(fed1->getPublisher()->ice_oneway()); EventPrx eventFed2 = EventPrx::uncheckedCast(fed2->getPublisher()->ice_oneway()); EventPrx eventFed3 = EventPrx::uncheckedCast(fed3->getPublisher()->ice_oneway()); Ice::Context context; int i; context["cost"] = "0"; for(i = 0; i < 10; ++i) { eventFed1->pub("fed1:0", context); } context["cost"] = "10"; for(i = 0; i < 10; ++i) { eventFed1->pub("fed1:10", context); } context["cost"] = "15"; for(i = 0; i < 10; ++i) { eventFed1->pub("fed1:15", context); } context["cost"] = "0"; for(i = 0; i < 10; ++i) { eventFed2->pub("fed2:0", context); } context["cost"] = "5"; for(i = 0; i < 10; ++i) { eventFed2->pub("fed2:5", context); } context["cost"] = "0"; for(i = 0; i < 10; ++i) { eventFed3->pub("fed3:0", context); } // // Before we exit, we ping all proxies as twoway, to make sure // that all oneways are delivered. // EventPrx::uncheckedCast(eventFed1->ice_twoway())->ice_ping(); EventPrx::uncheckedCast(eventFed2->ice_twoway())->ice_ping(); EventPrx::uncheckedCast(eventFed3->ice_twoway())->ice_ping(); return EXIT_SUCCESS; }
int Client::main(StringSeq& args) { int status = EXIT_SUCCESS; try { _appName = args[0]; InitializationData id; id.properties = createProperties(args); id.properties->setProperty("Ice.Warn.Endpoints", "0"); _communicator = initialize(id); { IceUtilInternal::MutexPtrLock<IceUtil::Mutex> sync(_staticMutex); _globalClient = this; } _ctrlCHandler.setCallback(interruptCallback); try { status = run(args); } catch(const CommunicatorDestroyedException&) { // Expected if the client is interrupted during the initialization. } } catch(const IceUtil::Exception& ex) { cerr << _appName << ": " << ex << endl; status = EXIT_FAILURE; } catch(const std::exception& ex) { cerr << _appName << ": std::exception: " << ex.what() << endl; status = EXIT_FAILURE; } catch(const std::string& msg) { cerr << _appName << ": " << msg << endl; status = EXIT_FAILURE; } catch(const char* msg) { cerr << _appName << ": " << msg << endl; status = EXIT_FAILURE; } catch(...) { cerr << _appName << ": unknown exception" << endl; status = EXIT_FAILURE; } if(_communicator) { try { _communicator->destroy(); } catch(const CommunicatorDestroyedException&) { } catch(const Exception& ex) { cerr << ex << endl; status = EXIT_FAILURE; } } _ctrlCHandler.setCallback(0); { IceUtilInternal::MutexPtrLock<IceUtil::Mutex> sync(_staticMutex); _globalClient = 0; } return status; }
int run(int argc, char* argv[], const CommunicatorPtr& communicator) { IceUtilInternal::Options opts; opts.addOpt("", "count", 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; } TopicPrx fed1; try { fed1 = manager->retrieve("fed1"); } catch(const NoSuchTopic& e) { cerr << argv[0] << ": NoSuchTopic: " << e.name << endl; return EXIT_FAILURE; } EventPrx eventFed1 = EventPrx::uncheckedCast(fed1->getPublisher()->ice_oneway()); string arg = opts.optArg("count"); int count = 1; if(arg.empty()) { count = atoi(arg.c_str()); } while(true) { for(int i = 0; i < 10; ++i) { eventFed1->pub("fed1"); } // // Before we exit, we ping all proxies as twoway, to make sure // that all oneways are delivered. // EventPrx::uncheckedCast(eventFed1->ice_twoway())->ice_ping(); if(count == 0) { break; } --count; IceUtil::ThreadControl::sleep(IceUtil::Time::seconds(1)); } return EXIT_SUCCESS; }