AMActorHandler.cs 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. using System;
  2. namespace ET.Server
  3. {
  4. [EnableClass]
  5. public abstract class AMActorHandler<E, Message>: IMActorHandler where E : Entity where Message : class, IActorMessage
  6. {
  7. protected abstract ETTask Run(E entity, Message message);
  8. public async ETTask Handle(Entity entity, int fromProcess, object actorMessage)
  9. {
  10. if (actorMessage is not Message msg)
  11. {
  12. Log.Error($"消息类型转换错误: {actorMessage.GetType().FullName} to {typeof (Message).Name}");
  13. return;
  14. }
  15. if (entity is not E e)
  16. {
  17. Log.Error($"Actor类型转换错误: {entity.GetType().Name} to {typeof (E).Name} --{typeof (Message).Name}");
  18. return;
  19. }
  20. await this.Run(e, msg);
  21. }
  22. public Type GetRequestType()
  23. {
  24. if (typeof (IActorLocationMessage).IsAssignableFrom(typeof (Message)))
  25. {
  26. Log.Error($"message is IActorLocationMessage but handler is AMActorHandler: {typeof (Message)}");
  27. }
  28. return typeof (Message);
  29. }
  30. public Type GetResponseType()
  31. {
  32. return null;
  33. }
  34. }
  35. }