Пример #1
0
 public void asyncRequestCanceled(OutgoingAsyncBase outAsync, Ice.LocalException ex)
 {
     Debug.Assert(_outAsync == outAsync);
     if (_retryQueue.cancel(this))
     {
         if (_instance.traceLevels().retry >= 1)
         {
             _instance.initializationData().logger.trace(_instance.traceLevels().retryCat,
                                                         string.Format("operation retry canceled\n{0}", ex));
         }
         if (_outAsync.exception(ex))
         {
             _outAsync.invokeExceptionAsync();
         }
     }
 }
Пример #2
0
        private bool sentAsync(OutgoingAsyncBase outAsync)
        {
            lock (this)
            {
                if (!_sendAsyncRequests.Remove(outAsync))
                {
                    return(false); // The request timed-out.
                }
            }

            Ice.AsyncCallback cb = outAsync.sent();
            if (cb != null)
            {
                outAsync.invokeSent(cb);
            }
            return(true);
        }
Пример #3
0
        private bool sentAsync(OutgoingAsyncBase outAsync)
        {
            lock (this)
            {
                if (!_sendAsyncRequests.Remove(outAsync))
                {
                    return(false); // The request timed-out.
                }

                if (!outAsync.sent())
                {
                    return(true);
                }
            }
            outAsync.invokeSent();
            return(true);
        }
Пример #4
0
 public bool handleException(Ice.Exception ex, OutgoingAsyncBase og)
 {
     //
     // If this is a synchronous call, we can notify the task from this thread to avoid
     // the thread context switch. We know there aren't any continuations setup with the
     // task.
     //
     if (og.isSynchronous())
     {
         handleInvokeException(ex, og);
         return(false);
     }
     else
     {
         return(true);
     }
 }
Пример #5
0
 public void asyncRequestCanceled(OutgoingAsyncBase outAsync, Ice.LocalException ex)
 {
     Debug.Assert(_outAsync == outAsync);
     if (_retryQueue.cancel(this))
     {
         if (_instance.traceLevels().retry >= 1)
         {
             string s = "operation retry canceled\n" + ex;
             _instance.initializationData().logger.trace(_instance.traceLevels().retryCat, s);
         }
         Ice.AsyncCallback cb = _outAsync.completed(ex);
         if (cb != null)
         {
             _outAsync.invokeCompletedAsync(cb);
         }
     }
 }
Пример #6
0
 public bool handleResponse(bool userThread, bool ok, OutgoingAsyncBase og)
 {
     //
     // If this is a synchronous call, we can notify the task from this thread to avoid the
     // thread context switch. We know there aren't any continuations setup with the
     // task.
     //
     if (userThread || og.isSynchronous())
     {
         handleInvokeResponse(ok, og);
         return(false);
     }
     else
     {
         return(true);
     }
 }
Пример #7
0
 public void asyncRequestCanceled(OutgoingAsyncBase outAsync, Ice.LocalException ex)
 {
     lock (this)
     {
         int requestId;
         if (_sendAsyncRequests.TryGetValue(outAsync, out requestId))
         {
             if (requestId > 0)
             {
                 _asyncRequests.Remove(requestId);
             }
             _sendAsyncRequests.Remove(outAsync);
             Ice.AsyncCallback cb = outAsync.completed(ex);
             if (cb != null)
             {
                 outAsync.invokeCompletedAsync(cb);
             }
             _adapter.decDirectCount(); // invokeAll won't be called, decrease the direct count.
             return;
         }
         if (outAsync is OutgoingAsync)
         {
             OutgoingAsync o = (OutgoingAsync)outAsync;
             Debug.Assert(o != null);
             foreach (KeyValuePair <int, OutgoingAsyncBase> e in _asyncRequests)
             {
                 if (e.Value == o)
                 {
                     _asyncRequests.Remove(e.Key);
                     Ice.AsyncCallback cb = outAsync.completed(ex);
                     if (cb != null)
                     {
                         outAsync.invokeCompletedAsync(cb);
                     }
                     return;
                 }
             }
         }
     }
 }
Пример #8
0
 public void AsyncRequestCanceled(OutgoingAsyncBase outAsync, Ice.LocalException ex)
 {
     lock (this)
     {
         if (_sendAsyncRequests.TryGetValue(outAsync, out int requestId))
         {
             if (requestId > 0)
             {
                 _asyncRequests.Remove(requestId);
             }
             _sendAsyncRequests.Remove(outAsync);
             if (outAsync.Exception(ex))
             {
                 outAsync.InvokeExceptionAsync();
             }
             _adapter.DecDirectCount(); // invokeAll won't be called, decrease the direct count.
             return;
         }
         if (outAsync is OutgoingAsync o)
         {
             Debug.Assert(o != null);
             foreach (KeyValuePair <int, OutgoingAsyncBase> e in _asyncRequests)
             {
                 if (e.Value == o)
                 {
                     _asyncRequests.Remove(e.Key);
                     if (outAsync.Exception(ex))
                     {
                         outAsync.InvokeExceptionAsync();
                     }
                     return;
                 }
             }
         }
     }
 }
Пример #9
0
        public int invokeAsyncRequest(OutgoingAsyncBase outAsync, int batchRequestNum, bool synchronous)
        {
            //
            // Increase the direct count to prevent the thread pool from being destroyed before
            // invokeAll is called. This will also throw if the object adapter has been deactivated.
            //
            _adapter.incDirectCount();

            int requestId = 0;

            try
            {
                lock (this)
                {
                    outAsync.cancelable(this); // This will throw if the request is canceled

                    if (_response)
                    {
                        requestId = ++_requestId;
                        _asyncRequests.Add(requestId, outAsync);
                    }

                    _sendAsyncRequests.Add(outAsync, requestId);
                }
            }
            catch (Exception)
            {
                _adapter.decDirectCount();
                throw;
            }

            outAsync.attachCollocatedObserver(_adapter, requestId);
            if (!synchronous || !_response || _reference.getInvocationTimeout() > 0)
            {
                // Don't invoke from the user thread if async or invocation timeout is set
                _adapter.getThreadPool().dispatch(
                    () =>
                {
                    if (sentAsync(outAsync))
                    {
                        invokeAll(outAsync.getOs(), requestId, batchRequestNum);
                    }
                }, null);
            }
            else if (_dispatcher)
            {
                _adapter.getThreadPool().dispatchFromThisThread(
                    () =>
                {
                    if (sentAsync(outAsync))
                    {
                        invokeAll(outAsync.getOs(), requestId, batchRequestNum);
                    }
                }, null);
            }
            else // Optimization: directly call invokeAll if there's no dispatcher.
            {
                if (sentAsync(outAsync))
                {
                    invokeAll(outAsync.getOs(), requestId, batchRequestNum);
                }
            }
            return(OutgoingAsyncBase.AsyncStatusQueued);
        }
Пример #10
0
 public override void handleInvokeResponse(bool ok, OutgoingAsyncBase og)
 {
     SetResult(((OutgoingAsyncT <T>)og).getResult(ok));
 }
Пример #11
0
 public abstract void handleInvokeResponse(bool ok, OutgoingAsyncBase og);
Пример #12
0
 public void handleInvokeException(Ice.Exception ex, OutgoingAsyncBase og)
 {
     SetException(ex);
 }
Пример #13
0
 public virtual void handleInvokeSent(bool sentSynchronously, bool done, bool alreadySent, OutgoingAsyncBase og)
 {
     if (progress_ != null && !alreadySent)
     {
         progress_.Report(sentSynchronously);
     }
     if (done)
     {
         SetResult(default(T));
     }
 }
Пример #14
0
        public bool invokeAsyncRequest(OutgoingAsyncBase outAsync, int batchRequestNum, bool synchronous,
                                       out Ice.AsyncCallback sentCallback)
        {
            //
            // Increase the direct count to prevent the thread pool from being destroyed before
            // invokeAll is called. This will also throw if the object adapter has been deactivated.
            //
            _adapter.incDirectCount();

            int requestId = 0;

            try
            {
                lock (this)
                {
                    outAsync.cancelable(this); // This will throw if the request is canceled

                    if (_response)
                    {
                        requestId = ++_requestId;
                        _asyncRequests.Add(requestId, outAsync);
                    }

                    _sendAsyncRequests.Add(outAsync, requestId);
                }
            }
            catch (System.Exception ex)
            {
                _adapter.decDirectCount();
                throw ex;
            }

            outAsync.attachCollocatedObserver(_adapter, requestId);

            if (synchronous)
            {
                //
                // Treat this collocated call as if it is a synchronous invocation.
                //
                if (_reference.getInvocationTimeout() > 0 || !_response)
                {
                    // Don't invoke from the user thread, invocation timeouts wouldn't work otherwise.
                    _adapter.getThreadPool().dispatch(() =>
                    {
                        if (sentAsync(outAsync))
                        {
                            invokeAll(outAsync.getOs(), requestId, batchRequestNum);
                        }
                    }, null);
                }
                else if (_dispatcher)
                {
                    _adapter.getThreadPool().dispatchFromThisThread(() =>
                    {
                        if (sentAsync(outAsync))
                        {
                            invokeAll(outAsync.getOs(), requestId, batchRequestNum);
                        }
                    }, null);
                }
                else // Optimization: directly call invokeAll if there's no dispatcher.
                {
                    if (sentAsync(outAsync))
                    {
                        invokeAll(outAsync.getOs(), requestId, batchRequestNum);
                    }
                }
                sentCallback = null;
            }
            else
            {
                _adapter.getThreadPool().dispatch(() =>
                {
                    if (sentAsync(outAsync))
                    {
                        invokeAll(outAsync.getOs(), requestId, batchRequestNum);
                    }
                }, null);
                sentCallback = null;
            }
            return(false);
        }
Пример #15
0
 public void asyncRequestCanceled(OutgoingAsyncBase outAsync, Ice.LocalException ex)
 {
     _connection.asyncRequestCanceled(outAsync, ex);
 }
Пример #16
0
 internal void canceled()
 {
     Debug.Assert(outAsync != null); // Only requests can timeout.
     outAsync = null;
 }
Пример #17
0
 internal OutgoingMessage(IceInternal.OutgoingAsyncBase outAsync, OutputStream stream,
                          bool compress, int requestId)
 {
     this.outAsync = outAsync;
     this.stream = stream;
     this.compress = compress;
     this.requestId = requestId;
 }