Exemple #1
0
        public virtual Task <IOperation> Enqueue(IOperation op)
        {
            var tcs = new TaskCompletionSource <IOperation>();

            counterItemCount.Increment();

            if (IsAlive)
            {
                writeQueue.Enqueue(new Data {
                    Op = op, Task = tcs
                });
                counterEnqueuePerSec.Increment();
                counterWriteQueue.Increment();

                if (trace.IsEnabled())
                {
                    trace.EnqueueWriteOp(name);
                }
            }
            else
            {
                counterErrorPerSec.Increment();
                tcs.SetException(new IOException(endpoint + " is not alive"));
            }

            return(tcs.Task);
        }
Exemple #2
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);
        }