Creating multiple successive router sessions with the same router and communicator
The Ice MFC demo used to create multiple sessions (successively) with the same router and communicator. This happened to work fine because for each session it creates an object adapter with the router. When the session is destroyed, the object adapter is deactivated and this cause the router info to be removed from the router manager (see also comment 20 on ICE-433).
However, if a Glacier2 client doesn't use an object adapter with the router or still make invocations after the OA is deactivated, the router info for the router won't be removed from the router manager.
This will cause problems with clients that create multiple sessions with the same router and communicator: sessions will be using the same router info which is not correct because the router info holds a cache which is really session specific.
See also http://www.zeroc.com/vbulletin/showthread.php?p=10344#post10344
To fix this bug, perhaps we could add an explicit call to clear the router info from the router manager
associated with the communicator, for example: communicator->clearRouterInfo(router); However, I'm afraid it wouldn't be really obvious to the user what this is doing! He'd have to call this after the session is destroyed to make sure the session specific stuff from the RouterInfo is cleared (i.e.: the table of identities, the client and server proxies). This could also be error prone... if he makes further "routed" invocations after calling this, the router info would be re-added automatically...
Another solution would perhaps be to add the following methods to the communicator:
void Communicator::startRouterSession(const Ice::RouterPrx& router): this should be called when the client application starts using the router, i.e.: when it wants to make "routed" invocations on proxies with the given router set. If this isn't call, invocations on proxies with the router set would fail with NoEndpointException. Under the hood, we would create a RouterInfo object for the router and add it to the router manager, router info objects wouldn't be created automatically anymore.void Communicator::finishRouterSession(const RouterPrx& router): this should be called when the client application stops using the router, i.e.: when it doesn't want to make "routed" invocations on proxies with the router set. Under the hood, the router info object would be removed from the router manager. Since there's no more router info, invocations on proxies with the router set would fail with NoEndpointException.
Calling Communicator::createObjectAdapterWithRouter() would only be possible if the router has an active "session" (i.e.: if the user called startRouterSession on the communicator for the router...). The object adapter could automatically be deactivated when finishRouterSession is called on the communicator (the OA is really session specific, it can't be re-used for multiple sessions – at least not unless we really want to fix ICE-901).
For Glacier2 sessions, the user would call startRouterSession once the Glacier2 session is created with the router and he would call finishRouterSession once it's destroyed...
See ICE-1020 for full discussion