void OnNeighborClosing(object sender, PeerNeighborCloseEventArgs e)
        {
            IPeerNeighbor neighbor = (IPeerNeighbor)sender;
            PeerConnector localConnector;

            localConnector = connector;

            if (localConnector != null)
                localConnector.OnNeighborClosing(neighbor, e.Reason);

            // Finally notify any Peernode client
            EventHandler<PeerNeighborCloseEventArgs> handler = NeighborClosing;
            if (handler != null)
            {
                handler(this, e);
            }
        }
        void OnNeighborClosed(object sender, PeerNeighborCloseEventArgs e)
        {
            IPeerNeighbor neighbor = (IPeerNeighbor)sender;
            PeerConnector localConnector;
            PeerMaintainer localMaintainer;
            PeerFlooder localFlooder;

            localConnector = connector;
            localMaintainer = maintainer;
            localFlooder = flooder;

            UtilityExtension.OnNeighborClosed(neighbor);
            PeerChannelAuthenticatorExtension.OnNeighborClosed(neighbor);

            if (localConnector != null)
                localConnector.OnNeighborClosed(neighbor);
            if (localMaintainer != null)
                localMaintainer.OnNeighborClosed(neighbor);
            if (localFlooder != null)
                localFlooder.OnNeighborClosed(neighbor);

            // Finally notify any Peernode client
            EventHandler<PeerNeighborCloseEventArgs> handler = NeighborClosed;
            if (handler != null)
            {
                handler(this, e);
            }
        }
            // Close a neighbor gracefully
            public IAsyncResult BeginClose(PeerCloseReason reason,
                PeerCloseInitiator closeInit, Exception exception,
                AsyncCallback callback, object asyncState)
            {
                bool callClosing = false;

                lock (ThisLock)
                {
                    // Set close reason etc. if they are not already set.
                    if (!this.isClosing)
                    {
                        callClosing = true;
                        this.isClosing = true;
                        this.closeReason = reason;
                        this.closeInitiator = closeInit;
                        this.closeException = exception;
                    }
                }

                // Initiate close, if another thread has not already done so....
                // NOTE: NeighborClosing handlers should not throw any catchable exceptions.
                if (callClosing)
                {
                    EventHandler<PeerNeighborCloseEventArgs> handler = this.Closing;
                    if (handler != null)
                    {
                        try
                        {
                            PeerNeighborCloseEventArgs args = new PeerNeighborCloseEventArgs(
                                reason, closeInitiator, exception);
                            handler(this, args);
                        }
                        catch (Exception e)
                        {
                            if (Fx.IsFatal(e)) throw;
                            Abort();
                            throw;
                        }
                    }
                }

                if (this.channelFactory != null)
                    return this.channelFactory.BeginClose(callback, asyncState);
                else
                    return this.proxyChannel.BeginClose(callback, asyncState);
            }
 static void FireEvent(EventHandler<PeerNeighborCloseEventArgs> handler,
     PeerNeighbor neighbor, PeerCloseReason closeReason,
     PeerCloseInitiator closeInitiator, Exception closeException)
 {
     if (handler != null)
     {
         PeerNeighborCloseEventArgs args = new PeerNeighborCloseEventArgs(
             closeReason, closeInitiator, closeException);
         handler(neighbor, args);
     }
 }
 private void OnNeighborClosing(object sender, PeerNeighborCloseEventArgs e)
 {
     IPeerNeighbor neighbor = (IPeerNeighbor) sender;
     PeerConnector connector = this.connector;
     if (connector != null)
     {
         connector.OnNeighborClosing(neighbor, e.Reason);
     }
     EventHandler<PeerNeighborCloseEventArgs> neighborClosing = this.NeighborClosing;
     if (neighborClosing != null)
     {
         neighborClosing(this, e);
     }
 }
 private void OnNeighborClosed(object sender, PeerNeighborCloseEventArgs e)
 {
     IPeerNeighbor neighbor = (IPeerNeighbor) sender;
     PeerConnector connector = this.connector;
     PeerMaintainer maintainer = this.maintainer;
     PeerFlooder flooder = this.flooder;
     UtilityExtension.OnNeighborClosed(neighbor);
     PeerChannelAuthenticatorExtension.OnNeighborClosed(neighbor);
     if (connector != null)
     {
         connector.OnNeighborClosed(neighbor);
     }
     if (maintainer != null)
     {
         maintainer.OnNeighborClosed(neighbor);
     }
     if (flooder != null)
     {
         flooder.OnNeighborClosed(neighbor);
     }
     EventHandler<PeerNeighborCloseEventArgs> neighborClosed = this.NeighborClosed;
     if (neighborClosed != null)
     {
         neighborClosed(this, e);
     }
 }