Esempio n. 1
0
void
SessionHelperI::connected(const Glacier2::RouterPrx& router, const Glacier2::SessionPrx& session)
{
    //
    // Remote invocation should be done without acquire a mutex lock.
    //
    assert(router);
    Ice::ConnectionPtr conn = router->ice_getCachedConnection();
    string category = router->getCategoryForClient();
    Ice::Long timeout = router->getSessionTimeout();
    
    {
        IceUtil::Mutex::Lock sync(_mutex);
        _router = router;

        if(_destroy)
        {
            //
            // Run the destroyInternal in a thread. This is because it
            // destroyInternal makes remote invocations.
            //
            IceUtil::ThreadPtr thread = new DestroyInternal(this, _callback);
            thread->start().detach();
            return;
        }

        //
        // Cache the category.
        //
        _category = category;

        //
        // Assign the session after _destroy is checked.
        //
        _session = session;
        _connected = true;

        assert(!_refreshThread);
        
        if(timeout > 0)
        {
            _refreshThread = new SessionRefreshThread(this, _router, (timeout)/2);
            _refreshThread->start();
        }
    }
    dispatchCallback(new Connected(_callback, this), conn);
}
Esempio n. 2
0
void
SessionHelperI::connected(const Glacier2::RouterPrx& router, const Glacier2::SessionPrx& session)
{
    //
    // Remote invocation should be done without acquiring a mutex lock.
    //
    assert(router);
    Ice::ConnectionPtr conn = router->ice_getCachedConnection();
    string category = router->getCategoryForClient();
    Ice::Int acmTimeout = 0;
    try
    {
        acmTimeout = router->getACMTimeout();
    }
    catch(const Ice::OperationNotExistException&)
    {
    }

    if(acmTimeout <= 0)
    {
        acmTimeout = static_cast<Ice::Int>(router->getSessionTimeout());
    }

    //
    // We create the callback object adapter here because createObjectAdapter internally
    // makes synchronous RPCs to the router. We can't create the OA on-demand when the
    // client calls objectAdapter() or addWithUUID() because they can be called from the
    // GUI thread.
    //
    if(_useCallbacks)
    {
        _adapter = _communicator->createObjectAdapterWithRouter("", router);
        _adapter->activate();
    }

    bool destroy;
    {
        IceUtil::Mutex::Lock sync(_mutex);
        _router = router;
        destroy = _destroy;

        if(!_destroy)
        {
            //
            // Cache the category.
            //
            _category = category;

            //
            // Assign the session after _destroy is checked.
            //
            _session = session;
            _connected = true;

            if(acmTimeout > 0)
            {
                Ice::ConnectionPtr connection = _router->ice_getCachedConnection();
                assert(connection);
                connection->setACM(acmTimeout, IceUtil::None, Ice::HeartbeatAlways);
                connection->setCallback(new ConnectionCallbackI(this));
            }
        }
    }

    if(destroy)
    {
        //
        // connected() is only called from the ConnectThread so it is ok to
        // call destroyInternal here.
        //
        destroyInternal(new Disconnected(this, _callback));
    }
    else
    {
        dispatchCallback(new Connected(_callback, this), conn);
    }
}