public ActorChannelSessionDataReceivedEventArgs(
     ActorChannelSession session,
     ActorIdentity remoteActor,
     byte[] data)
     : this(session, remoteActor, data, 0, data.Length)
 {
 }
Beispiel #2
0
        private void OnConnected(object sender, ActorTransportSessionConnectedEventArgs e)
        {
            var session = new ActorChannelSession(_localActor, _channelConfiguration, e.Session);

            session.Handshaked   += OnSessionHandshaked;
            session.DataReceived += OnSessionDataReceived;
            _sessions.Add(session.SessionKey, session);
        }
Beispiel #3
0
        private void OnDataReceived(object sender, ActorTransportSessionDataReceivedEventArgs e)
        {
            ActorChannelSession session = null;

            if (_sessions.TryGetValue(e.SessionKey, out session))
            {
                session.OnDataReceived(e.Data, e.DataOffset, e.DataLength);
            }
        }
Beispiel #4
0
        public void BeginSend(string actorType, byte[] data, int offset, int count)
        {
            var actor = _remoteActors.Values.Where(a => a.Type == actorType).OrderBy(t => Guid.NewGuid()).FirstOrDefault();

            if (actor != null)
            {
                var sessionKey = _actorKeys.Get(actor.GetKey());
                ActorChannelSession session = null;
                if (_sessions.TryGetValue(sessionKey, out session))
                {
                    session.BeginSend(actorType, data, offset, count);
                }
            }
        }
Beispiel #5
0
        public void BeginSend(string actorType, string actorName, byte[] data, int offset, int count)
        {
            var actorKey   = ActorIdentity.GetKey(actorType, actorName);
            var sessionKey = _actorKeys.Get(actorKey);

            if (!string.IsNullOrEmpty(sessionKey))
            {
                ActorChannelSession session = null;
                if (_sessions.TryGetValue(sessionKey, out session))
                {
                    session.BeginSend(actorType, actorName, data, offset, count);
                }
            }
        }
Beispiel #6
0
 public ActorChannelSessionHandshakedEventArgs(
     ActorChannelSession session,
     ActorIdentity remoteActor)
 {
     if (session == null)
     {
         throw new ArgumentNullException("session");
     }
     if (remoteActor == null)
     {
         throw new ArgumentNullException("remoteActor");
     }
     this.Session     = session;
     this.RemoteActor = remoteActor;
 }
Beispiel #7
0
        public IAsyncResult BeginSend(string actorType, string actorName, byte[] data, int offset, int count, AsyncCallback callback, object state)
        {
            var actorKey   = ActorIdentity.GetKey(actorType, actorName);
            var sessionKey = _actorKeys.Get(actorKey);

            if (!string.IsNullOrEmpty(sessionKey))
            {
                ActorChannelSession session = null;
                if (_sessions.TryGetValue(sessionKey, out session))
                {
                    return(session.BeginSend(actorType, actorName, data, offset, count, callback, state));
                }
            }

            return(null);
        }
        public ActorChannelSessionDataReceivedEventArgs(
            ActorChannelSession session,
            ActorIdentity remoteActor,
            byte[] data, int dataOffset, int dataLength)
        {
            if (session == null)
            {
                throw new ArgumentNullException("session");
            }
            if (remoteActor == null)
            {
                throw new ArgumentNullException("remoteActor");
            }
            this.Session     = session;
            this.RemoteActor = remoteActor;

            this.Data       = data;
            this.DataOffset = dataOffset;
            this.DataLength = dataLength;
        }
Beispiel #9
0
        private void OnDisconnected(object sender, ActorTransportSessionDisconnectedEventArgs e)
        {
            ActorChannelSession session = null;

            if (_sessions.TryRemove(e.SessionKey, out session))
            {
                session.Handshaked   -= OnSessionHandshaked;
                session.DataReceived -= OnSessionDataReceived;
                session.Close();
            }

            ActorIdentity remoteActor = null;

            if (_remoteActors.TryRemove(e.SessionKey, out remoteActor))
            {
                _actorKeys.Remove(remoteActor.GetKey());
                _log.InfoFormat("Disconnected with remote [{0}], SessionKey[{1}].", remoteActor, e.SessionKey);

                if (Disconnected != null)
                {
                    Disconnected(this, new ActorDisconnectedEventArgs(e.SessionKey, remoteActor));
                }
            }
        }