Esempio n. 1
0
        protected void setCompletedCallback(Ice.AsyncCallback cb)
        {
            lock (this)
            {
                if (cb == null)
                {
                    throw new System.ArgumentException("callback is null");
                }
                if (_completedCallback != null)
                {
                    throw new System.ArgumentException("callback already set");
                }
                _completedCallback = cb;
                if ((state_ & StateDone) == 0)
                {
                    return;
                }
                else if ((getProxy() == null || !getProxy().ice_isTwoway()) && _exception == null)
                {
                    return;
                }
            }

            instance_.clientThreadPool().dispatch(() =>
            {
                try
                {
                    cb(this);
                }
                catch (System.Exception ex)
                {
                    warning(ex);
                }
            }, cachedConnection_);
        }
Esempio n. 2
0
        private void doCheck(bool userThread)
        {
            lock (this)
            {
                Debug.Assert(_useCount > 0);
                if (--_useCount > 0)
                {
                    return;
                }
            }

            Ice.AsyncCallback sentCB = sent(true);
            if (userThread)
            {
                sentSynchronously_ = true;
                if (sentCB != null)
                {
                    invokeSent(sentCB);
                }
            }
            else
            {
                if (sentCB != null)
                {
                    invokeSentAsync(sentCB);
                }
            }
        }
Esempio n. 3
0
        public void flushConnection(Ice.ConnectionI con)
        {
            lock (this)
            {
                ++_useCount;
            }

            try
            {
                Ice.AsyncCallback sentCB = null;
                FlushBatch        flush  = new FlushBatch(this);
                int batchRequestNum      = con.getBatchRequestQueue().swap(flush.getOs());
                if (batchRequestNum == 0)
                {
                    flush.sent();
                }
                else
                {
                    con.sendAsyncRequest(flush, false, false, batchRequestNum, out sentCB);
                }
                Debug.Assert(sentCB == null);
            }
            catch (Ice.LocalException ex)
            {
                doCheck(false);
                throw ex;
            }
        }
Esempio n. 4
0
        public void asyncRequestCanceled(OutgoingAsyncBase outAsync, Ice.LocalException ex)
        {
            lock (this)
            {
                if (_exception != null)
                {
                    return; // The request has been notified of a failure already.
                }

                if (!initialized())
                {
                    LinkedListNode <ProxyOutgoingAsyncBase> p = _requests.First;
                    while (p != null)
                    {
                        if (p.Value == outAsync)
                        {
                            _requests.Remove(p);
                            Ice.AsyncCallback cb = outAsync.completed(ex);
                            if (cb != null)
                            {
                                outAsync.invokeCompletedAsync(cb);
                            }
                            return;
                        }
                        p = p.Next;
                    }
                    Debug.Assert(false); // The request has to be queued if it timed out and we're not initialized yet.
                }
            }
            _connection.asyncRequestCanceled(outAsync, ex);
        }
Esempio n. 5
0
        handleException(int requestId, Ice.Exception ex, bool amd)
        {
            if (requestId == 0)
            {
                return; // Ignore exception for oneway messages.
            }

            OutgoingAsyncBase outAsync;

            Ice.AsyncCallback cb = null;
            lock (this)
            {
                if (_asyncRequests.TryGetValue(requestId, out outAsync))
                {
                    _asyncRequests.Remove(requestId);
                    cb = outAsync.completed(ex);
                }
            }

            if (cb != null)
            {
                if (amd)
                {
                    outAsync.invokeCompletedAsync(cb);
                }
                else
                {
                    outAsync.invokeCompleted(cb);
                }
            }
        }
Esempio n. 6
0
 public CommunicatorFlushBatchCompletionCallback(Ice.Communicator communicator,
                                                 Instance instance,
                                                 string op,
                                                 object cookie,
                                                 Ice.AsyncCallback callback)
     : base(communicator, instance, op, cookie, callback)
 {
 }
Esempio n. 7
0
 public override bool invokeCollocated(CollocatedRequestHandler handler, out Ice.AsyncCallback sentCB)
 {
     if (_batchRequestNum == 0)
     {
         sentCB = sent();
         return(true);
     }
     return(handler.invokeAsyncRequest(this, _batchRequestNum, false, out sentCB));
 }
Esempio n. 8
0
 public override bool invokeCollocated(CollocatedRequestHandler handler, out Ice.AsyncCallback sentCB)
 {
     // The BasicStream cannot be cached if the proxy is not a twoway or there is an invocation timeout set.
     if (!proxy_.ice_isTwoway() || proxy_.reference__().getInvocationTimeout() != -1)
     {
         // Disable caching by marking the streams as cached!
         state_ |= StateCachedBuffers;
     }
     return(handler.invokeAsyncRequest(this, 0, _synchronous, out sentCB));
 }
Esempio n. 9
0
 public override bool invokeCollocated(CollocatedRequestHandler handler, out Ice.AsyncCallback sentCB)
 {
     sentCB = null;
     Ice.AsyncCallback cb = finished(true);
     if (cb != null)
     {
         invokeCompletedAsync(cb);
     }
     return(true);
 }
Esempio n. 10
0
 public override bool invokeRemote(Ice.ConnectionI con, bool compress, bool resp, out Ice.AsyncCallback sentCB)
 {
     sentCB            = null;
     cachedConnection_ = con;
     Ice.AsyncCallback cb = finished(true);
     if (cb != null)
     {
         invokeCompletedAsync(cb);
     }
     return(true);
 }
Esempio n. 11
0
        protected AsyncResultI(Ice.Communicator communicator,
                               Instance instance,
                               string op,
                               object cookie,
                               Ice.AsyncCallback cb)
        {
            instance_ = instance;
            state_    = 0;

            _communicator      = communicator;
            _operation         = op;
            exception_         = null;
            _cookie            = cookie;
            completedCallback_ = cb;
        }
Esempio n. 12
0
        public void invokeCompletedAsync(Ice.AsyncCallback cb)
        {
            //
            // This is called when it's not safe to call the exception callback synchronously
            // from this thread. Instead the exception callback is called asynchronously from
            // the client thread pool.
            //
            Debug.Assert(cb != null);

            // CommunicatorDestroyedException is the only exception that can propagate directly.
            instance_.clientThreadPool().dispatch(() =>
            {
                invokeCompleted(cb);
            }, cachedConnection_);
        }
Esempio n. 13
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);
         }
     }
 }
Esempio n. 14
0
        public Ice.AsyncResult whenSent(Ice.AsyncCallback cb)
        {
            lock (this)
            {
                if (cb == null)
                {
                    throw new System.ArgumentException("callback is null");
                }
                if (sentCallback_ != null)
                {
                    throw new System.ArgumentException("sent callback already set");
                }
                sentCallback_ = cb;
                if ((state_ & StateSent) == 0)
                {
                    return(this);
                }
            }

            if (outgoing_.sentSynchronously())
            {
                try
                {
                    sentCallback_(this);
                }
                catch (System.Exception ex)
                {
                    warning(ex);
                }
            }
            else
            {
                instance_.clientThreadPool().dispatch(() =>
                {
                    try
                    {
                        sentCallback_(this);
                    }
                    catch (System.Exception ex)
                    {
                        warning(ex);
                    }
                }, cachedConnection_);
            }
            return(this);
        }
Esempio n. 15
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);
        }
Esempio n. 16
0
        public void sendResponse(int requestId, Ice.OutputStream os, byte status, bool amd)
        {
            Ice.AsyncCallback cb = null;
            OutgoingAsyncBase outAsync;

            lock (this)
            {
                Debug.Assert(_response);

                if (_traceLevels.protocol >= 1)
                {
                    fillInValue(os, 10, os.size());
                }

                // Adopt the OutputStream's buffer.
                Ice.InputStream iss = new Ice.InputStream(os.instance(), os.getEncoding(), os.getBuffer(), true);

                iss.pos(Protocol.replyHdr.Length + 4);

                if (_traceLevels.protocol >= 1)
                {
                    TraceUtil.traceRecv(iss, _logger, _traceLevels);
                }

                if (_asyncRequests.TryGetValue(requestId, out outAsync))
                {
                    _asyncRequests.Remove(requestId);
                    outAsync.getIs().swap(iss);
                    cb = outAsync.completed();
                }
            }

            if (cb != null)
            {
                if (amd)
                {
                    outAsync.invokeCompletedAsync(cb);
                }
                else
                {
                    outAsync.invokeCompleted(cb);
                }
            }
            _adapter.decDirectCount();
        }
Esempio n. 17
0
 public virtual void abort(Ice.Exception ex)
 {
     Debug.Assert(childObserver_ == null);
     Ice.AsyncCallback cb = finished(ex);
     if (cb != null)
     {
         invokeCompletedAsync(cb);
     }
     else if (ex is Ice.CommunicatorDestroyedException)
     {
         //
         // If it's a communicator destroyed exception, don't swallow
         // it but instead notify the user thread. Even if no callback
         // was provided.
         //
         throw ex;
     }
 }
Esempio n. 18
0
 public bool flushAsyncBatchRequests(BatchOutgoingAsync @out, out Ice.AsyncCallback sentCallback)
 {
     _m.Lock();
     try
     {
         if (!initialized())
         {
             _requests.AddLast(new Request(@out));
             sentCallback = null;
             return(false);
         }
     }
     finally
     {
         _m.Unlock();
     }
     return(_connection.flushAsyncBatchRequests(@out, out sentCallback));
 }
Esempio n. 19
0
        public void invokeCompleted(Ice.AsyncCallback cb)
        {
            Debug.Assert(cb != null);
            try
            {
                cb(this);
            }
            catch (System.Exception ex)
            {
                warning(ex);
            }

            if (observer_ != null)
            {
                observer_.detach();
                observer_ = null;
            }
        }
Esempio n. 20
0
        public bool sendAsyncRequest(ProxyOutgoingAsyncBase outAsync, out Ice.AsyncCallback sentCallback)
        {
            lock (this)
            {
                if (!_initialized)
                {
                    outAsync.cancelable(this); // This will throw if the request is canceled
                }

                if (!initialized())
                {
                    _requests.AddLast(outAsync);
                    sentCallback = null;
                    return(false);
                }
            }
            return(outAsync.invokeRemote(_connection, _compress, _response, out sentCallback));
        }
Esempio n. 21
0
 public bool sendAsyncRequest(OutgoingAsync @out, out Ice.AsyncCallback sentCallback)
 {
     _m.Lock();
     try
     {
         if (!initialized())
         {
             _requests.AddLast(new Request(@out));
             sentCallback = null;
             return(false);
         }
     }
     finally
     {
         _m.Unlock();
     }
     return(_connection.sendAsyncRequest(@out, _compress, _response, out sentCallback));
 }
Esempio n. 22
0
        public void invoke()
        {
            try
            {
                int batchRequestNum = _connection.getBatchRequestQueue().swap(os_);

                bool isSent = false;
                Ice.AsyncCallback sentCB;
                if (batchRequestNum == 0)
                {
                    isSent = true;
                    sentCB = sent();
                }
                else
                {
                    isSent = _connection.sendAsyncRequest(this, false, false, batchRequestNum, out sentCB);
                }

                if (isSent)
                {
                    sentSynchronously_ = true;
                    if (sentCB != null)
                    {
                        invokeSent(sentCB);
                    }
                }
            }
            catch (RetryException ex)
            {
                Ice.AsyncCallback cb = completed(ex.get());
                if (cb != null)
                {
                    invokeCompletedAsync(cb);
                }
            }
            catch (Ice.Exception ex)
            {
                Ice.AsyncCallback cb = completed(ex);
                if (cb != null)
                {
                    invokeCompletedAsync(cb);
                }
            }
        }
Esempio n. 23
0
 public void invokeSentAsync(Ice.AsyncCallback cb)
 {
     //
     // This is called when it's not safe to call the exception callback synchronously
     // from this thread. Instead the exception callback is called asynchronously from
     // the client thread pool.
     //
     Debug.Assert(cb != null);
     try
     {
         instance_.clientThreadPool().dispatch(() =>
         {
             invokeSent(cb);
         }, cachedConnection_);
     }
     catch (Ice.CommunicatorDestroyedException)
     {
     }
 }
Esempio n. 24
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;
                 }
             }
         }
     }
 }
Esempio n. 25
0
        public void invokeSent(Ice.AsyncCallback cb)
        {
            Debug.Assert(cb != null);
            try
            {
                cb(this);
            }
            catch (System.Exception ex)
            {
                warning(ex);
            }

            if (observer_ != null)
            {
                Ice.ObjectPrx proxy = getProxy();
                if (proxy == null || !proxy.ice_isTwoway())
                {
                    observer_.detach();
                    observer_ = null;
                }
            }
        }
Esempio n. 26
0
 public void retryException(Ice.Exception ex)
 {
     try
     {
         //
         // It's important to let the retry queue do the retry. This is
         // called from the connect request handler and the retry might
         // require could end up waiting for the flush of the
         // connection to be done.
         //
         proxy_.updateRequestHandler__(handler_, null); // Clear request handler and always retry.
         instance_.retryQueue().add(this, 0);
     }
     catch (Ice.Exception exc)
     {
         Ice.AsyncCallback cb = completed(exc);
         if (cb != null)
         {
             invokeCompletedAsync(cb);
         }
     }
 }
Esempio n. 27
0
        public void sendResponse(int requestId, BasicStream os, byte status, bool amd)
        {
            Ice.AsyncCallback cb = null;
            OutgoingAsyncBase outAsync;

            lock (this)
            {
                Debug.Assert(_response);

                os.pos(Protocol.replyHdr.Length + 4);

                if (_traceLevels.protocol >= 1)
                {
                    fillInValue(os, 10, os.size());
                    TraceUtil.traceRecv(os, _logger, _traceLevels);
                }

                if (_asyncRequests.TryGetValue(requestId, out outAsync))
                {
                    _asyncRequests.Remove(requestId);
                    outAsync.getIs().swap(os);
                    cb = outAsync.completed();
                }
            }

            if (cb != null)
            {
                if (amd)
                {
                    outAsync.invokeCompletedAsync(cb);
                }
                else
                {
                    outAsync.invokeCompleted(cb);
                }
            }
            _adapter.decDirectCount();
        }
Esempio n. 28
0
        public void setException(Ice.LocalException ex)
        {
            lock (this)
            {
                Debug.Assert(!_initialized && _exception == null);
                _exception = ex;
                _proxies.Clear();
                _proxy = null; // Break cyclic reference count.

                //
                // NOTE: remove the request handler *before* notifying the
                // requests that the connection failed. It's important to ensure
                // that future invocations will obtain a new connect request
                // handler once invocations are notified.
                //
                try
                {
                    _reference.getInstance().requestHandlerFactory().removeRequestHandler(_reference, this);
                }
                catch (Ice.CommunicatorDestroyedException)
                {
                    // Ignore
                }

                foreach (ProxyOutgoingAsyncBase outAsync in _requests)
                {
                    Ice.AsyncCallback cb = outAsync.completed(_exception);
                    if (cb != null)
                    {
                        outAsync.invokeCompletedAsync(cb);
                    }
                }
                _requests.Clear();
                System.Threading.Monitor.PulseAll(this);
            }
        }
Esempio n. 29
0
            internal bool sent(ConnectionI connection, bool notify)
            {
                isSent = true; // The message is sent.

                if(@out != null)
                {
                    @out.sent(notify); // true = notify the waiting thread that the request was sent.
                    return false;
                }
                else if(outAsync != null)
                {
                    sentCallback = outAsync.sent__(connection);
                    return sentCallback != null;
                }
                else
                {
                    return false;
                }
            }
Esempio n. 30
0
 internal bool sent()
 {
     if(outAsync != null)
     {
         sentCallback = outAsync.sent();
     }
     return sentCallback != null || receivedReply;
 }
 private Ice.AsyncResult <NProgDistributed.TheIce.Callback_IMessageService_Send> begin_Send(NProgDistributed.TheIce.MessageDto message, _System.Collections.Generic.Dictionary <string, string> ctx__, bool explicitContext__, Ice.AsyncCallback cb__, object cookie__)
 {
     checkAsyncTwowayOnly__(__Send_name);
     IceInternal.TwowayOutgoingAsync <NProgDistributed.TheIce.Callback_IMessageService_Send> result__ = new IceInternal.TwowayOutgoingAsync <NProgDistributed.TheIce.Callback_IMessageService_Send>(this, __Send_name, Send_completed__, cookie__);
     if (cb__ != null)
     {
         result__.whenCompletedWithAsyncCallback(cb__);
     }
     try
     {
         result__.prepare__(__Send_name, Ice.OperationMode.Normal, ctx__, explicitContext__);
         IceInternal.BasicStream os__ = result__.startWriteParams__(Ice.FormatType.DefaultFormat);
         os__.writeObject(message);
         os__.writePendingObjects();
         result__.endWriteParams__();
         result__.send__(true);
     }
     catch (Ice.LocalException ex__)
     {
         result__.exceptionAsync__(ex__);
     }
     return(result__);
 }
 public Ice.AsyncResult begin_Send(NProgDistributed.TheIce.MessageDto message, _System.Collections.Generic.Dictionary <string, string> ctx__, Ice.AsyncCallback cb__, object cookie__)
 {
     return(begin_Send(message, ctx__, true, cb__, cookie__));
 }
Esempio n. 33
0
        protected AsyncResultI(Ice.Communicator communicator,
                               Instance instance,
                               string op,
                               object cookie,
                               Ice.AsyncCallback cb)
        {
            instance_ = instance;
            state_ = 0;

            _communicator = communicator;
            _operation = op;
            exception_ = null;
            _cookie = cookie;
            completedCallback_ = cb;
        }
Esempio n. 34
0
        public Ice.AsyncResult whenSent(Ice.SentCallback cb)
        {
            lock(this)
            {
                if(cb == null)
                {
                    throw new System.ArgumentException("callback is null");
                }
                if(sentCallback_ != null)
                {
                    throw new System.ArgumentException("sent callback already set");
                }
                sentCallback_ = (Ice.AsyncResult r) =>
                    {
                        cb(r.sentSynchronously());
                    };
                if((state_ & StateSent) == 0)
                {
                    return this;
                }
            }

            if(outgoing_.sentSynchronously())
            {
                try
                {
                    cb(true);
                }
                catch(System.Exception ex)
                {
                    warning(ex);
                }
            }
            else
            {
                instance_.clientThreadPool().dispatch(() =>
                {
                    try
                    {
                        cb(false);
                    }
                    catch(System.Exception ex)
                    {
                        warning(ex);
                    }
                }, cachedConnection_);
            }
            return this;
        }
Esempio n. 35
0
        protected void setCompletedCallback(Ice.AsyncCallback cb)
        {
            lock(this)
            {
                if(cb == null)
                {
                    throw new System.ArgumentException("callback is null");
                }
                if(completedCallback_ != null)
                {
                    throw new System.ArgumentException("callback already set");
                }
                completedCallback_ = cb;
                if((state_ & StateDone) == 0)
                {
                    return;
                }
                else if((getProxy() == null || !getProxy().ice_isTwoway()) && exception_ == null)
                {
                    return;
                }
            }

            instance_.clientThreadPool().dispatch(() =>
            {
                try
                {
                    try
                    {
                        cb(this);
                    }
                    catch(System.AggregateException ex)
                    {
                        throw ex.InnerException;
                    }
                }
                catch(System.Exception ex)
                {
                    warning(ex);
                }
            }, cachedConnection_);
        }