Exemple #1
0
        public void Execute(IEventInput input, IEventCompleted callBackEvent)
        {
            if (input.ID == 0)
            {
                input.ID = GetInputID();
            }
            EventOutput output = new EventOutput();

            output.Token      = input.Token;
            output.ID         = input.ID;
            output.EventError = EventError.Success;
            EventActionHandler handler = GetActionHandler(input.EventPath);

            if (handler == null)
            {
                output.EventError = EventError.NotFound;
                output.Data       = new object[] { $"Process event error {input.EventPath} not found!" };
                if (EnabledLog(LogType.Warring))
                {
                    Log(LogType.Warring, $"[{input.ID}]{input.Token} Process event error {input.EventPath} not found!");
                }
                callBackEvent.Completed(output);
            }
            else
            {
                OnExecute(input, output, handler, callBackEvent);
            }
        }
        public void Execute(EventOutput eventOutput, IEventCompleted completed)
        {
            mEventOutput    = eventOutput;
            mEventCompleted = completed;
            ThreadType threadType = Handler.ThreadType;

            if (threadType == ThreadType.ThreadPool)
            {
                System.Threading.ThreadPool.QueueUserWorkItem(async(d) => await Execute());
            }
            else
            {
                NextQueue.Enqueue(this);
            }
        }
Exemple #3
0
        public void Execute(IEventInput input, IEventCompleted callBackEvent)
        {
            if (input.ID == 0)
            {
                input.ID = GetInputID();
            }
            EventOutput output = new EventOutput();

            output.Token      = input.Token;
            output.ID         = input.ID;
            output.EventError = EventError.Success;
            EventActionHandler handler = GetActionHandler(input.EventPath);

            if (handler == null)
            {
                output.EventError = EventError.NotFound;
                output.Data       = new object[] { $"Process event error {input.EventPath} not found!" };
                if (EnabledLog(LogType.Warring))
                {
                    Log(LogType.Warring, $"{input.Token} Process event error {input.EventPath} not found!");
                }
                callBackEvent.Completed(output);
            }
            else
            {
                try
                {
                    OnExecute(input, output, handler, 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.Token} process event {input.EventPath} error {e_.Message}@{e_.StackTrace}");
                    }
                    callBackEvent.Completed(output);
                }
            }
        }
Exemple #4
0
        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);
        }
Exemple #5
0
 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);
     }
 }