int run(int, char**, const Ice::CommunicatorPtr& communicator) { IceUtil::TimerPtr timer = new IceUtil::Timer(); communicator->getProperties()->setProperty("TestAdapter1.Endpoints", getTestEndpoint(communicator, 0) + ":udp"); communicator->getProperties()->setProperty("TestAdapter1.ThreadPool.Size", "5"); communicator->getProperties()->setProperty("TestAdapter1.ThreadPool.SizeMax", "5"); communicator->getProperties()->setProperty("TestAdapter1.ThreadPool.SizeWarn", "0"); communicator->getProperties()->setProperty("TestAdapter1.ThreadPool.Serialize", "0"); Ice::ObjectAdapterPtr adapter1 = communicator->createObjectAdapter("TestAdapter1"); adapter1->add(ICE_MAKE_SHARED(HoldI, timer, adapter1), communicator->stringToIdentity("hold")); communicator->getProperties()->setProperty("TestAdapter2.Endpoints", getTestEndpoint(communicator, 1) + ":udp"); communicator->getProperties()->setProperty("TestAdapter2.ThreadPool.Size", "5"); communicator->getProperties()->setProperty("TestAdapter2.ThreadPool.SizeMax", "5"); communicator->getProperties()->setProperty("TestAdapter2.ThreadPool.SizeWarn", "0"); communicator->getProperties()->setProperty("TestAdapter2.ThreadPool.Serialize", "1"); Ice::ObjectAdapterPtr adapter2 = communicator->createObjectAdapter("TestAdapter2"); adapter2->add(ICE_MAKE_SHARED(HoldI, timer, adapter2), communicator->stringToIdentity("hold")); adapter1->activate(); adapter2->activate(); TEST_READY communicator->waitForShutdown(); timer->destroy(); return EXIT_SUCCESS; }
bool ChatServer::start(int, char*[], int& status) { _timer = new IceUtil::Timer(); // Timeout for reaping polling sessions. int timeout = communicator()->getProperties()->getPropertyAsIntWithDefault("ReaperTimeout", 10); bool traceEnabled = communicator()->getProperties()->getPropertyAsIntWithDefault("Server.Trace", 0) != 0; Ice::LoggerPtr logger = communicator()->getLogger(); ReaperTaskPtr reaper = new ReaperTask(timeout, traceEnabled, logger); _timer->scheduleRepeated(reaper, IceUtil::Time::seconds(timeout)); try { _adapter = communicator()->createObjectAdapter("ChatServer"); ChatRoomPtr chatRoom = new ChatRoom(traceEnabled, logger); if(traceEnabled) { ostringstream os; os << "Chat room created ok."; logger->trace("info", os.str()); } _adapter->add(new ChatSessionManagerI(chatRoom, traceEnabled, logger), communicator()->stringToIdentity("ChatSessionManager")); if(traceEnabled) { ostringstream os; os << "Chat session manager created ok."; logger->trace("info", os.str()); } _adapter->add(new PollingChatSessionFactoryI(chatRoom, reaper, traceEnabled, logger), communicator()->stringToIdentity("PollingChatSessionFactory")); if(traceEnabled) { ostringstream os; os << "Polling chat session factory created ok."; logger->trace("info", os.str()); } _adapter->activate(); if(traceEnabled) { ostringstream os; os << "Chat server started ok."; logger->trace("info", os.str()); } } catch(const Ice::LocalException&) { status = EXIT_FAILURE; _timer->destroy(); throw; } status = EXIT_SUCCESS; return true; }
int SessionServer::run(int argc, char*[]) { if(argc > 1) { cerr << appName() << ": too many arguments" << endl; return EXIT_FAILURE; } Ice::ObjectAdapterPtr adapter = communicator()->createObjectAdapter("SessionFactory"); IceUtil::TimerPtr timer = new IceUtil::Timer(); ReapTaskPtr reapTask = new ReapTask; timer->scheduleRepeated(reapTask, IceUtil::Time::seconds(1)); SessionFactoryPtr factory = new SessionFactoryI(reapTask); adapter->add(factory, Ice::stringToIdentity("SessionFactory")); adapter->activate(); communicator()->waitForShutdown(); timer->destroy(); return EXIT_SUCCESS; }
void SessionClient::cleanup(bool destroy) { IceUtil::Mutex::Lock sync(_mutex); // // The refresher thread must be terminated before destroy is // called, otherwise it might get ObjectNotExistException. refresh // is set to 0 so that if session->destroy() raises an exception // the thread will not be re-terminated and re-joined. // if(_timer) { _timer->destroy(); _timer = 0; } if(destroy && _session) { _session->destroy(); } _session = 0; }
bool ChatServer::stop() { _timer->destroy(); return true; }
int SessionClient::run(int argc, char* argv[]) { if(argc > 1) { cerr << appName() << ": too many arguments" << endl; return EXIT_FAILURE; } string name; cout << "Please enter your name ==> "; cin >> name; if(!cin.good()) { return EXIT_FAILURE; } Ice::ObjectPrx base = communicator()->propertyToProxy("SessionFactory.Proxy"); SessionFactoryPrx factory = SessionFactoryPrx::checkedCast(base); if(!factory) { cerr << argv[0] << ": invalid proxy" << endl; return EXIT_FAILURE; } { IceUtil::Mutex::Lock sync(_mutex); _session = factory->create(name); _timer = new IceUtil::Timer(); _timer->scheduleRepeated(new RefreshTask(communicator()->getLogger(), _session), IceUtil::Time::seconds(5)); } vector<HelloPrx> hellos; menu(); try { bool destroy = true; bool shutdown = false; while(true) { cout << "==> "; char c; cin >> c; if(!cin.good()) { break; } if(isdigit(c)) { string s; s += c; vector<HelloPrx>::size_type index = atoi(s.c_str()); if(index < hellos.size()) { hellos[index]->sayHello(); } else { cout << "Index is too high. " << hellos.size() << " hello objects exist so far.\n" << "Use `c' to create a new hello object." << endl; } } else if(c == 'c') { hellos.push_back(_session->createHello()); cout << "Created hello object " << hellos.size() - 1 << endl; } else if(c == 's') { destroy = false; shutdown = true; break; } else if(c == 'x') { break; } else if(c == 't') { destroy = false; break; } else if(c == '?') { menu(); } else { cout << "Unknown command `" << c << "'." << endl; menu(); } } cleanup(destroy); if(shutdown) { factory->shutdown(); } } catch(...) { try { cleanup(true); } catch(...) { } throw; } return EXIT_SUCCESS; }