Exemple #1
0
 /// <summary>
 /// Dispara el evento Disconnected.
 ///
 /// It fires the <see cref="Disconnected"/> event.
 /// </summary>
 /// <param name="peer">
 /// Es el punto de conexión que se desconectó.
 /// </param>
 private void OnDisconnected(ServerPeer peer)
 {
     if (Disconnected != null)
     {
         Disconnected(this, new ServerPeerDisconnectedEventArgs(peer));
     }
 }
Exemple #2
0
 /// <summary>
 /// Dispara el evento <see cref="Connected"/>.
 ///
 /// It fires the <see cref="Connected"/> event.
 /// </summary>
 /// <param name="peer">
 /// Es el punto de conexión que se conectó.
 /// </param>
 private void OnConnected(ServerPeer peer)
 {
     if (Connected != null)
     {
         Connected(this, new ServerPeerConnectedEventArgs(peer));
     }
 }
        /// <summary>
        /// It creates a new server peer, and associates the provided
        /// channel to it.
        /// </summary>
        /// <param name="channel">
        /// It's the channel to associate with the peer.
        /// </param>
        /// <returns>
        /// It's the new server peer.
        /// </returns>
        protected virtual ServerPeer GetServerPeer(IChannel channel)
        {
            ServerPeer peer     = null;
            string     peerName = string.Format("Peer-{0}", _nextPeerNumber++);

            if (_messagesIdentifier == null)
            {
                peer = new ServerPeer(peerName);
            }
            else
            {
                peer = new ServerPeer(peerName, _messagesIdentifier);
            }

            peer.MessageProcessor = this;

            peer.Disconnected += new PeerDisconnectedEventHandler(OnPeerDisconnected);

            peer.Bind(channel);

            if (Logger.IsDebugEnabled)
            {
                Logger.Info(string.Format("BasicServerPeerManager - GetServerPeer = {0}.", peerName));
            }

            return(peer);
        }
Exemple #4
0
        /// <summary>
        /// Agrega un punto de conexión a la colección.
        /// </summary>
        /// <param name="peer">
        /// Es el punto de conexión a agregar a la colección.
        /// </param>
        /// <remarks>
        /// Si existe es reemplazado.
        /// </remarks>
        public void Add(ServerPeer peer)
        {
            if (peer == null)
            {
                return;
            }

            this[peer.Name] = peer;
        }
        /// <summary>
        /// Crea e inicializa una nueva clase del tipo <see cref="ServerPeerConnectedEventArgs"/>.
        /// </summary>
        /// <param name="peer">
        /// Es el punto de conexión que se ha conectado.
        /// </param>
        /// <exception cref="ArgumentNullException">
        /// peer contiene una referencia nula.
        /// </exception>
        public ServerPeerConnectedEventArgs(ServerPeer peer)
        {
            if (peer == null)
            {
                throw new ArgumentNullException("peer");
            }

            _peer = peer;
        }
        /// <summary>
        /// Through the invocation of this method <see cref="Server"/> informs to
        /// the peer manager of the connection of the indicated channel.
        /// </summary>
        /// <param name="channel">
        /// It's the connected channel.
        /// </param>
        /// <returns>
        /// The peer associated to the channel.
        /// </returns>
        /// <remarks>
        /// Normally at this time the peers manager associates the channel to the peer.
        /// </remarks>
        public ServerPeer Connected(IChannel channel)
        {
            ServerPeer peer = null;

            lock (this) {
                peer = GetServerPeer(channel);
                _peers.Add(peer);
            }

            return(peer);
        }
Exemple #7
0
        /// <summary>
        /// Maneja el evento <see cref="IListener.Connected"/>.
        /// </summary>
        /// <param name="sender">
        /// Es el objeto que envía el evento.
        /// </param>
        /// <param name="e">
        /// Son los parámetros del evento.
        /// </param>
        private void OnListenerConnected(object sender, ListenerConnectedEventArgs e)
        {
            ServerPeer peer = _serverPeerManager.Connected(e.Channel);

            peer.Disconnected += new PeerDisconnectedEventHandler(OnPeerDisconnected);

            if (Logger.IsDebugEnabled)
            {
                Logger.Debug(string.Format("Server '{0}' - OnListenerConnected '{1}'.",
                                           _name, peer.Name));
            }

            OnConnected(peer);
        }
Exemple #8
0
        /// <summary>
        /// Maneja el evento <see cref="Peer.Disconnected"/>.
        /// </summary>
        /// <param name="sender">
        /// Es el objeto que envía el evento.
        /// </param>
        /// <param name="e">
        /// Son los parámetros del evento.
        /// </param>
        /// <remarks>
        /// El servidor devuelve el canal del punto de conexión al pool de
        /// canales del oyente.
        /// </remarks>
        private void OnPeerDisconnected(object sender, EventArgs e)
        {
            ServerPeer peer = ( ServerPeer)sender;

            peer.Disconnected -= new PeerDisconnectedEventHandler(OnPeerDisconnected);

            if (Logger.IsDebugEnabled)
            {
                Logger.Debug(string.Format("Server '{0}' - OnPeerDisconnected '{1}'.",
                                           _name, peer.Name));
            }

            OnDisconnected(peer);
        }
        /// <summary>
        /// Disables the <see cref="ServerPeer"/>.
        /// </summary>
        /// <param name="peer">
        /// It's the peer to disable.
        /// </param>
        /// <remarks>
        /// It's called when the peer channel is disconnected or an
        /// error occurs.
        /// </remarks>
        protected virtual void DisablePeer(ServerPeer peer)
        {
            lock (this) {
                if (_peers.Contains(peer.Name))
                {
                    if (Logger.IsDebugEnabled)
                    {
                        Logger.Debug(string.Format("BasicServerPeerManager - DisablePeer = {0}.", peer.Name));
                    }

                    peer.MessageProcessor = null;
                    peer.Disconnected    -= new PeerDisconnectedEventHandler(OnPeerDisconnected);
                    _peers.Remove(peer.Name);
                    peer.Dispose();
                }
            }
        }