Another possibility would be to register a "dummy" servant locator with your OA.
Ice will call deactivate() on this servant locator (that you implement) when the OA is deactivated.
I finally tried this. It doesn't seem to do what I want; the deactivate() doesn't seem to get called until the point where I'm actually exiting, not when I stop the server through IceGrid.
Here's some code to make it clearer; this is an excerpt from the run() method of an Ice::Application:
Code:
jast::common::DummyServantLocator *sl = new jast::common::DummyServantLocator();
TalkerI *talkerI = new TalkerI( talkerDML );
adapter->add(talkerI, id);
adapter->addServantLocator (sl, "");
adapter->activate();
while (!(sl->isDone())) {
try {
adapter->getCommunicator();
} catch (const Ice::ObjectAdapterDeactivatedException&) {
cerr << "Deactivated!!" << endl;
break;
}
// Call the external event loop
talkerDML->vRun(Poll_e, 100);
}
cerr << "Talker server exiting!" << endl;
return EXIT_SUCCESS;
Here's a bit of DummyServantLocator:
Code:
void jast::common::DummyServantLocator::deactivate (const std::string& category) {
std::cerr << "Dummy servant locator deactivated!" << std::endl;
deactivated = true;
}
bool jast::common::DummyServantLocator::isDone() {
return deactivated;
}
If I don't put in the try-catch, the loop never breaks at all when I stop the server through IceGrid. If I do put it in, the sequence of outputs printed when I stop through IceGrid is:
Deactivated!!
Talker server exiting!
Dummy servant locator deactivated!
Of course, there may be threading issues or something going on, but it looks to me like this means ServantLocator.deactivate() doesn't get called until after I return from run(). Would it help if I stopped using Ice::Application?
Thanks for your help,
MEF