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; }
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(); }
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&) { } } }
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 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; }