AMActorLocationHandler.cs 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. using System;
  2. namespace ET.Server
  3. {
  4. [EnableClass]
  5. public abstract class AMActorLocationHandler<E, Message>: IMActorHandler where E : Entity where Message : class, IActorLocationMessage
  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 message)
  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. ActorResponse response = new() {RpcId = message.RpcId};
  21. ActorHandleHelper.Reply(fromProcess, response);
  22. await this.Run(e, message);
  23. }
  24. public Type GetRequestType()
  25. {
  26. return typeof (Message);
  27. }
  28. public Type GetResponseType()
  29. {
  30. return typeof (ActorResponse);
  31. }
  32. }
  33. }