コード例 #1
0
 private void OnActorDataReceived(object sender, ActorDataReceivedEventArgs e)
 {
     if (DataReceived != null)
     {
         DataReceived(sender, e);
     }
 }
コード例 #2
0
 protected virtual void OnActorDataReceived(object sender, ActorDataReceivedEventArgs e)
 {
     if (DataReceived != null)
     {
         DataReceived(sender, e);
     }
 }
コード例 #3
0
        public IPEndPoint LookupRemoteActorEndPoint(string actorType)
        {
            var actorLookupRequest       = new ActorLookupRequest();
            var actorLookupRequestBuffer = _encoder.Encode(actorLookupRequest);

            ManualResetEventSlim       waitingResponse = new ManualResetEventSlim(false);
            ActorDataReceivedEventArgs responseEvent   = null;
            EventHandler <ActorDataReceivedEventArgs> onDataReceived =
                (s, e) =>
            {
                responseEvent = e;
                waitingResponse.Set();
            };

            _centerChannel.DataReceived += onDataReceived;
            _centerChannel.SendAsync(_centerActor.Type, _centerActor.Name, actorLookupRequestBuffer);

            bool lookedup = waitingResponse.Wait(TimeSpan.FromSeconds(15));

            _centerChannel.DataReceived -= onDataReceived;
            waitingResponse.Dispose();

            if (lookedup && responseEvent != null)
            {
                var actorLookupResponse = _decoder.Decode <ActorLookupResponse>(
                    responseEvent.Data, responseEvent.DataOffset, responseEvent.DataLength);
                var actors = actorLookupResponse.Actors;
                if (actors != null)
                {
                    _log.InfoFormat("Lookup actors [{0}], [{1}].", actors.Count, string.Join(",", actors.Select(a => a.Type).Distinct().ToArray()));
                    var actor = actors.Where(a => a.Type == actorType).OrderBy(t => Guid.NewGuid()).FirstOrDefault();
                    if (actor != null)
                    {
                        IPAddress actorAddress  = ResolveIPAddress(actor.Address);
                        int       actorPort     = int.Parse(actor.Port);
                        var       actorEndPoint = new IPEndPoint(actorAddress, actorPort);
                        return(actorEndPoint);
                    }
                }
            }

            throw new ActorNotFoundException(string.Format(
                                                 "Cannot lookup remote actor, Type[{0}].", actorType));
        }
コード例 #4
0
        protected override void OnActorDataReceived(object sender, ActorDataReceivedEventArgs e)
        {
            var requestMessage = this.Decoder.DecodeEnvelope(e.Data, e.DataOffset, e.DataLength);

            if (requestMessage.MessageType == typeof(ActorLookupRequest).Name)
            {
                var request = this.Decoder.DecodeMessage <ActorLookupRequest>(
                    requestMessage.MessageData, 0, requestMessage.MessageData.Length);
                if (request != null)
                {
                    var response = new ActorLookupResponse();
                    response.Actors = this.GetAllActors().ToList();
                    var responseBuffer = this.Encoder.Encode(response);

                    _log.InfoFormat("Lookup actors [{0}], RemoteActor[{1}].", response.Actors.Count, e.RemoteActor);
                    this.SendAsync(e.RemoteActor.Type, e.RemoteActor.Name, responseBuffer);
                }
            }
            else
            {
                base.OnActorDataReceived(sender, e);
            }
        }