Archived

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

Glacier2 destroy session question

xdm
xdm La Coruña, Spain
Hi i have a question regards Glacier2 sessions

When i call router->destroySession();

glacier automatic remove the session servant from the adapter, or must my code remove the Session servant?


I observer that ClientSessionI destructor is not automatic called in my case.

I using Ice-3.2 release version | gentoo linux gcc-4.6


Here is my SessionManager implementation.
Glacier2::SessionPrx Oz::SessionManagerI::create(const std::string& login,
    const Glacier2::SessionControlPrx& sessionControl,const Ice::Current& current){
    Glacier2::SessionPrx sessionPx = 0;
    try{
        Ice::Identity sessionId;
        sessionId.category= "_" + login;
        sessionId.name = IceUtil::generateUUID();
        QString userId = login.c_str();
        QStringList userIdTokens = userId.split("@");
        std::string userName = userIdTokens[0].toUtf8().data();
        std::string domainName = userIdTokens[1].toUtf8().data();
        Oz::Domains::IDomainPrx domainPx = _domainServer->getDomain(domainName);
        Oz::Domains::IUserPrx userPx = domainPx->getUser(userName);

        ClientSessionIPtr session = new ClientSessionI(sessionId,userPx,userName,domainPx,domainName);
        sessionPx = Glacier2::SessionPrx::uncheckedCast(current.adapter->add(session,sessionId));
    }catch(const std::exception& std_e){
        std::cerr<<"file: "<<__FILE__<<" line: "<<__LINE__<<" "<<std_e.what()<<std::endl;
    }
    return sessionPx;
}

Code for login
void Oz::Ui::Application::login(const QString& user,const QString& password){
    try{
        Glacier2::RouterPrx router = getRouter();
        _session = IClientSessionPrx::uncheckedCast(router->createSession(user.toUtf8().data(),password.toUtf8().data()));
        _adapter = communicator()->createObjectAdapter("Ui.Client");
        _adapter->activate();
        loginSuccess();
    }catch(const Glacier2::PermissionDeniedException& glacier2_e){
        showError(QString(glacier2_e.reason.c_str()));
    }catch(const Ice::Exception& ice_e){
        std::ostringstream os;
        os << ice_e;
        showError(QString(os.str().c_str()));
    }
}

Code for logout
void Oz::Ui::Application::logout(){
    try{
        _router->destroySession();
    }catch(const Ice::ConnectionLostException& connectionlost_e){
        //Expected when destroy session.
        _adapter->destroy();
        _session = 0;
        _mainWindow->logoutSuccess();
    }catch(const Ice::Exception& ice_e){
        showError(QString(ice_e.what()));
    }
}

Comments

  • benoit
    benoit Rennes, France
    You need to remove the session servant from the adapter. You can do this from the session destroy() method (which is called by Glacier2 when your client calls router->destroySession()).

    See the demo from the demo/Glacier2/callback directory for an example.

    Cheers,
    Benoit.