private void OnExecute(IEventInput input, EventOutput output, EventActionHandler handler, IEventCompleted callBackEvent) { var actorID = input.Properties?[ACTOR_TAG]; string actorPath = null; object controller = null; NextQueue nextQueue = null; if (string.IsNullOrEmpty(actorID)) { nextQueue = this.InputNextQueue.Next(this.NextQueueWaits); if (EnabledLog(LogType.Debug)) { Log(LogType.Debug, $"{input.Token} Process event {input.EventPath}"); } controller = handler.Controller; if (handler.ThreadType == ThreadType.SingleQueue) { nextQueue = handler.GetNextQueue(input.Data); } if (!handler.SingleInstance) { controller = CreateController(handler.ControllerType); } } else { ActorCollection.ActorCollectionItem item; item = handler.Actors.Get(actorID); if (item == null) { actorPath = "/" + handler.ServiceName + "/" + actorID; if (EnabledLog(LogType.Debug)) { Log(LogType.Debug, $"{input.Token} {handler.ControllerType.Name}@{actorPath} create actor"); } item = new ActorCollection.ActorCollectionItem(); item.ActorID = actorID; item.Actor = CreateController(handler.Actors.ServiceType); item.ServiceName = handler.ServiceName; item.Interface = handler.Interface; item = handler.Actors.Set(actorID, item); item.TimeOut = EventCenter.Watch.ElapsedMilliseconds + ActorFreeTime * 1000; controller = item.Actor; if (controller is IActorState state) { state.ActorPath = actorPath; state.EventCenter = this; state.EventPath = input.EventPath; state.Token = input.Token; state.ActorInit(actorID); if (EnabledLog(LogType.Debug)) { Log(LogType.Debug, $"{input.Token} {handler.ControllerType.Name}@{actorPath} actor initialized"); } } } else { item.TimeOut = EventCenter.Watch.ElapsedMilliseconds + ActorFreeTime * 1000; controller = item.Actor; if (controller is IActorState state) { state.EventPath = input.EventPath; state.Token = input.Token; } } nextQueue = item.NextQueue; if (EnabledLog(LogType.Debug)) { Log(LogType.Debug, $"{input.Token} Process event {input.EventPath} in /{item.ServiceName}/{item.ActorID} actor"); } } EventActionHandlerContext context = new EventActionHandlerContext(this, input, handler, controller, nextQueue); context.Execute(output, callBackEvent); }
private async void OnExecute(IEventInput input, EventOutput output, EventActionHandler handler, IEventCompleted callBackEvent) { try { string actorID = null; input.Properties?.TryGetValue(ACTOR_TAG, out actorID); string actorPath = null; object controller = null; NextQueue nextQueue = null; ActorCollection.ActorItem item = null; if (string.IsNullOrEmpty(actorID)) { nextQueue = this.InputNextQueue.Next(this.NextQueueWaits); if (EnabledLog(LogType.Debug)) { Log(LogType.Debug, $"[{input.ID}]{input.Token} Process event {input.EventPath}"); } controller = handler.Controller; if (handler.ThreadType == ThreadType.SingleQueue) { nextQueue = handler.GetNextQueue(input.Data); } if (!handler.SingleInstance) { controller = CreateController(handler.ControllerType); } } else { item = handler.Actors.Get(actorID); if (item == null) { actorPath = "/" + handler.ServiceName + "/" + actorID; if (EnabledLog(LogType.Debug)) { Log(LogType.Debug, $"[{input.ID}]{input.Token} {handler.ControllerType.Name}@{actorPath} create actor"); } item = new ActorCollection.ActorItem(); item.ActorID = actorID; item.Actor = CreateController(handler.Actors.ServiceType); item.ServiceName = handler.ServiceName; item.Interface = handler.Interface; item.TimeOut = EventCenter.Watch.ElapsedMilliseconds + ActorFreeTime * 1000; item = handler.Actors.Set(actorID, item, out bool add); controller = item.Actor; if (controller is IActorState state) { state.ActorID = actorID; state.ActorPath = actorPath; state.EventCenter = this; if (EnabledLog(LogType.Debug)) { Log(LogType.Debug, $"[{input.ID}]{input.Token} {handler.ControllerType.Name}@{actorPath} actor initialized"); } } } else { item.TimeOut = EventCenter.Watch.ElapsedMilliseconds + ActorFreeTime * 1000; controller = item.Actor; } nextQueue = item.NextQueue; if (EnabledLog(LogType.Debug)) { Log(LogType.Debug, $"[{input.ID}]{input.Token} Process event {input.EventPath} in /{item.ServiceName}/{item.ActorID} actor"); } await item.Initialize(); } EventActionHandlerContext context = new EventActionHandlerContext(this, input, handler, controller, nextQueue, item); context.Execute(output, callBackEvent); } catch (Exception e_) { output.EventError = EventError.InnerError; output.Data = new object[] { $"Process event {input.EventPath} error {e_.Message}" }; if (EnabledLog(LogType.Error)) { Log(LogType.Error, $"[{input.ID}]{input.Token} process event {input.EventPath} error {e_.Message}@{e_.StackTrace}"); } callBackEvent.Completed(output); } }