Beispiel #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"));
                }
            }
        }
Beispiel #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"));
                }
            }
        }
Beispiel #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);
        }
Beispiel #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);
 }
Beispiel #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();
            }
        }
Beispiel #6
0
 private void NotifyItemProcessed(WorkerItem item)
 {
     Interlocked.Increment(ref _totalProcessedEventCount);
     _coordinator.Complete(item.Task);
 }
Beispiel #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();
     }
 }
Beispiel #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"));
            }
        }
Beispiel #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;
 }
Beispiel #10
0
 public bool TryGetWorkItem(Guid key, out WorkerItem value)
 {
     return _events.TryGetValue(key, out value);
 }
Beispiel #11
0
 public bool TryGetWorkItem(Guid key, out WorkerItem value)
 {
     return(_events.TryGetValue(key, out value));
 }
Beispiel #12
0
 private void NotifyItemProcessed(WorkerItem item)
 {
     Interlocked.Increment(ref _totalProcessedEventCount);
     _coordinator.Complete(item.Task);
 }
Beispiel #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"));
            }
        }
Beispiel #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;
        }