Esempio n. 1
0
void
NodeEntry::setSession(const NodeSessionIPtr& session)
{
    Lock sync(*this);

    if(session)
    {
        while(_session)
        {
            if(_session->isDestroyed())
            {
                // If the current session has just been destroyed, wait for the setSession(0) call.
                assert(session != _session);
                wait();
            }
            else
            {
                NodeSessionIPtr session = _session;
                sync.release();
                try
                {
                    session->getNode()->ice_ping();
                    throw NodeActiveException();
                }
                catch(const Ice::LocalException&)
                {
                    try
                    {
                        session->destroy();
                    }
                    catch(const Ice::ObjectNotExistException&)
                    {
                    }
                }
                sync.acquire();
            }
        }
        
        //
        // Clear the saved proxy, the node has established a session
        // so we won't need anymore to try to register it with this
        // registry.
        //
        _proxy = 0;
    }
    else
    {
        if(!_session)
        {
            return;
        }
    }
    
    _session = session;
    notifyAll();

    if(_registering)
    {
        _registering = false;
        notifyAll();
    }

    if(session)
    {
        if(_cache.getTraceLevels() && _cache.getTraceLevels()->node > 0)
        {
            Ice::Trace out(_cache.getTraceLevels()->logger, _cache.getTraceLevels()->nodeCat);
            out << "node `" << _name << "' up";
        }
    }
    else
    {
        if(_cache.getTraceLevels() && _cache.getTraceLevels()->node > 0)
        {
            Ice::Trace out(_cache.getTraceLevels()->logger, _cache.getTraceLevels()->nodeCat);
            out << "node `" << _name << "' down";
        }
    }
}