AMActorHandler.cs 1.3 KB

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