Esempio n. 1
0
void
ObjectAdapterI::updateLocatorRegistry(const IceInternal::LocatorInfoPtr& locatorInfo,
                                      const Ice::ObjectPrx& proxy,
                                      bool registerProcess)
{
    if(!registerProcess && _id.empty())
    {
        return; // Nothing to update.
    }

    //
    // Call on the locator registry outside the synchronization to 
    // blocking other threads that need to lock this OA.
    //
    LocatorRegistryPrx locatorRegistry = locatorInfo ? locatorInfo->getLocatorRegistry() : LocatorRegistryPrx();
    string serverId;
    if(registerProcess)
    {
        assert(_instance);
        serverId = _instance->initializationData().properties->getProperty("Ice.ServerId");

        if(!locatorRegistry)
        {
            Warning out(_instance->initializationData().logger);
            out << "object adapter `" << getName() << "' cannot register the process without a locator registry";
        }
        else if(serverId.empty())
        {
            Warning out(_instance->initializationData().logger);
            out << "object adapter `" << getName() << "' cannot register the process without a value for Ice.ServerId";
        }
    }

    if(!locatorRegistry)
    {
        return;
    }

    if(!_id.empty())
    {
        try
        {
            if(_replicaGroupId.empty())
            {
                locatorRegistry->setAdapterDirectProxy(_id, proxy);
            }
            else
            {
                locatorRegistry->setReplicatedAdapterDirectProxy(_id, _replicaGroupId, proxy);
            }
        }
        catch(const AdapterNotFoundException&)
        {
            if(_instance->traceLevels()->location >= 1)
            {
                Trace out(_instance->initializationData().logger, _instance->traceLevels()->locationCat);
                out << "couldn't update object adapter `" + _id + "' endpoints with the locator registry:\n";
                out << "the object adapter is not known to the locator registry";
            }

            NotRegisteredException ex(__FILE__, __LINE__);
            ex.kindOfObject = "object adapter";
            ex.id = _id;
            throw ex;
        }
        catch(const InvalidReplicaGroupIdException&)
        {
            if(_instance->traceLevels()->location >= 1)
            {
                Trace out(_instance->initializationData().logger, _instance->traceLevels()->locationCat);
                out << "couldn't update object adapter `" + _id + "' endpoints with the locator registry:\n";
                out << "the replica group `" << _replicaGroupId << "' is not known to the locator registry";
            }

            NotRegisteredException ex(__FILE__, __LINE__);
            ex.kindOfObject = "replica group";
            ex.id = _replicaGroupId;
            throw ex;
        }
        catch(const AdapterAlreadyActiveException&)
        {
            if(_instance->traceLevels()->location >= 1)
            {
                Trace out(_instance->initializationData().logger, _instance->traceLevels()->locationCat);
                out << "couldn't update object adapter `" + _id + "' endpoints with the locator registry:\n";
                out << "the object adapter endpoints are already set";
            }

            ObjectAdapterIdInUseException ex(__FILE__, __LINE__);
            ex.id = _id;
            throw ex;
        }
        catch(const LocalException& ex)
        {
            if(_instance->traceLevels()->location >= 1)
            {
                Trace out(_instance->initializationData().logger, _instance->traceLevels()->locationCat);
                out << "couldn't update object adapter `" + _id + "' endpoints with the locator registry:\n" << ex;
            }
            throw; // TODO: Shall we raise a special exception instead of a non obvious local exception?
        }

        if(_instance->traceLevels()->location >= 1)
        {
            Trace out(_instance->initializationData().logger, _instance->traceLevels()->locationCat);
            out << "updated object adapter `" + _id + "' endpoints with the locator registry\n";
            out << "endpoints = ";
            if(proxy)
            {
                EndpointSeq endpts = proxy ? proxy->ice_getEndpoints() : EndpointSeq();
                ostringstream o;
                transform(endpts.begin(), endpts.end(), ostream_iterator<string>(o, endpts.size() > 1 ? ":" : ""), 
                          Ice::constMemFun(&Endpoint::toString));
                out << o.str();
            }
        }
    }

    if(registerProcess && !serverId.empty())
    {
        {
            IceUtil::Monitor<IceUtil::RecMutex>::Lock sync(*this);

            if(_processId.name == "")
            {
                ProcessPtr servant = new ProcessI(_communicator);
                _processId = addWithUUID(servant)->ice_getIdentity();
            }
        }

        try
        {
            locatorRegistry->setServerProcessProxy(serverId, ProcessPrx::uncheckedCast(createDirectProxy(_processId)));
        }
        catch(const ServerNotFoundException&)
        {
            if(_instance->traceLevels()->location >= 1)
            {
                Trace out(_instance->initializationData().logger, _instance->traceLevels()->locationCat);
                out << "couldn't register server `" + serverId + "' with the locator registry:\n";
                out << "the server is not known to the locator registry";
            }

            NotRegisteredException ex(__FILE__, __LINE__);
            ex.kindOfObject = "server";
            ex.id = serverId;
            throw ex;
        }
        catch(const Ice::LocalException& ex)
        {
            if(_instance->traceLevels()->location >= 1)
            {
                Trace out(_instance->initializationData().logger, _instance->traceLevels()->locationCat);
                out << "couldn't register server `" + serverId + "' with the locator registry:\n" << ex;
            }
            throw; // TODO: Shall we raise a special exception instead of a non obvious local exception?
        }

        if(_instance->traceLevels()->location >= 1)
        {
            Trace out(_instance->initializationData().logger, _instance->traceLevels()->locationCat);
            out << "registered server `" + serverId + "' with the locator registry";
        }
   }
}
Esempio n. 2
0
void
ObjectAdapterI::updateLocatorRegistry(const IceInternal::LocatorInfoPtr& locatorInfo,
                                      const Ice::ObjectPrx& proxy,
                                      bool registerProcess)
{
    if(!registerProcess && _id.empty())
    {
        return; // Nothing to update.
    }

    //
    // We must get and call on the locator registry outside the thread
    // synchronization to avoid deadlocks. (we can't make remote calls
    // within the OA synchronization because the remote call will
    // indirectly call isLocal() on this OA with the OA factory
    // locked).
    //
    // TODO: This might throw if we can't connect to the
    // locator. Shall we raise a special exception for the activate
    // operation instead of a non obvious network exception?
    //
    LocatorRegistryPrx locatorRegistry = locatorInfo ? locatorInfo->getLocatorRegistry() : LocatorRegistryPrx();
    string serverId;
    if(registerProcess)
    {
        assert(_instance);
        serverId = _instance->initializationData().properties->getProperty("Ice.ServerId");

        if(!locatorRegistry)
        {
            Warning out(_instance->initializationData().logger);
            out << "object adapter `" << getName() << "' cannot register the process without a locator registry";
        }
        else if(serverId.empty())
        {
            Warning out(_instance->initializationData().logger);
            out << "object adapter `" << getName() << "' cannot register the process without a value for Ice.ServerId";
        }
    }

    if(!locatorRegistry)
    {
        return;
    }

    if(!_id.empty())
    {
        try
        {
            if(_replicaGroupId.empty())
            {
                locatorRegistry->setAdapterDirectProxy(_id, proxy);
            }
            else
            {
                locatorRegistry->setReplicatedAdapterDirectProxy(_id, _replicaGroupId, proxy);
            }
        }
        catch(const AdapterNotFoundException&)
        {
            NotRegisteredException ex(__FILE__, __LINE__);
            ex.kindOfObject = "object adapter";
            ex.id = _id;
            throw ex;
        }
        catch(const InvalidReplicaGroupIdException&)
        {
            NotRegisteredException ex(__FILE__, __LINE__);
            ex.kindOfObject = "replica group";
            ex.id = _replicaGroupId;
            throw ex;
        }
        catch(const AdapterAlreadyActiveException&)
        {
            ObjectAdapterIdInUseException ex(__FILE__, __LINE__);
            ex.id = _id;
            throw ex;
        }
    }       

    if(registerProcess && !serverId.empty())
    {
        try
        {
            ProcessPtr servant = new ProcessI(_communicator);
            Ice::ObjectPrx process = createDirectProxy(addWithUUID(servant)->ice_getIdentity());
            locatorRegistry->setServerProcessProxy(serverId, ProcessPrx::uncheckedCast(process));
        }
        catch(const ServerNotFoundException&)
        {
            NotRegisteredException ex(__FILE__, __LINE__);
            ex.kindOfObject = "server";
            ex.id = serverId;
            throw ex;
        }
    }
}
Esempio n. 3
0
void
ObjectAdapterI::updateLocatorRegistry(const IceInternal::LocatorInfoPtr& locatorInfo, const Ice::ObjectPrxPtr& proxy)
{
    if(_id.empty() || !locatorInfo)
    {
        return; // Nothing to update.
    }

    LocatorRegistryPrxPtr locatorRegistry = locatorInfo->getLocatorRegistry();
    if(!locatorRegistry)
    {
        return;
    }

    try
    {
        if(_replicaGroupId.empty())
        {
            locatorRegistry->setAdapterDirectProxy(_id, proxy);
        }
        else
        {
            locatorRegistry->setReplicatedAdapterDirectProxy(_id, _replicaGroupId, proxy);
        }
    }
    catch(const AdapterNotFoundException&)
    {
        if(_instance->traceLevels()->location >= 1)
        {
            Trace out(_instance->initializationData().logger, _instance->traceLevels()->locationCat);
            out << "couldn't update object adapter `" + _id + "' endpoints with the locator registry:\n";
            out << "the object adapter is not known to the locator registry";
        }

        throw NotRegisteredException(__FILE__, __LINE__, "object adapter", _id);
    }
    catch(const InvalidReplicaGroupIdException&)
    {
        if(_instance->traceLevels()->location >= 1)
        {
            Trace out(_instance->initializationData().logger, _instance->traceLevels()->locationCat);
            out << "couldn't update object adapter `" + _id + "' endpoints with the locator registry:\n";
            out << "the replica group `" << _replicaGroupId << "' is not known to the locator registry";
        }

        throw NotRegisteredException(__FILE__, __LINE__, "replica group", _replicaGroupId);
    }
    catch(const AdapterAlreadyActiveException&)
    {
        if(_instance->traceLevels()->location >= 1)
        {
            Trace out(_instance->initializationData().logger, _instance->traceLevels()->locationCat);
            out << "couldn't update object adapter `" + _id + "' endpoints with the locator registry:\n";
            out << "the object adapter endpoints are already set";
        }

        throw ObjectAdapterIdInUseException(__FILE__, __LINE__, _id);
    }
    catch(const ObjectAdapterDeactivatedException&)
    {
        // Expected if collocated call and OA is deactivated, ignore.
    }
    catch(const CommunicatorDestroyedException&)
    {
        // Ignore.
    }
    catch(const LocalException& ex)
    {
        if(_instance->traceLevels()->location >= 1)
        {
            Trace out(_instance->initializationData().logger, _instance->traceLevels()->locationCat);
            out << "couldn't update object adapter `" + _id + "' endpoints with the locator registry:\n" << ex;
        }
        throw; // TODO: Shall we raise a special exception instead of a non obvious local exception?
    }

    if(_instance->traceLevels()->location >= 1)
    {
        Trace out(_instance->initializationData().logger, _instance->traceLevels()->locationCat);
        out << "updated object adapter `" + _id + "' endpoints with the locator registry\n";
        out << "endpoints = ";
        if(proxy)
        {
            EndpointSeq endpts = proxy ? proxy->ice_getEndpoints() : EndpointSeq();
            ostringstream o;
            transform(endpts.begin(), endpts.end(), ostream_iterator<string>(o, endpts.size() > 1 ? ":" : ""),
                      Ice::constMemFun(&Endpoint::toString));
            out << o.str();
        }
    }
}
Esempio n. 4
0
void
ObjectAdapter::updateLocatorRegistry(const IceInternal::LocatorInfoPtr& locatorInfo, const Ice::ObjectPrx& proxy)
{
    if(_id.empty())
    {
        return; // Nothing to update.
    }

    //
    // Call on the locator registry outside the synchronization to
    // blocking other threads that need to lock this OA.
    //
    LocatorRegistryPrx locatorRegistry = locatorInfo ? locatorInfo->getLocatorRegistry() : LocatorRegistryPrx();
    if(!locatorRegistry)
    {
        return;
    }

    if(!_id.empty())
    {
        try
        {
            if(_replicaGroupId.empty())
            {
                locatorRegistry->setAdapterDirectProxy(_id, proxy);
            }
            else
            {
                locatorRegistry->setReplicatedAdapterDirectProxy(_id, _replicaGroupId, proxy);
            }
        }
        catch(const AdapterNotFoundException&)
        {
            if(_instance->traceLevels()->location >= 1)
            {
                Trace out(_instance->initializationData().logger, _instance->traceLevels()->locationCat);
                out << "couldn't update object adapter `" + _id + "' endpoints with the locator registry:\n";
                out << "the object adapter is not known to the locator registry";
            }

            NotRegisteredException ex(__FILE__, __LINE__);
            ex.kindOfObject = "object adapter";
            ex.id = _id;
            throw ex;
        }
        catch(const InvalidReplicaGroupIdException&)
        {
            if(_instance->traceLevels()->location >= 1)
            {
                Trace out(_instance->initializationData().logger, _instance->traceLevels()->locationCat);
                out << "couldn't update object adapter `" + _id + "' endpoints with the locator registry:\n";
                out << "the replica group `" << _replicaGroupId << "' is not known to the locator registry";
            }

            NotRegisteredException ex(__FILE__, __LINE__);
            ex.kindOfObject = "replica group";
            ex.id = _replicaGroupId;
            throw ex;
        }
        catch(const AdapterAlreadyActiveException&)
        {
            if(_instance->traceLevels()->location >= 1)
            {
                Trace out(_instance->initializationData().logger, _instance->traceLevels()->locationCat);
                out << "couldn't update object adapter `" + _id + "' endpoints with the locator registry:\n";
                out << "the object adapter endpoints are already set";
            }

            ObjectAdapterIdInUseException ex(__FILE__, __LINE__);
            ex.id = _id;
            throw ex;
        }
        catch(const LocalException& ex)
        {
            if(_instance->traceLevels()->location >= 1)
            {
                Trace out(_instance->initializationData().logger, _instance->traceLevels()->locationCat);
                out << "couldn't update object adapter `" + _id + "' endpoints with the locator registry:\n"
                    << ex.toString();
            }
            throw; // TODO: Shall we raise a special exception instead of a non obvious local exception?
        }

        if(_instance->traceLevels()->location >= 1)
        {
            Trace out(_instance->initializationData().logger, _instance->traceLevels()->locationCat);
            out << "updated object adapter `" + _id + "' endpoints with the locator registry\n";
            out << "endpoints = ";
            vector<EndpointPtr> endpts = proxy ? proxy->__reference()->getEndpoints() : vector<EndpointPtr>();
            for(vector<EndpointPtr>::iterator p = endpts.begin(); p != endpts.end(); ++p)
            {
                if(p != endpts.begin())
                {
                    out << ":";
                }
                out << (*p)->toString();
            }
        }
    }
}