예제 #1
0
        /// <summary>
        /// Clear the saga timeout associated with the specified <paramref name="sagaReference"/> (thread-safe).
        /// </summary>
        /// <param name="sagaReference">The saga reference to clear a scheduled timeout.</param>
        public void ClearTimeout(SagaReference sagaReference)
        {
            Log.Trace("Clearing saga timeout for {0}", sagaReference);

            lock (syncLock)
            {
                ClearTimeoutInternal(sagaReference);
            }

            Log.Trace("Saga timeout cleared for {0}", sagaReference);
        }
        /// <summary>
        /// Removes all saga timeouts associated with the specified <paramref name="sagaReference"/>.
        /// </summary>
        /// <param name="sagaReference">The saga reference for which all saga timeouts are to be removed.</param>
        public Boolean Remove(SagaReference sagaReference)
        {
            List <SagaTimeoutNode> sagaTimeouts;

            if (!scheduledSagaTimeouts.TryGetValue(sagaReference, out sagaTimeouts))
            {
                return(false);
            }

            scheduledSagaTimeouts.Remove(sagaReference);
            foreach (var sagaTimeout in sagaTimeouts)
            {
                sortedSagaTimeouts.Remove(sagaTimeout);
            }

            return(sagaTimeouts.Count > 0);
        }
        /// <summary>
        /// Adds a <see cref="SagaTimeout"/> to the sorted collection.
        /// </summary>
        /// <param name="sagaTimeout"></param>
        public void Add(SagaTimeout sagaTimeout)
        {
            SagaTimeoutNode        node          = sortedSagaTimeouts.First;
            SagaReference          sagaReference = sagaTimeout;
            List <SagaTimeoutNode> timeouts;

            if (!scheduledSagaTimeouts.TryGetValue(sagaReference, out timeouts))
            {
                scheduledSagaTimeouts[sagaReference] = timeouts = new List <SagaTimeoutNode>();
            }

            while (node != null && node.Value.Timeout <= sagaTimeout.Timeout)
            {
                node = node.Next;
            }

            timeouts.Add(node == null ? sortedSagaTimeouts.AddLast(sagaTimeout) : sortedSagaTimeouts.AddBefore(node, sagaTimeout));
        }
        private Boolean Remove(SagaTimeout sagaTimeout, Boolean removeAll)
        {
            Boolean result = false;
            List <SagaTimeoutNode> sagaTimeouts;
            SagaReference          sagaReference = sagaTimeout;

            if (!scheduledSagaTimeouts.TryGetValue(sagaReference, out sagaTimeouts))
            {
                return(false);
            }

            for (var i = sagaTimeouts.Count - 1; i >= 0; i--)
            {
                var node = sagaTimeouts[i];
                if (!sagaTimeout.Equals(node.Value))
                {
                    continue;
                }

                sortedSagaTimeouts.Remove(node);
                sagaTimeouts.RemoveAt(i);
                result = true;

                if (!removeAll)
                {
                    break;
                }
            }

            if (sagaTimeouts.Count == 0)
            {
                scheduledSagaTimeouts.Remove(sagaReference);
            }

            return(result);
        }
 /// <summary>
 /// Determines whether a <see cref="SagaReference"/> has one or more saga timeouts in the <see cref="SagaTimeoutCollection"/>.
 /// </summary>
 /// <param name="sagaReference">The <see cref="SagaReference"/> to locate in the <see cref="SagaTimeoutCollection"/>.</param>
 public Boolean Contains(SagaReference sagaReference)
 {
     return(scheduledSagaTimeouts.ContainsKey(sagaReference));
 }
예제 #6
0
 /// <summary>
 /// Initializes a new instance of <see cref="SagaLock"/>.
 /// </summary>
 /// <param name="sagaReference">The saga reference associated with this saga lock instance.</param>
 public SagaLock(SagaReference sagaReference)
 {
     this.sagaReference = sagaReference;
 }
예제 #7
0
 /// <summary>
 /// Clear the saga timeout associated with the specified <paramref name="sagaReference"/>.
 /// </summary>
 /// <param name="sagaReference">The saga reference to clear a scheduled timeout.</param>
 private void ClearTimeoutInternal(SagaReference sagaReference)
 {
     sagaTimeouts.Remove(sagaReference);
 }