Exemplo n.º 1
0
        public override async Task OnActivateAsync()
        {
            var dITask = DependencyInjection();

            if (!dITask.IsCompletedSuccessfully)
            {
                await dITask;
            }
            try
            {
                if (ArchiveOptions.On)
                {
                    //加载最后一条归档
                    LastArchive = await ArchiveStorage.GetLatestBrief(GrainId);
                }
                await ReadSnapshotAsync();

                if (FullyActive)
                {
                    await RecoveryFromStorage();
                }
                if (Logger.IsEnabled(LogLevel.Trace))
                {
                    Logger.LogTrace("Activation completed: {0}->{1}", GrainType.FullName, Serializer.Serialize(Snapshot));
                }
            }
            catch (Exception ex)
            {
                Logger.LogCritical(ex, "Activation failed: {0}->{1}", GrainType.FullName, GrainId.ToString());
                throw;
            }
        }
Exemplo n.º 2
0
        public override async Task OnActivateAsync()
        {
            var dITask = DependencyInjection();

            if (!dITask.IsCompletedSuccessfully)
            {
                await dITask;
            }
            try
            {
                if (ArchiveOptions.On)
                {
                    //加载最后一条归档
                    LastArchive = await ArchiveStorage.GetLatestBrief(GrainId);
                }
                await ReadSnapshotAsync();

                if (FullyActive)
                {
                    while (true)
                    {
                        var eventList = await EventStorage.GetList(GrainId, Snapshot.Base.StartTimestamp, Snapshot.Base.Version + 1, Snapshot.Base.Version + NumberOfEventsPerRead);

                        var task = Tell(eventList);
                        if (!task.IsCompletedSuccessfully)
                        {
                            await task;
                        }
                        if (eventList.Count < NumberOfEventsPerRead)
                        {
                            break;
                        }
                    }
                    ;
                }
                if (Logger.IsEnabled(LogLevel.Trace))
                {
                    Logger.LogTrace("Activation completed: {0}->{1}", GrainType.FullName, Serializer.Serialize(Snapshot));
                }
            }
            catch (Exception ex)
            {
                Logger.LogCritical(ex, "Activation failed: {0}->{1}", GrainType.FullName, GrainId.ToString());
                throw;
            }
        }
Exemplo n.º 3
0
 private ArchiveBrief CombineArchiveInfo(ArchiveBrief main, ArchiveBrief merge)
 {
     if (merge.StartTimestamp < main.StartTimestamp)
     {
         main.StartTimestamp = merge.StartTimestamp;
     }
     if (merge.StartVersion < main.StartVersion)
     {
         main.StartVersion = merge.StartVersion;
     }
     if (merge.EndTimestamp > main.EndTimestamp)
     {
         main.EndTimestamp = merge.EndTimestamp;
     }
     if (merge.EndVersion > main.EndVersion)
     {
         main.EndVersion = merge.EndVersion;
     }
     return(main);
 }
Exemplo n.º 4
0
        public override async Task OnActivateAsync()
        {
            if (Logger.IsEnabled(LogLevel.Trace))
            {
                Logger.LogTrace(LogEventIds.GrainActivateId, "Start activation followgrain with id = {0}", GrainId.ToString());
            }
            var dITask = DependencyInjection();

            if (!dITask.IsCompletedSuccessfully)
            {
                await dITask;
            }
            try
            {
                if (ArchiveOptions.On)
                {
                    //加载最后一条归档
                    LastArchive = await ArchiveStorage.GetLatestBrief(GrainId);
                }
                await ReadSnapshotAsync();

                if (FullyActive)
                {
                    await FullActive();
                }
                if (Logger.IsEnabled(LogLevel.Trace))
                {
                    Logger.LogTrace(LogEventIds.GrainActivateId, "Followgrain activation completed with id = {0}", GrainId.ToString());
                }
            }
            catch (Exception ex)
            {
                if (Logger.IsEnabled(LogLevel.Critical))
                {
                    Logger.LogCritical(LogEventIds.FollowGrainActivateId, ex, "Followgrain activation failed with Id = {0}", GrainId.ToString());
                }
                throw;
            }
        }