Beispiel #1
0
        public int InvokeAsyncRequest(ProxyOutgoingAsyncBase outAsync, 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 (!outAsync.IsOneway)
                    {
                        requestId = ++_requestId;
                        _asyncRequests.Add(requestId, outAsync);
                    }

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

            outAsync.AttachCollocatedObserver(_adapter, requestId, outAsync.RequestFrame.Size);
            if (!synchronous || outAsync.IsOneway || _reference.InvocationTimeout > 0)
            {
                // Don't invoke from the user thread if async or invocation timeout is set
                // TODO: why is oneway included in this list?
                _adapter.ThreadPool.Dispatch(
                    () =>
                {
                    if (SentAsync(outAsync))
                    {
                        ValueTask vt = InvokeAllAsync(outAsync.RequestFrame, requestId);
                        // TODO: do something with the value task
                    }
                });
            }
            else // Optimization: directly call invokeAll
            {
                if (SentAsync(outAsync))
                {
                    Debug.Assert(outAsync.RequestFrame != null);
                    ValueTask vt = InvokeAllAsync(outAsync.RequestFrame, requestId);
                    // TODO: do something with the value task
                }
            }
            return(OutgoingAsyncBase.AsyncStatusQueued);
        }
Beispiel #2
0
        public void InvokeAsyncRequest(ProxyOutgoingAsyncBase outAsync, 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 (!outAsync.IsOneway)
                    {
                        requestId = ++_requestId;
                        _asyncRequests.Add(requestId, outAsync);
                    }

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

            outAsync.AttachCollocatedObserver(_adapter, requestId, outAsync.RequestFrame.Size);
            if (_adapter.TaskScheduler != null || !synchronous || outAsync.IsOneway || _reference.InvocationTimeout > 0)
            {
                // Don't invoke from the user thread if async or invocation timeout is set. We also don't dispatch
                // oneway from the user thread to match the non-collocated behavior where the oneway synchronous
                // request returns as soon as it's sent over the transport.
                Task.Factory.StartNew(
                    () =>
                {
                    if (SentAsync(outAsync))
                    {
                        ValueTask vt = InvokeAllAsync(outAsync.RequestFrame, requestId);
                        // TODO: do something with the value task
                    }
                }, default, TaskCreationOptions.None, _adapter.TaskScheduler ?? TaskScheduler.Default);
Beispiel #3
0
        public int SendAsyncRequest(ProxyOutgoingAsyncBase outAsync)
        {
            lock (this)
            {
                if (!_initialized)
                {
                    outAsync.Cancelable(this); // This will throw if the request is canceled
                }

                if (!Initialized())
                {
                    _requests.AddLast(outAsync);
                    return(OutgoingAsyncBase.AsyncStatusQueued);
                }
            }
            Debug.Assert(_connection != null);
            return(outAsync.InvokeRemote(_connection, _compress, _response));
        }
Beispiel #4
0
        public void SendAsyncRequest(ProxyOutgoingAsyncBase outAsync)
        {
            lock (this)
            {
                if (!_initialized)
                {
                    outAsync.Cancelable(this); // This will throw if the request is canceled
                }

                if (!Initialized())
                {
                    _requests.AddLast(outAsync);
                    return;
                }
            }
            Debug.Assert(_connection != null);
            outAsync.InvokeRemote(_connection, _compress, !outAsync.IsOneway);
        }