Пример #1
0
        public void Retry(WorkerItem item)
        {
            lock (_connectionLock)
            {
                if (_events.TryRemove(item.CorrelationId, out item))
                {
                    var newCorrId = Guid.NewGuid();

                    item.CorrelationId = newCorrId;
                    item.Attempt      += 1;
                    Interlocked.Exchange(ref item.LastUpdatedTicks, DateTime.UtcNow.Ticks);

                    _events.TryAdd(newCorrId, item);

                    _connection.EnqueueSend(_packager(newCorrId, item.Event).AsByteArray());
                }
                else
                {
                    SignalWorkerFailed(null,
                                       string.Format("Worker {0} couldn't remove event '{1}' on retry. Concurrency failure!",
                                                     Name,
                                                     item != null
                                                               ? item.CorrelationId.ToString()
                                                               : "null"));
                }
            }
        }
Пример #2
0
        private void Retry(WorkerItem item)
        {
            lock (_connectionLock)
            {
                if (_items.TryRemove(item.CorrelationId, out item))
                {
                    var newCorrId = Guid.NewGuid();

                    item.CorrelationId = newCorrId;
                    item.Attempt      += 1;
                    Interlocked.Exchange(ref item.LastUpdatedTicks, DateTime.UtcNow.Ticks);

                    if (item.Attempt > 100)
                    {
                        _coordinator.SignalWorkerFailed(error: string.Format("Item's {0} current attempt is {1}!",
                                                                             item,
                                                                             item.Attempt));
                    }

                    _items.TryAdd(newCorrId, item);
                    _connection.EnqueueSend(item.Task.CreateNetworkPackage(newCorrId).AsByteArray());
                }
                else
                {
                    _coordinator.SignalWorkerFailed(null, string.Format("Worker {0} couldn't remove corrid '{1}' on retry. Concurrency failure!",
                                                                        _name,
                                                                        item != null
                                                                            ? item.CorrelationId.ToString()
                                                                            : "null"));
                }
            }
        }
Пример #3
0
        private bool TryRemoveWorkItem(WorkerItem workItem)
        {
            if (!_items.TryRemove(workItem.CorrelationId, out workItem))
            {
                _coordinator.SignalWorkerFailed(null, string.Format("Worker {0} couldn't remove corrid '{1}'. Concurrency failure!",
                                                                    _name,
                                                                    workItem.CorrelationId));
                return(false);
            }

            Interlocked.Decrement(ref _inProgressCount);
            return(true);
        }
Пример #4
0
 public bool TryRemoveWorkItem(WorkerItem workItem)
 {
     if (!_events.TryRemove(workItem.CorrelationId, out workItem))
     {
         SignalWorkerFailed(
             error: string.Format("Worker {0} couldn't remove event '{1}'. Concurrency failure!",
                                  Name,
                                  workItem.Event.Event.EventId));
         return(false);
     }
     Interlocked.Decrement(ref _inProgressCount);
     return(true);
 }
Пример #5
0
        public void NotifyItemProcessed(WorkerItem item)
        {
            switch (_role)
            {
            case WorkerRole.Writer:
                Interlocked.Increment(ref _totalProcessedEventCount);
                _coordinator.NotifyEventCommitted(item.Event);
                break;

            case WorkerRole.Verifier:
                Interlocked.Increment(ref _totalProcessedEventCount);
                _coordinator.NotifyEventVerified(item.Event);
                break;

            default:
                throw new ArgumentOutOfRangeException();
            }
        }
Пример #6
0
 private void NotifyItemProcessed(WorkerItem item)
 {
     Interlocked.Increment(ref _totalProcessedEventCount);
     _coordinator.Complete(item.Task);
 }
Пример #7
0
 public void NotifyItemProcessed(WorkerItem item)
 {
     switch (_role)
     {
         case WorkerRole.Writer:
             Interlocked.Increment(ref _totalProcessedEventCount);
             _coordinator.NotifyEventCommitted(item.Event);
             break;
         case WorkerRole.Verifier:
             Interlocked.Increment(ref _totalProcessedEventCount);
             _coordinator.NotifyEventVerified(item.Event);
             break;
         default:
             throw new ArgumentOutOfRangeException();
     }
 }
Пример #8
0
        public void Retry(WorkerItem item)
        {
            lock (_connectionLock)
            {
                if (_events.TryRemove(item.CorrelationId, out item))
                {
                    var newCorrId = Guid.NewGuid();

                    item.CorrelationId = newCorrId;
                    item.Attempt += 1;
                    Interlocked.Exchange(ref item.LastUpdatedTicks, DateTime.UtcNow.Ticks);

                    _events.TryAdd(newCorrId, item);

                    _connection.EnqueueSend(_packager(newCorrId, item.Event).AsByteArray());
                }
                else
                    SignalWorkerFailed(null,
                                       string.Format("Worker {0} couldn't remove event '{1}' on retry. Concurrency failure!",
                                                     Name,
                                                     item != null
                                                               ? item.CorrelationId.ToString()
                                                               : "null"));
            }
        }
Пример #9
0
 public bool TryRemoveWorkItem(WorkerItem workItem)
 {
     if (!_events.TryRemove(workItem.CorrelationId, out workItem))
     {
         SignalWorkerFailed(
             error: string.Format("Worker {0} couldn't remove event '{1}'. Concurrency failure!",
                                  Name,
                                  workItem.Event.Event.EventId));
         return false;
     }
     Interlocked.Decrement(ref _inProgressCount);
     return true;
 }
Пример #10
0
 public bool TryGetWorkItem(Guid key, out WorkerItem value)
 {
     return _events.TryGetValue(key, out value);
 }
Пример #11
0
 public bool TryGetWorkItem(Guid key, out WorkerItem value)
 {
     return(_events.TryGetValue(key, out value));
 }
Пример #12
0
 private void NotifyItemProcessed(WorkerItem item)
 {
     Interlocked.Increment(ref _totalProcessedEventCount);
     _coordinator.Complete(item.Task);
 }
Пример #13
0
        private void Retry(WorkerItem item)
        {
            lock (_connectionLock)
            {
                if (_items.TryRemove(item.CorrelationId, out item))
                {
                    var newCorrId = Guid.NewGuid();

                    item.CorrelationId = newCorrId;
                    item.Attempt += 1;
                    Interlocked.Exchange(ref item.LastUpdatedTicks, DateTime.UtcNow.Ticks);

                    if (item.Attempt > 100)
                        _coordinator.SignalWorkerFailed(error: string.Format("Item's {0} current attempt is {1}!", 
                                                                             item, 
                                                                             item.Attempt));

                    _items.TryAdd(newCorrId, item);
                    _connection.EnqueueSend(item.Task.CreateNetworkPackage(newCorrId).AsByteArray());
                }
                else
                    _coordinator.SignalWorkerFailed(null, string.Format("Worker {0} couldn't remove corrid '{1}' on retry. Concurrency failure!",
                                                                        _name,
                                                                        item != null
                                                                            ? item.CorrelationId.ToString()
                                                                            : "null"));
            }
        }
Пример #14
0
        private bool TryRemoveWorkItem(WorkerItem workItem)
        {
            if (!_items.TryRemove(workItem.CorrelationId, out workItem))
            {
                _coordinator.SignalWorkerFailed(null, string.Format("Worker {0} couldn't remove corrid '{1}'. Concurrency failure!",
                                                                    _name,
                                                                    workItem.CorrelationId));
                return false;
            }

            Interlocked.Decrement(ref _inProgressCount);
            return true;
        }