示例#1
0
        public override async Task OnActivateAsync()
        {
            await ReadSnapshotAsync();

            while (true)
            {
                var eventList = await EventStorage.GetListAsync(this.GrainId, this.State.Version, this.State.Version + 1000, this.State.VersionTime);

                foreach (var @event in eventList)
                {
                    this.State.IncrementDoingVersion();//标记将要处理的Version
                    EventHandle.Apply(this.State, @event.Event);
                    if ([email protected])
                    {
                        using (var ms = new PooledMemoryStream())
                        {
                            Serializer.Serialize(ms, @event.Event);
                            await AfterEventSavedHandle(@event.Event, ms.ToArray());
                        }
                    }
                    this.State.UpdateVersion(@event.Event);//更新处理完成的Version
                }
                if (eventList.Count < 1000)
                {
                    break;
                }
            }
            ;
        }
示例#2
0
文件: ESGrain.cs 项目: zhaoyingju/Ray
        public override async Task OnActivateAsync()
        {
            await ReadSnapshotAsync();

            while (true)
            {
                var eventList = await EventStorage.GetListAsync(this.GrainId, this.State.Version, this.State.Version + 1000, this.State.VersionTime);

                foreach (var @event in eventList)
                {
                    @event.Event.Apply(this.State);
                    if ([email protected])
                    {
                        using (var ms = new MemoryStream())
                        {
                            Serializer.Serialize(ms, @event.Event);
                            await EventInsertAfterHandle(@event.Event, ms.ToArray());
                        }
                    }
                }
                if (eventList.Count < 1000)
                {
                    break;
                }
            }
            ;
        }
示例#3
0
 public async Task Tell(W message)
 {
     var type = MessageTypeMapping.GetType(message.TypeCode);
     if (type != null)
     {
         using (var ems = new MemoryStream(message.BinaryBytes))
         {
             var @event = Serializer.Deserialize(type, ems) as IEventBase<K>;
             if (@event != null)
             {
                 if (@event.Version == this.State.Version + 1)
                 {
                     await OnExecution(@event);
                     this.State.IncrementDoingVersion();//标记将要处理的Version
                     EventHandle.Apply(this.State, @event);
                     this.State.UpdateVersion(@event);//更新处理完成的Version
                     await OnExecuted(@event);
                     await SaveSnapshotAsync();
                 }
                 else if (@event.Version > this.State.Version)
                 {
                     var eventList = await EventStorage.GetListAsync(this.GrainId, this.State.Version, @event.Version);
                     foreach (var item in eventList)
                     {
                         await OnExecution(@event);
                         this.State.IncrementDoingVersion();//标记将要处理的Version
                         EventHandle.Apply(this.State, @event);
                         this.State.UpdateVersion(@event);//更新处理完成的Version
                         await OnExecuted(@event);
                         await SaveSnapshotAsync();
                     }
                 }
                 if (@event.Version == this.State.Version + 1)
                 {
                     await OnExecution(@event);
                     this.State.IncrementDoingVersion();//标记将要处理的Version
                     EventHandle.Apply(this.State, @event);
                     this.State.UpdateVersion(@event);//更新处理完成的Version
                     await OnExecuted(@event);
                     await SaveSnapshotAsync();
                 }
                 if (@event.Version > this.State.Version)
                 {
                     throw new Exception($"Event version of the error,Type={ThisType.FullName},StateId={this.GrainId.ToString()},StateVersion={this.State.Version},EventVersion={@event.Version}");
                 }
             }
         }
     }
 }
示例#4
0
        public async Task Tell(W message)
        {
            var type = MessageTypeMapping.GetType(message.TypeCode);

            if (type != null)
            {
                using (var ems = new MemoryStream(message.BinaryBytes))
                {
                    var @event = Serializer.Deserialize(type, ems) as IEventBase <K>;
                    if (@event != null)
                    {
                        if (@event.Version == this.State.Version + 1)
                        {
                            await OnExecution(@event);

                            @event.Apply(State);
                            await OnExecuted(@event);
                            await SaveSnapshotAsync();
                        }
                        else if (@event.Version > this.State.Version)
                        {
                            var eventList = await EventStorage.GetListAsync(this.GrainId, this.State.Version, @event.Version);

                            foreach (var item in eventList)
                            {
                                await OnExecution(@event);

                                item.Event.Apply(State);
                                await OnExecuted(@event);
                                await SaveSnapshotAsync();
                            }
                        }
                        if (@event.Version == this.State.Version + 1)
                        {
                            await OnExecution(@event);

                            @event.Apply(State);
                            await OnExecuted(@event);
                            await SaveSnapshotAsync();
                        }
                        if (@event.Version > this.State.Version)
                        {
                            throw new Exception($"ESReplicaGrain出现严重BUG,Type={ThisType.FullName},StateId={this.GrainId.ToString()},StateVersion={this.State.Version},EventVersion={@event.Version}");
                        }
                    }
                }
            }
        }
示例#5
0
 private async Task Active()
 {
     await ReadSnapshotAsync();
     var storageContainer = ServiceProvider.GetService<IStorageContainer>();
     while (true)
     {
         var eventList = await EventStorage.GetListAsync(this.GrainId, this.State.Version, this.State.Version + 1000, this.State.VersionTime);
         foreach (var @event in eventList)
         {
             this.State.IncrementDoingVersion();//标记将要处理的Version
             EventHandle.Apply(this.State, @event.Event);
             this.State.UpdateVersion(@event.Event);//更新处理完成的Version
         }
         if (eventList.Count < 1000) break;
     };
 }
示例#6
0
        public async Task Tell(W msg)
        {
            var type = MessageTypeMapping.GetType(msg.TypeCode);

            if (type != null)
            {
                using (var ems = new MemoryStream(msg.BinaryBytes))
                {
                    var message = Serializer.Deserialize(type, ems);
                    if (message != null)
                    {
                        if (!outsideMsgTypecodeList.Contains(msg.TypeCode))
                        {
                            if (message is IEvent @event)
                            {
                                if (@event.Version == this.State.Version + 1)
                                {
                                    await EventExcute(@event);
                                }
                                else if (@event.Version > this.State.Version)
                                {
                                    while (true)
                                    {
                                        var eventList = await EventStorage.GetListAsync(this.GrainId, this.State.Version, this.State.Version + 1000, this.State.VersionTime);

                                        foreach (var item in eventList)
                                        {
                                            await EventExcute(item.Event);
                                        }
                                        if (this.State.Version >= @event.Version)
                                        {
                                            break;
                                        }
                                    }
                                    ;
                                }
                            }
                        }
                        else if (message is IMessage value)
                        {
                            await NotEventMsgExcute(value);
                        }
                    }
                }
            }
        }
示例#7
0
        private async Task Active()
        {
            await ReadSnapshotAsync();

            var storageContainer = ServiceProvider.GetService <IStorageContainer>();

            while (true)
            {
                var eventList = await EventStorage.GetListAsync(this.GrainId, this.State.Version, this.State.Version + 1000, this.State.VersionTime);

                foreach (var @event in eventList)
                {
                    @event.Event.Apply(this.State);
                }
                if (eventList.Count < 1000)
                {
                    break;
                }
            }
            ;
        }
示例#8
0
        public override async Task OnActivateAsync()
        {
            await ReadSnapshotAsync();

            while (true)
            {
                var eventList = await EventStorage.GetListAsync(GrainId, State.Version, State.Version + 1000, State.VersionTime);

                foreach (var @event in eventList)
                {
                    State.IncrementDoingVersion();//标记将要处理的Version
                    await OnEventDelivered(@event);

                    State.UpdateVersion(@event);//更新处理完成的Version
                }
                await SaveSnapshotAsync();

                if (eventList.Count < 1000)
                {
                    break;
                }
            }
            ;
        }
示例#9
0
        public async Task Tell(W message)
        {
            var type = MessageTypeMapper.GetType(message.TypeCode);

            if (type != null)
            {
                using (var ems = new MemoryStream(message.BinaryBytes))
                {
                    if (Serializer.Deserialize(type, ems) is IEventBase <K> @event)
                    {
                        if (@event.Version == State.Version + 1)
                        {
                            State.IncrementDoingVersion();//标记将要处理的Version
                            try
                            {
                                await OnEventDelivered(@event);

                                State.UpdateVersion(@event);//更新处理完成的Version
                            }
                            catch (Exception e)
                            {
                                State.DoingVersion = State.Version;//标记将要处理的Version
                                ExceptionDispatchInfo.Capture(e).Throw();
                            }
                            await OnExecuted(@event);
                            await SaveSnapshotAsync();
                        }
                        else if (@event.Version > State.Version)
                        {
                            var eventList = await EventStorage.GetListAsync(GrainId, State.Version, @event.Version, State.VersionTime);

                            foreach (var item in eventList)
                            {
                                State.IncrementDoingVersion();//标记将要处理的Version
                                try
                                {
                                    await OnEventDelivered(item);

                                    State.UpdateVersion(item);//更新处理完成的Version
                                }
                                catch (Exception e)
                                {
                                    State.DoingVersion = State.Version;//标记将要处理的Version
                                    ExceptionDispatchInfo.Capture(e).Throw();
                                }
                                await OnExecuted(@event);
                                await SaveSnapshotAsync();
                            }
                        }
                        if (@event.Version == State.Version + 1)
                        {
                            State.IncrementDoingVersion();//标记将要处理的Version
                            try
                            {
                                await OnEventDelivered(@event);

                                State.UpdateVersion(@event);//更新处理完成的Version
                            }
                            catch (Exception e)
                            {
                                State.DoingVersion = State.Version;//标记将要处理的Version
                                ExceptionDispatchInfo.Capture(e).Throw();
                            }
                            await OnExecuted(@event);
                            await SaveSnapshotAsync();
                        }
                        if (@event.Version > State.Version)
                        {
                            throw new Exception($"Event version of the error,Type={GetType().FullName},StateId={this.GrainId.ToString()},StateVersion={State.Version},EventVersion={@event.Version}");
                        }
                    }
                }
            }
        }