void
IceInternal::OutgoingConnectionFactory::ConnectCallback::nextConnector()
{
    Ice::ConnectionIPtr connection;
    try
    {

        const CommunicatorObserverPtr& obsv = _factory->_instance->getObserver();
        if(obsv)
        {
            _observer = obsv->getConnectionEstablishmentObserver(_iter->endpoint, _iter->connector->toString());
            if(_observer)
            {
                _observer->attach();
            }
        }

        assert(_iter != _connectors.end());
        connection = _factory->createConnection(_iter->connector->connect(), *_iter);
        connection->start(this);
    }
    catch(const Ice::LocalException& ex)
    {
        connectionStartFailed(connection, ex);
    }
}
Example #2
0
void
IceInternal::ConnectionACMMonitor::runTimerTask()
{
    Ice::ConnectionIPtr connection;
    {
        Lock sync(*this);
        if(!_connection)
        {
            return;
        }
        connection = _connection;
    }

    try
    {
        connection->monitor(IceUtil::Time::now(IceUtil::Time::Monotonic), _config);
    }
    catch(const exception& ex)
    {
        _parent->handleException(ex);
    }
    catch(...)
    {
        _parent->handleException();
    }
}
Ice::ConnectionI*
ConnectRequestHandler::sendRequest(Outgoing* out)
{
    // Must be called first, _compress might not be initialized before this returns.
    Ice::ConnectionIPtr connection = getConnection(true);
    assert(connection);
    if(!connection->sendRequest(out, _compress, _response) || _response)
    {
        return _connection.get(); // The request hasn't been sent or we're expecting a response.
    }
    else
    {
        return 0; // The request has been sent.
    }
}
Example #4
0
ReferencePtr
IceInternal::ReferenceFactory::create(const Identity& ident, const Ice::ConnectionIPtr& connection)
{
    if(ident.name.empty() && ident.category.empty())
    {
        return 0;
    }

    //
    // Create new reference
    //
    return new FixedReference(_instance, 
                              _communicator, 
                              ident, 
                              "",  // Facet
                              connection->endpoint()->datagram() ? Reference::ModeDatagram : Reference::ModeTwoway,
                              connection->endpoint()->secure(),
                              connection);
}
ConnectionIPtr
IceInternal::OutgoingConnectionFactory::createConnection(const TransceiverPtr& transceiver, const ConnectorInfo& ci)
{
    IceUtil::Monitor<IceUtil::Mutex>::Lock sync(*this);
    assert(_pending.find(ci.connector) != _pending.end() && transceiver);

    //
    // Create and add the connection to the connection map. Adding the connection to the map
    // is necessary to support the interruption of the connection initialization and validation
    // in case the communicator is destroyed.
    //
    Ice::ConnectionIPtr connection;
    try
    {
        if(_destroyed)
        {
            throw Ice::CommunicatorDestroyedException(__FILE__, __LINE__);
        }

        connection = new ConnectionI(_communicator, _instance, _reaper, transceiver, ci.connector,
                                     ci.endpoint->compress(false), 0);
    }
    catch(const Ice::LocalException&)
    {
        try
        {
            transceiver->close();
        }
        catch(const Ice::LocalException&)
        {
            // Ignore
        }
        throw;
    }

    _connections.insert(pair<const ConnectorPtr, ConnectionIPtr>(ci.connector, connection));
    _connectionsByEndpoint.insert(pair<const EndpointIPtr, ConnectionIPtr>(connection->endpoint(), connection));
    _connectionsByEndpoint.insert(pair<const EndpointIPtr, ConnectionIPtr>(connection->endpoint()->compress(true),
                                  connection));
    return connection;
}
void
IceInternal::IncomingConnectionFactory::connectionStartCompleted(const Ice::ConnectionIPtr& connection)
{
    IceUtil::Monitor<IceUtil::Mutex>::Lock sync(*this);

    //
    // Initialy, connections are in the holding state. If the factory is active
    // we activate the connection.
    //
    if(_state == StateActive)
    {
        connection->activate();
    }
}
Example #7
0
bool
FlushBatch::send(const Ice::ConnectionIPtr& connection, bool, bool)
{
    return connection->flushBatchRequests(this);
}
Example #8
0
bool
Outgoing::send(const Ice::ConnectionIPtr& connection, bool compress, bool response)
{
    return connection->sendRequest(this, compress, response);
}
ConnectionIPtr
IceInternal::OutgoingConnectionFactory::create(const vector<EndpointIPtr>& endpts, bool hasMore,
        Ice::EndpointSelectionType selType, bool& compress)
{
    assert(!endpts.empty());

    //
    // Apply the overrides.
    //
    vector<EndpointIPtr> endpoints = applyOverrides(endpts);

    //
    // Try to find a connection to one of the given endpoints.
    //
    Ice::ConnectionIPtr connection = findConnection(endpoints, compress);
    if(connection)
    {
        return connection;
    }

    IceUtil::UniquePtr<Ice::LocalException> exception;

    //
    // If we didn't find a connection with the endpoints, we create the connectors
    // for the endpoints.
    //
    vector<ConnectorInfo> connectors;
    for(vector<EndpointIPtr>::const_iterator p = endpoints.begin(); p != endpoints.end(); ++p)
    {
        //
        // Create connectors for the endpoint.
        //
        try
        {
            vector<ConnectorPtr> cons = (*p)->connectors(selType);
            assert(!cons.empty());
            for(vector<ConnectorPtr>::const_iterator r = cons.begin(); r != cons.end(); ++r)
            {
                assert(*r);
                connectors.push_back(ConnectorInfo(*r, *p));
            }
        }
        catch(const Ice::LocalException& ex)
        {
            exception.reset(ex.ice_clone());
            handleException(ex, hasMore || p != endpoints.end() - 1);
        }
    }

    if(connectors.empty())
    {
        assert(exception.get());
        exception->ice_throw();
    }

    //
    // Try to get a connection to one of the connectors. A null result indicates that no
    // connection was found and that we should try to establish the connection (and that
    // the connectors were added to _pending to prevent other threads from establishing
    // the connection).
    //
    connection = getConnection(connectors, 0, compress);
    if(connection)
    {
        return connection;
    }

    //
    // Try to establish the connection to the connectors.
    //
    DefaultsAndOverridesPtr defaultsAndOverrides = _instance->defaultsAndOverrides();
    const CommunicatorObserverPtr& obsv = _instance->getObserver();
    vector<ConnectorInfo>::const_iterator q;
    for(q = connectors.begin(); q != connectors.end(); ++q)
    {
        ObserverPtr observer;
        if(obsv)
        {
            observer = obsv->getConnectionEstablishmentObserver(q->endpoint, q->connector->toString());
            if(observer)
            {
                observer->attach();
            }
        }

        try
        {
            connection = createConnection(q->connector->connect(), *q);
            connection->start(0);

            if(observer)
            {
                observer->detach();
            }

            if(defaultsAndOverrides->overrideCompress)
            {
                compress = defaultsAndOverrides->overrideCompressValue;
            }
            else
            {
                compress = q->endpoint->compress();
            }

            connection->activate();
            break;
        }
        catch(const Ice::CommunicatorDestroyedException& ex)
        {
            if(observer)
            {
                observer->failed(ex.ice_name());
                observer->detach();
            }
            exception.reset(ex.ice_clone());
            handleConnectionException(*exception.get(), hasMore || q != connectors.end() - 1);
            connection = 0;
            break; // No need to continue
        }
        catch(const Ice::LocalException& ex)
        {
            if(observer)
            {
                observer->failed(ex.ice_name());
                observer->detach();
            }
            exception.reset(ex.ice_clone());
            handleConnectionException(*exception.get(), hasMore || q != connectors.end() - 1);
            connection = 0;
        }
    }

    //
    // Finish creating the connection (this removes the connectors from the _pending
    // list and notifies any waiting threads).
    //
    if(connection)
    {
        finishGetConnection(connectors, *q, connection, 0);
    }
    else
    {
        finishGetConnection(connectors, *exception.get(), 0);
    }

    if(!connection)
    {
        assert(exception.get());
        exception->ice_throw();
    }

    return connection;
}
Example #10
0
bool
ProxyFlushBatch::invokeRemote(const Ice::ConnectionIPtr& connection, bool compress, bool response)
{
    return connection->sendRequest(this, compress, response, _batchRequestNum);
}
Example #11
0
bool
Outgoing::invokeRemote(const Ice::ConnectionIPtr& connection, bool compress, bool response)
{
    return connection->sendRequest(this, compress, response, 0);
}