You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

43 lines
1.3 KiB

using System;
namespace ET
{
[ActorMessageHandler]
public abstract class AMActorLocationHandler<E, Message>: IMActorHandler where E : Entity where Message : class, IActorLocationMessage
{
protected abstract ETTask Run(E entity, Message message);
public async ETTask Handle(Entity entity, object actorMessage, Action<IActorResponse> reply)
{
Message msg = actorMessage as Message;
if (msg == null)
{
Log.Error($"消息类型转换错误: {actorMessage.GetType().FullName} to {typeof (Message).Name}");
return;
}
E e = entity as E;
if (e == null)
{
Log.Error($"Actor类型转换错误: {entity.GetType().Name} to {typeof (E).Name} --{typeof (Message).Name}");
return;
}
IActorResponse response = (IActorResponse) Activator.CreateInstance(GetResponseType());
response.RpcId = msg.RpcId;
reply.Invoke(response);
await this.Run(e, msg);
}
public Type GetRequestType()
{
return typeof (Message);
}
public Type GetResponseType()
{
return typeof (ActorResponse);
}
}
}