Ejemplo n.º 1
0
RequestHandlerPtr
ConnectionRequestHandler::update(const RequestHandlerPtr& previousHandler, const RequestHandlerPtr& newHandler)
{
    assert(previousHandler);
    try
    {
        if(previousHandler.get() == this)
        {
            return newHandler;
        }
        else if(previousHandler->getConnection() == _connection)
        {
            //
            // If both request handlers point to the same connection, we also
            // update the request handler. See bug ICE-5489 for reasons why
            // this can be useful.
            //
            return newHandler;
        }
    }
    catch(const Ice::Exception&)
    {
        // Ignore.
    }
    return this;
}
Ejemplo n.º 2
0
Archivo: Proxy.cpp Proyecto: lmtoo/ice
ConnectionPtr
IceProxy::Ice::Object::ice_getConnection()
{
    InvocationObserver observer(this, ice_getConnection_name, ::Ice::noExplicitContext);
    int cnt = 0;
    while(true)
    {
        RequestHandlerPtr handler;
        try
        {
            handler = __getRequestHandler();
            return handler->waitForConnection(); // Wait for the connection to be established.
        }
        catch(const IceInternal::RetryException&)
        {
            __updateRequestHandler(handler, 0); // Clear request handler and retry.
        }
        catch(const Exception& ex)
        {
            try
            {
                int interval = __handleException(ex, handler, ICE_ENUM(OperationMode, Idempotent), false, cnt);
                observer.retried();
                if(interval > 0)
                {
                    IceUtil::ThreadControl::sleep(IceUtil::Time::milliSeconds(interval));
                }
            }
            catch(const Exception& exc)
            {
                observer.failed(exc.ice_id());
                throw;
            }
        }
    }
}
Ejemplo n.º 3
0
RequestHandlerPtr
ConnectRequestHandler::update(const RequestHandlerPtr& previousHandler, const RequestHandlerPtr& newHandler)
{
    return previousHandler.get() == this ? newHandler : ICE_SHARED_FROM_THIS;
}
Ejemplo n.º 4
0
void
FlushBatch::invoke()
{
    assert(_proxy || _connection);

    if(_connection)
    {
        if(_connection->flushBatchRequests(this))
        {
            return;
        }

        Monitor<Mutex>::Lock sync(_monitor);
        while(!_exception.get() && !_sent)
        {
            _monitor.wait();
        }
        if(_exception.get())
        {
            _exception->ice_throw();
        }
        return;
    }

    RequestHandlerPtr handler;
    try
    {
        handler = _proxy->__getRequestHandler();
        if(handler->sendRequest(this))
        {
            return;
        }

        bool timedOut = false;
        {
            Monitor<Mutex>::Lock sync(_monitor);
            int timeout = _proxy->__reference()->getInvocationTimeout();
            if(timeout > 0)
            {
                Time now = Time::now(Time::Monotonic);
                Time deadline = now + Time::milliSeconds(timeout);
                while(!_exception.get() && !_sent && !timedOut)
                {
                    _monitor.timedWait(deadline - now);                
                    if(!_exception.get() && !_sent)
                    {
                        now = Time::now(Time::Monotonic);
                        timedOut = now >= deadline;
                    }
                }
            }
            else
            {
                while(!_exception.get() && !_sent)
                {
                    _monitor.wait();
                }
            }
        }

        if(timedOut)
        {
            Ice::InvocationTimeoutException ex(__FILE__, __LINE__);
            handler->requestCanceled(this, ex);

            //
            // Wait for the exception to propagate. It's possible the request handler ignores
            // the timeout if there was a failure shortly before requestTimedOut got called. 
            // In this case, the exception should be set on the Outgoing.
            //
            Monitor<Mutex>::Lock sync(_monitor);
            while(!_exception.get() && !_sent)
            {
                _monitor.wait();
            }
        }
    
        if(_exception.get())
        {
            _exception->ice_throw();
        }
    }
    catch(const RetryException& ex)
    {
        _proxy->__setRequestHandler(handler, 0); // Clear request handler
        ex.get()->ice_throw(); // Throw to notify the user that batch requests were potentially lost.
    }
    catch(const Ice::Exception& ex)
    {
        _proxy->__setRequestHandler(handler, 0); // Clear request handler
        _observer.failed(ex.ice_name());
        throw; // Throw to notify the user that batch requests were potentially lost.
    }
}
Ejemplo n.º 5
0
RequestHandlerPtr
CollocatedRequestHandler::update(const RequestHandlerPtr& previousHandler, const RequestHandlerPtr& newHandler)
{
    return previousHandler.get() == this ? newHandler : this;
}
Ejemplo n.º 6
0
RequestHandlerPtr
CollocatedRequestHandler::update(const RequestHandlerPtr& previousHandler, const RequestHandlerPtr& newHandler)
{
    return previousHandler.get() == this ? newHandler : shared_from_this();
}