Exemplo n.º 1
0
        /// <summary>
        /// Cleans up a ConcurrentQueue, marking all items as failed
        /// </summary>
        private void FailQueue(ConcurrentQueue <OpQueueEntry> queue, Exception e)
        {
            OpQueueEntry data;

            while (queue.TryDequeue(out data))
            {
                var t = data.Task;
                if (t != null)
                {
                    t.SetException(e);
                }

                npm.Error();
                CoreEventSource.NodeError(name);
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Cleans up an AdvQueue, marking all items as failed
        /// </summary>
        private void FailQueue(Queue <OpQueueEntry> queue, Exception e)
        {
            foreach (var data in queue)
            {
                var t = data.Task;
                if (t == null)
                {
                    break;
                }
                t.TrySetException(e);

                npm.Error();
                CoreEventSource.NodeError(name);
            }

            queue.Clear();
        }
Exemplo n.º 3
0
        public virtual Task <IOperation> Enqueue(IOperation op)
        {
            var tcs = new TaskCompletionSource <IOperation>();

            npm.NewOp();

            try
            {
                if (IsAlive)
                {
                    writeQueue.Enqueue(new OpQueueEntry(op, tcs));

                    #region Diagnostics
                    npm.EnqueueWriteOp();
                    CoreEventSource.EnqueueWriteOp(name);
                    #endregion
                }
                else
                {
                    tcs.TrySetException(new IOException(endpoint + " is not alive"));

                    #region Diagnostics
                    npm.Error();
                    CoreEventSource.NodeError(name);
                    #endregion
                }
            }
            catch (Exception e)
            {
                tcs.TrySetException(new IOException(endpoint + " enqueue failed. See inner excption for details.", e));

                #region Diagnostics
                npm.Error();
                CoreEventSource.NodeError(name);
                #endregion
            }

            return(tcs.Task);
        }