Exemplo n.º 1
0
 private void OnSagaTimedOut(TimeoutData timeoutData)
 {
     if (SagaTimedOut != null)
     {
         SagaTimedOut(null, timeoutData);
     }
 }
Exemplo n.º 2
0
        void IPersistTimeouts.Add(TimeoutData timeout)
        {
            var msg = new Message
            {
                Body  = timeout,
                Label = timeout.SagaId.ToString()
            };

            storageQueue.Send(msg, MessageQueueTransactionType.Automatic);

            lock (sagaToMessageIdLookup)
                sagaToMessageIdLookup[timeout.SagaId] = msg.Id;
        }
Exemplo n.º 3
0
        void IManageTimeouts.PushTimeout(TimeoutData timeout)
        {
            lock (data)
            {
                if (!data.ContainsKey(timeout.Time))
                {
                    data[timeout.Time] = new List <TimeoutData>();
                }

                data[timeout.Time].Add(timeout);
                sagaLookup[timeout.SagaId] = timeout.Time;
            }
        }
Exemplo n.º 4
0
        void IPersistTimeouts.Add(TimeoutData timeout)
        {
            var msg = new Message
                        {
                            Body = timeout,
                            Label = timeout.SagaId.ToString()
                        };

            storageQueue.Send(msg, MessageQueueTransactionType.Automatic);

            lock (sagaToMessageIdLookup)
                sagaToMessageIdLookup[timeout.SagaId] = msg.Id;
        }
Exemplo n.º 5
0
        void IPersistTimeouts.Add(TimeoutData timeout)
        {
            string stateAddress = Serialize(timeout.State);

            context.AddObject(ServiceContext.TimeoutDataEntityTableName,
                                  new TimeoutDataEntity(stateAddress, "TimeoutData")
                                      {
                                          Destination = timeout.Destination.ToString(),
                                          SagaId = timeout.SagaId,
                                          StateAddress = stateAddress,
                                          Time = timeout.Time
                                      });
            context.SaveChanges();
        }
Exemplo n.º 6
0
        void IPersistTimeouts.Add(TimeoutData timeout)
        {
            var stateAddress = Serialize(timeout.State, Hash(timeout));

            context.AttachTo(ServiceContext.TimeoutDataEntityTableName,
                                  new TimeoutDataEntity("TimeoutData", stateAddress)
                                      {
                                          Destination = timeout.Destination.ToString(),
                                          SagaId = timeout.SagaId,
                                          StateAddress = stateAddress,
                                          Time = timeout.Time
                                      });
            context.SaveChanges(SaveChangesOptions.ReplaceOnUpdate);
        }
Exemplo n.º 7
0
        public bool CanSend(TimeoutData data)
        {
            var hash = Hash(data);
            var result = (from c in context.TimeoutData
                          where c.RowKey == hash
                          select c).SingleOrDefault();

            if (result == null) return false;

            var leaseBlob = container.GetBlockBlobReference(result.StateAddress);

            using (var lease = new AutoRenewLease(leaseBlob))
            {
                return lease.HasLease;
            }
        }
Exemplo n.º 8
0
        public void Handle(TimeoutMessage message)
        {
            if (message.ClearTimeout)
            {
                Manager.ClearTimeout(message.SagaId);
                Persister.Remove(message.SagaId);
            }
            else
            {
                var data = new TimeoutData
                {
                    Destination = Bus.CurrentMessageContext.ReturnAddress,
                    SagaId      = message.SagaId,
                    State       = message.State,
                    Time        = message.Expires
                };

                Manager.PushTimeout(data);
                Persister.Add(data);
            }

            Bus.DoNotContinueDispatchingCurrentMessageToHandlers();
        }
Exemplo n.º 9
0
        private string Hash(TimeoutData timeout)
        {
            var s = timeout.SagaId + timeout.Destination + timeout.Time.Ticks;
            var sha1 = SHA1.Create();
            var bytes = sha1.ComputeHash(Encoding.UTF8.GetBytes(s));

            var hash = new StringBuilder();
            for (var i = 0; i < bytes.Length; i++)
            {
                hash.Append(bytes[i].ToString("X2"));
            }
            return hash.ToString();
        }
Exemplo n.º 10
0
        void IManageTimeouts.PushTimeout(TimeoutData timeout)
        {
            lock (data)
            {
                if (!data.ContainsKey(timeout.Time))
                    data[timeout.Time] = new List<TimeoutData>();

                data[timeout.Time].Add(timeout);
                sagaLookup[timeout.SagaId] = timeout.Time;
            }
        }
Exemplo n.º 11
0
 private void OnSagaTimedOut(TimeoutData timeoutData)
 {
     if (SagaTimedOut != null)
         SagaTimedOut(null, timeoutData);
 }