Exemplo n.º 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;
                }
            }
            ;
        }
Exemplo n.º 2
0
        public override async Task OnActivateAsync()
        {
            Logger = ServiceProvider.GetService <ILogger <ESGrain <K, S, W> > >();
            await ReadSnapshotAsync();

            while (true)
            {
                var eventList = await(await GetEventStorage()).GetListAsync(GrainId, State.Version, State.Version + EventNumberPerRead, State.VersionTime);
                foreach (var @event in eventList)
                {
                    State.IncrementDoingVersion(); //标记将要处理的Version
                    EventHandle.Apply(State, @event);
                    State.UpdateVersion(@event);   //更新处理完成的Version
                }
                if (eventList.Count < EventNumberPerRead)
                {
                    break;
                }
            }
            ;
        }