This forum has been archived. Please start a new discussion on GitHub.

Session creation/destruction

Should I be able to create a session, destroy it, and then create another session later on using the same router and communicator? I'm using Glacier2 in between my client and my server. I'm using Ice 3.0.1 for Java. Here's what I'm doing:

1) The client (which is a subclass of Ice.Application) creates the Glacier2 router in the run() method. Here's a snippet of the code:
private RouterPrx router;

public SessionPrx createSession(final String userId, final String password) throws CannotCreateSessionException, PermissionDeniedException
   return router.createSession(userId, password);

public void destroySession() throws SessionNotExistException

public int run(final String[] args)
   final Ice.RouterPrx defaultRouter = communicator().getDefaultRouter();
   if (defaultRouter == null)
      LOG.error("no default router set");
      return 1;

   router = RouterPrxHelper.checkedCast(defaultRouter);
   if (router == null)
      LOG.error("configured router is not a Glacier2 router");
      return 1;

   // spawn a GUI...

2) The GUI spawned by the run method allows the user to enter their username and password. When they click "Login", the GUI calls the createSession() method shown above and it also creates a little session pinger thread (as shown in one of the Connections issues).

3) When the user clicks "Logout", the GUI calls the destroySession() method shown above and stops the session pinger.

All that seems to be working fine. The problems start if I try to log in again after having logged out. Sometimes, the createSession() method throws the following exception:
        at Ice.ConnectionI.parseMessage(
        at Ice.ConnectionI.access$100(
        at Ice.ConnectionI$

Other times, it succeeds, but the session pinger dies when it tries to ping because of the same exception.

Should what I'm trying to do even work? Should I be recreating the communicator or something? Any guesses as to what I'm doing wrong? I imagine it's something stupid, but I haven't had any luck finding it yet.




  • bernard
    bernard Jupiter, FL
    Hi Chris,

    Did you disable retries in your client? Does it work if you enable retries?

  • Hi Bernard,

    Thanks for the quick reply. I had Ice.RetryIntervals set to -1 because I thought retries weren't possible with Glacier2. That would explain the lack of retries, thanks.

    However, I've seen this post (from you) which suggests trying it. I did, but then I got an Ice.AlreadyRegisteredException instead. After a little more poking around, I discovered that I was calling communicator().createObjectAdapter(objectAdapterName) more than once with the same objectAdapterName. Caching created adapters appears to have fixed the problem.

    Is there a recommended set of retry intervals? Is something like this absurd/overkill?
    Ice.RetryIntervals=0 10 20 40 80 160 320 500 1000

    Thanks so much for your help!
  • marc
    marc Florida
    You only need one retry, so you can just use the default values (i.e., don't use any explicit retry settings).

    Note that this behavior is a bug. No retries should be necessary, as stated by the documentation. The next version of Ice will fix this.
  • As always, thanks, guys, for your help. Works great now! :)