Exemple #1
0
Ice::ObjectProxySeq
QueryI::findAllReplicas(const Ice::ObjectPrx& proxy, const Ice::Current&) const
{
    if(!proxy)
    {
        return Ice::ObjectProxySeq();
    }

    //
    // If the given proxy has an empty adapter id, we check if it's a
    // well-known object. If it's a well-known object we use the
    // registered proxy instead.
    //
    Ice::ObjectPrx prx = proxy;
    if(prx->ice_getAdapterId().empty())
    {
        try
        {
            ObjectInfo info = _database->getObjectInfo(prx->ice_getIdentity());
            prx = info.proxy;
        }
        catch(const ObjectNotRegisteredException&)
        {
            return Ice::ObjectProxySeq();
        }
    }

    try
    {
        AdapterInfoSeq infos = _database->getAdapterInfo(prx->ice_getAdapterId());
        if(infos.empty() || infos[0].replicaGroupId != prx->ice_getAdapterId()) 
        {
            // The adapter id doesn't refer to a replica group or the replica group is empty.
            return Ice::ObjectProxySeq();
        }

        Ice::ObjectProxySeq proxies;
        for(AdapterInfoSeq::const_iterator p = infos.begin(); p != infos.end(); ++p)
        {
            assert(!p->id.empty());
            proxies.push_back(prx->ice_adapterId(p->id));
        }
        return proxies;
    }
    catch(const AdapterNotExistException&)
    {
        return Ice::ObjectProxySeq();
    }
}