Пример #1
0
        protected override Task OnPostActorMethodAsync(ActorMethodContext actorMethodContext)
        {
            stopwatch.Stop();

            logger.LogActorMethod <T>(actorMethodContext, DateTime.Now.AddMilliseconds(stopwatch.ElapsedMilliseconds), stopwatch.Elapsed);

            return(Task.CompletedTask);
        }
Пример #2
0
 protected override async Task OnPreActorMethodAsync(ActorMethodContext actorMethodContext)
 {
     if (ActorData != null && ActorData.AutoSave && actorMethodContext.CallType == ActorCallType.ActorInterfaceMethod)
     {
         RecordActorData = ActorData with {
         };
     }
     await Task.CompletedTask;
 }
Пример #3
0
 public static void LogActorMethod <TActor>(this ILogger logger, ActorMethodContext context, DateTime started, TimeSpan duration) where TActor : Actor
 {
     logger.LogInformation(ServiceFabricEvent.ActorMethod,
                           "The {CallType} call to actor {Actor}  method {MethodName} finished in {Duration} ms (started at ({Started}))",
                           context.CallType,
                           typeof(TActor).FullName,
                           context.MethodName,
                           duration.TotalMilliseconds,
                           started);
 }
Пример #4
0
        protected override async Task OnPostActorMethodAsync(ActorMethodContext actorMethodContext)
        {
            var postMethodOrderStatus = await StateManager.GetStateAsync <OrderStatus>(OrderStatusStateName);

            if (_preMethodOrderStatusId != postMethodOrderStatus.Id)
            {
                _logger.LogInformation("Order with Id: {OrderId} has been updated to status {Status}",
                                       OrderId, postMethodOrderStatus.Name);
            }
        }
Пример #5
0
        /// <summary>
        /// actor业务处理后置事件
        /// </summary>
        /// <param name="actorMethodContext"></param>
        /// <returns></returns>
        protected override async Task OnPostActorMethodAsync(ActorMethodContext actorMethodContext)
        {
            if (ActorData != null && ActorData.AutoSave)
            {
                if (actorMethodContext.CallType == ActorCallType.ActorInterfaceMethod)
                {
                    ActorData.UpdateVersion(RecordActorData);//方法调用后强制升级一次版本
                    if (ActorData.IsDelete)
                    {
                        if (await StateManager.TryRemoveStateAsync("ActorData"))
                        {
                            ActorData = null;
                            await UnRegisterTimer();
                        }
                    }
                    else
                    {
                        await StateManager.SetStateAsync("ActorData", ActorData);

                        if (ActorData.ReminderSeconds == 0)
                        {
                            //如果开启自动保存,但是没有设置定期更新时间,则立即触发一次保存
                            await SendEvent <T, ActorStateModel>(ActorData);
                        }
                        else if (!registerTimerState) //当ReminderSeconds>0未注册Timer时,需要重新注册timer
                        {
                            registerTimerState = true;
                            await RegisterTimer(ActorData.ReminderSeconds);
                        }
                    }
                }
                else
                {
                    if (ActorData != null && ActorData.AutoSave)
                    {
                        if (ActorData.CheckVersionChange())
                        {
                            await SendEvent <T, ActorStateModel>(ActorData);
                        }
                    }
                }
            }
            await Task.CompletedTask;
        }
Пример #6
0
 public void ActorMethodPost(Actor actor, ActorMethodContext context)
 {
     if (IsEnabled() &&
         actor.Id != null &&
         actor.ActorService != null &&
         actor.ActorService.Context != null &&
         actor.ActorService.Context.CodePackageActivationContext != null)
     {
         ActorMethodPost(
             actor.GetType().ToString(),
             actor.Id.ToString(),
             actor.ActorService.Context.CodePackageActivationContext.ApplicationTypeName,
             actor.ActorService.Context.CodePackageActivationContext.ApplicationName,
             actor.ActorService.Context.ServiceTypeName,
             actor.ActorService.Context.ServiceName.ToString(),
             actor.ActorService.Context.PartitionId,
             actor.ActorService.Context.ReplicaId,
             actor.ActorService.Context.NodeContext.NodeName,
             context.CallType,
             context.MethodName);
     }
 }
Пример #7
0
 /// <summary>
 /// This method is invoked after an actor method has finished execution.
 /// </summary>
 /// <param name="actorMethodContext"></param>
 /// <returns></returns>
 protected override Task OnPostActorMethodAsync(ActorMethodContext actorMethodContext)
 {
     EventSource.Current.ActorMethodPost(this, actorMethodContext);
     return(base.OnPostActorMethodAsync(actorMethodContext));
 }
        protected override async Task OnPostActorMethodAsync(ActorMethodContext actorMethodContext)
        {
            await SaveStateAsync();

            await base.OnPostActorMethodAsync(actorMethodContext);
        }
 protected override async Task OnPostActorMethodAsync(ActorMethodContext actorMethodContext)
 {
     await EventStoreSession.SaveChanges();
 }
Пример #10
0
        protected override async Task OnPreActorMethodAsync(ActorMethodContext actorMethodContext)
        {
            _random = await StateManager.GetOrAddStateAsync("random-generator", new Random(DateTime.Now.Millisecond));

            await base.OnPreActorMethodAsync(actorMethodContext);
        }
 protected override Task OnPostActorMethodAsync(ActorMethodContext actorMethodContext)
 {
     ActorEventSource.Current.ActorMessage(this, $"{actorMethodContext.MethodName} has finished..");
     return(base.OnPostActorMethodAsync(actorMethodContext));
 }
Пример #12
0
        protected override async Task OnPreActorMethodAsync(ActorMethodContext actorMethodContext)
        {
            var orderStatus = await StateManager.TryGetStateAsync <OrderStatus>(OrderStatusStateName);

            _preMethodOrderStatusId = orderStatus.HasValue ? orderStatus.Value.Id : (int?)null;
        }
        protected override Task OnPreActorMethodAsync(ActorMethodContext actorMethodContext)
        {
            ActorEventSource.Current.ActorMessage(this, $"Actor {actorId} received call to {actorMethodContext.MethodName}.");

            return(Task.CompletedTask);
        }
Пример #14
0
 protected override Task OnPostActorMethodAsync(ActorMethodContext actorMethodContext)
 {
     return(base.OnPostActorMethodAsync(actorMethodContext));
 }
Пример #15
0
        protected override async Task OnPostActorMethodAsync(ActorMethodContext actorMethodContext)
        {
            await StateManager.SetStateAsync("random-generator", _random);

            await base.OnPostActorMethodAsync(actorMethodContext);
        }
Пример #16
0
        protected override Task OnPreActorMethodAsync(ActorMethodContext actorMethodContext)
        {
            stopwatch = Stopwatch.StartNew();

            return(Task.CompletedTask);
        }
        protected override async Task OnPreActorMethodAsync(ActorMethodContext actorMethodContext)
        {
            _results = await StateManager.GetOrAddStateAsync("results", new List <FizzBuzzResult>());

            await base.OnPreActorMethodAsync(actorMethodContext);
        }
 /// <summary>
 /// Invokes <see cref="ActorBase.InvokeOnPostActorMethodAsync"/> and returns the resulting task.
 /// Call <see cref="MockActorMethodContextFactory.ActorMethodContextCreateForActor"/>
 /// /<see cref="MockActorMethodContextFactory.ActorMethodContextCreateForReminder"/>
 /// /<see cref="MockActorMethodContextFactory.ActorMethodContextCreateForTimer"/>
 /// to create an <see cref="ActorMethodContext"/>./// </summary>
 /// <param name="actor"></param>
 /// <param name="actorMethodContext"> An <see cref="ActorMethodContext" /> describing the method that will be invoked by actor runtime after this method finishes.</param>
 /// <returns></returns>
 public static Task InvokeOnPostActorMethodAsync(this ActorBase actor, ActorMethodContext actorMethodContext)
 {
     return((Task)typeof(ActorBase)
            .GetMethod("OnPostActorMethodAsync", BindingFlags.Instance | BindingFlags.NonPublic)
            .Invoke(actor, new object[] { actorMethodContext }));
 }
Пример #19
0
        protected override async Task OnPreActorMethodAsync(ActorMethodContext actorMethodContext)
        {
            _workers = await StateManager.GetOrAddStateAsync("workers", new List <IFizzBuzzEvaluator>());

            await base.OnPreActorMethodAsync(actorMethodContext);
        }
Пример #20
0
        protected override async Task OnPostActorMethodAsync(ActorMethodContext actorMethodContext)
        {
            await StateManager.SetStateAsync("workers", _workers);

            await base.OnPostActorMethodAsync(actorMethodContext);
        }
Пример #21
0
 protected override Task OnPreActorMethodAsync(ActorMethodContext actorMethodContext)
 {
     key = Interlocked.Increment(ref _callCounter).ToString();
     return base.OnPreActorMethodAsync(actorMethodContext);
 }
 protected override Task OnPreActorMethodAsync(ActorMethodContext actorMethodContext)
 {
     ActorEventSource.Current.ActorMessage(this, $"{actorMethodContext.MethodName} will start soonn..");
     return(base.OnPostActorMethodAsync(actorMethodContext));
 }
Пример #23
0
 protected override Task OnPostActorMethodAsync(ActorMethodContext actorMethodContext)
 {
     OnPostActorMethodCalled = true;
     return(Task.FromResult(OnPostActorMethodCalled));
 }