public TRef CreateRef <TRef>(int actorId = 1) where TRef : InterfacedActorRef, new() { var actorRef = new TRef(); InterfacedActorRefModifier.SetTarget(actorRef, new BoundActorTarget(actorId)); InterfacedActorRefModifier.SetRequestWaiter(actorRef, this); return(actorRef); }
protected void OnPacket(Packet packet) { switch (packet.Type) { case PacketType.Notification: if (ObserverRegistry.OnNotificationPacket(packet) == false) { _logger?.WarnFormat("Notification didn't find observer. (ObserverId={0}, Message={1})", packet.ActorId, packet.Message.GetType().Name); } break; case PacketType.Response: ResponseWaitingItem waitingItem; if (_responseWaitingItems.TryRemove(packet.RequestId, out waitingItem)) { var actorRefUpdatable = packet.Message as IPayloadActorRefUpdatable; if (actorRefUpdatable != null) { actorRefUpdatable.Update(a => { var actorRef = (InterfacedActorRef)a; var target = (BoundActorTarget)actorRef.Target; if (string.IsNullOrEmpty(target.Address)) { // use this channel InterfacedActorRefModifier.SetRequestWaiter(actorRef, this); } else { // routed and use channel with specified address if (ChannelRouter != null) { var channel = ChannelRouter(this, target.Address); if (channel != null) { InterfacedActorRefModifier.SetTarget(actorRef, new BoundActorTarget(target.Id)); InterfacedActorRefModifier.SetRequestWaiter(actorRef, channel); } } } }); } waitingItem.ResponseHandler(waitingItem.TaskCompletionSource, new ResponseMessage { RequestId = packet.RequestId, ReturnPayload = (IValueGetable)packet.Message, Exception = packet.Exception }); } break; } }
protected override void OnResponseMessage(ResponseMessage message) { Action <ResponseMessage> handler; if (_requestMap.TryRemove(message.RequestId, out handler) == false) { return; } var actorRefUpdatable = message.ReturnPayload as IPayloadActorRefUpdatable; if (actorRefUpdatable != null) { actorRefUpdatable.Update(a => InterfacedActorRefModifier.SetRequestWaiter((InterfacedActorRef)a, this)); } handler(message); }