protected override void OnActorDataReceived(object sender, ActorDataReceivedEventArgs e) { ActorFrameHeader actorLookupRequestFrameHeader = null; bool isHeaderDecoded = this.ChannelConfiguration.FrameBuilder.TryDecodeFrameHeader( e.Data, e.DataOffset, e.DataLength, out actorLookupRequestFrameHeader); if (isHeaderDecoded && actorLookupRequestFrameHeader.OpCode == OpCode.Where) { byte[] payload; int payloadOffset; int payloadCount; this.ChannelConfiguration.FrameBuilder.DecodePayload( e.Data, e.DataOffset, actorLookupRequestFrameHeader, out payload, out payloadOffset, out payloadCount); var actorLookupRequestData = this.ChannelConfiguration .FrameBuilder .ControlFrameDataDecoder .DecodeFrameData <ActorIdentityLookup>(payload, payloadOffset, payloadCount); var lookupActorType = actorLookupRequestData != null ? actorLookupRequestData.Type : null; var actorCollection = new ActorIdentityCollection(); actorCollection.Items.AddRange(this.GetAllActors().Where(a => a.Type == lookupActorType).ToList()); var actorLookupResponseData = this.ChannelConfiguration.FrameBuilder.ControlFrameDataEncoder.EncodeFrameData(actorCollection); var actorLookupResponse = new HereFrame(actorLookupResponseData); var actorLookupRequestBuffer = this.ChannelConfiguration.FrameBuilder.EncodeFrame(actorLookupResponse); _log.InfoFormat("Lookup actors [{0}], RemoteActor[{1}].", actorCollection.Items.Count, e.RemoteActor); this.BeginSend(e.RemoteActor.Type, e.RemoteActor.Name, actorLookupRequestBuffer); } else { base.OnActorDataReceived(sender, e); } }
private void OnActorDataReceived(object sender, ActorDataReceivedEventArgs e) { if (DataReceived != null) { DataReceived(sender, e); } }
protected virtual void OnActorDataReceived(object sender, ActorDataReceivedEventArgs e) { if (DataReceived != null) { DataReceived(sender, e); } }
private IPEndPoint LookupRemoteActorEndPoint(string actorType, Func <IEnumerable <ActorIdentity>, ActorIdentity> matchActorFunc) { var actorLookupCondition = new ActorIdentityLookup() { Type = actorType, }; var actorLookupRequestData = _channelConfiguration.FrameBuilder.ControlFrameDataEncoder.EncodeFrameData(actorLookupCondition); var actorLookupRequest = new WhereFrame(actorLookupRequestData); var actorLookupRequestBuffer = _channelConfiguration.FrameBuilder.EncodeFrame(actorLookupRequest); ManualResetEventSlim waitingResponse = new ManualResetEventSlim(false); ActorDataReceivedEventArgs lookupResponseEvent = null; EventHandler <ActorDataReceivedEventArgs> onDataReceived = (s, e) => { lookupResponseEvent = e; waitingResponse.Set(); }; _centerChannel.DataReceived += onDataReceived; _centerChannel.BeginSend(_centerActor.Type, _centerActor.Name, actorLookupRequestBuffer); bool lookedup = waitingResponse.Wait(TimeSpan.FromSeconds(15)); _centerChannel.DataReceived -= onDataReceived; waitingResponse.Dispose(); if (lookedup && lookupResponseEvent != null) { ActorFrameHeader actorLookupResponseFrameHeader = null; bool isHeaderDecoded = _channelConfiguration.FrameBuilder.TryDecodeFrameHeader( lookupResponseEvent.Data, lookupResponseEvent.DataOffset, lookupResponseEvent.DataLength, out actorLookupResponseFrameHeader); if (isHeaderDecoded && actorLookupResponseFrameHeader.OpCode == OpCode.Here) { byte[] payload; int payloadOffset; int payloadCount; _channelConfiguration.FrameBuilder.DecodePayload( lookupResponseEvent.Data, lookupResponseEvent.DataOffset, actorLookupResponseFrameHeader, out payload, out payloadOffset, out payloadCount); var actorLookupResponseData = _channelConfiguration.FrameBuilder.ControlFrameDataDecoder.DecodeFrameData <ActorIdentityCollection>( payload, payloadOffset, payloadCount); var actors = actorLookupResponseData != null ? actorLookupResponseData.Items : null; if (actors != null) { _log.DebugFormat("Lookup actors [{0}].", actors.Count); var actor = matchActorFunc(actors); if (actor != null) { IPAddress actorAddress = ResolveIPAddress(actor.Address); int actorPort = int.Parse(actor.Port); var actorEndPoint = new IPEndPoint(actorAddress, actorPort); return(actorEndPoint); } } } } return(null); }