Close() public method

public Close ( ) : void
return void
        public void DestroyConnection(ClientConnection connection, Exception cause)
        {
            var address = connection.GetAddress();

            Logger.Finest("Destroying connection " + connection + " due to " + cause.Message);
            if (address != null)
            {
                ClientConnection conn;
                if (_activeConnections.TryRemove(address, out conn))
                {
                    connection.Close();
                    FireConnectionListenerEvent(f => f.ConnectionRemoved(connection));
                }
                else
                {
                    Logger.Warning("Could not find connection " + connection +
                                   " in list of connections, could not destroy connection. Current list of connections are " +
                                   string.Join(", ", _activeConnections.Keys));
                    connection.Close();
                }
            }
            else
            {
                // connection has not authenticated yet
                ((ClientInvocationService)_client.GetInvocationService()).CleanUpConnectionResources(connection);
            }
        }
        private ClientConnection InitializeConnection(Address address, Authenticator authenticator)
        {
            CheckLive();
            ClientConnection connection = null;
            var id = _nextConnectionId;

            try
            {
                if (Logger.IsFinestEnabled())
                {
                    Logger.Finest("Creating new connection for " + address + " with id " + id);
                }

                connection = new ClientConnection(this, (ClientInvocationService)_client.GetInvocationService(), id, address, _networkConfig);

                connection.Init(_socketInterceptor);
                authenticator(connection);
                Interlocked.Increment(ref _nextConnectionId);
                Logger.Finest("Authenticated to " + connection);
                return(connection);
            }
            catch (Exception e)
            {
                Logger.Severe("Error connecting to " + address + " with id " + id, e);
                if (connection != null)
                {
                    connection.Close();
                }
                throw ExceptionUtil.Rethrow(e, typeof(IOException), typeof(SocketException),
                                            typeof(TargetDisconnectedException));
            }
        }
        private ClientConnection GetNewConnection(Address address, Authenticator authenticator)
        {
            ClientConnection connection = null;

            lock (_connectionMutex)
            {
                var id = _nextConnectionId;
                try
                {
                    Logger.Finest("Creating new connection for " + address + " with id " + id);
                    connection = new ClientConnection(this, (ClientInvocationService)_client.GetInvocationService(),
                                                      id,
                                                      address, _networkConfig);
                    if (_socketInterceptor != null)
                    {
                        _socketInterceptor.OnConnect(connection.GetSocket());
                    }
                    connection.SwitchToNonBlockingMode();
                    authenticator(connection);
                    Interlocked.Increment(ref _nextConnectionId);
                    Logger.Finest("Authenticated to " + connection);
                    return(connection);
                }
                catch (Exception e)
                {
                    Logger.Severe("Error connecting to " + address + " with id " + id, e);
                    if (connection != null)
                    {
                        connection.Close();
                    }
                    throw ExceptionUtil.Rethrow(e, typeof(IOException), typeof(SocketException));
                }
            }
        }
        public void DestroyConnection(ClientConnection connection)
        {
            var address = connection.GetAddress();

            Logger.Finest("Destroying connection " + connection);
            lock (_connectionMutex)
            {
                if (address != null)
                {
                    ClientConnection conn;
                    if (_addresses.TryRemove(address, out conn))
                    {
                        if (conn == connection)
                        {
                            connection.Close();
                            FireConnectionListenerEvent(f => f.ConnectionRemoved(connection));
                        }
                        else
                        {
                            Logger.Warning(connection + " is already destroyed.");
                            _addresses.TryAdd(address, conn);
                        }
                    }
                }
            }
        }
        public void DestroyConnection(ClientConnection connection)
        {
            var address = connection.GetAddress();

            // ReSharper disable once InconsistentlySynchronizedField
            Logger.Finest("Destroying connection " + connection);
            if (address != null)
            {
                ClientConnection conn;
                if (_addresses.TryRemove(address, out conn))
                {
                    connection.Close();
                    FireConnectionListenerEvent(f => f.ConnectionRemoved(connection));
                }
            }
            else
            {
                // connection has not authenticated yet
                ((ClientInvocationService)_client.GetInvocationService()).CleanUpConnectionResources(connection);
            }
        }
Esempio n. 6
0
        private ClientConnection InitializeConnection(Address address, bool isOwner)
        {
            CheckLive();
            ClientConnection connection = null;
            var id = _nextConnectionId;

            var publicAddress = _client.GetAddressProvider().TranslateToPublic(address);

            try
            {
                if (Logger.IsFinestEnabled())
                {
                    Logger.Finest("Creating new connection for " + publicAddress + " with id " + id);
                }
                connection = new ClientConnection(this, (ClientInvocationService)_client.GetInvocationService(), id,
                                                  publicAddress, _networkConfig);
                connection.Init(_socketInterceptor);
                Authenticate(connection, isOwner);
                Interlocked.Increment(ref _nextConnectionId);
                Logger.Finest("Authenticated to " + connection);
                return(connection);
            }
            catch (Exception e)
            {
                if (Logger.IsFinestEnabled())
                {
                    Logger.Finest("Error connecting to " + publicAddress + " with id " + id, e);
                }

                if (connection != null)
                {
                    connection.Close();
                }
                throw ExceptionUtil.Rethrow(e, typeof(IOException), typeof(SocketException), typeof(TargetDisconnectedException));
            }
        }
        private ClientConnection InitializeConnection(Address address, Authenticator authenticator)
        {
            CheckLive();
            ClientConnection connection = null;
            var id = _nextConnectionId;
            try
            {
                if (Logger.IsFinestEnabled())
                {
                    Logger.Finest("Creating new connection for " + address + " with id " + id);
                }

                connection = new ClientConnection(this, (ClientInvocationService) _client.GetInvocationService(), id, address, _networkConfig);

                connection.Init(_socketInterceptor);
                authenticator(connection);
                Interlocked.Increment(ref _nextConnectionId);
                Logger.Finest("Authenticated to " + connection);
                return connection;
            }
            catch (Exception e)
            {
                if (Logger.IsFinestEnabled())
                {
                    Logger.Finest("Error connecting to " + address + " with id " + id, e);
                }

                if (connection != null)
                {
                    connection.Close();
                }
                throw ExceptionUtil.Rethrow(e, typeof (IOException), typeof (SocketException),
                    typeof (TargetDisconnectedException));
            }
        }
 public void DestroyConnection(ClientConnection connection, Exception cause)
 {
     var address = connection.GetAddress();
     Logger.Finest("Destroying connection " + connection + " due to " + cause.Message);
     if (address != null)
     {
         ClientConnection conn;
         if (_addresses.TryRemove(address, out conn))
         {
             connection.Close();
             FireConnectionListenerEvent(f => f.ConnectionRemoved(connection));
         }
         else
         {
             Logger.Warning("Could not find connection " + connection +
                            " in list of connections, could not destroy connection. Current list of connections are " +
                            string.Join(", ", _addresses.Keys));
             connection.Close();
         }
     }
     else
     {
         // connection has not authenticated yet
         ((ClientInvocationService) _client.GetInvocationService()).CleanUpConnectionResources(connection);
     }
 }
 public void DestroyConnection(ClientConnection connection)
 {
     var address = connection.GetAddress();
     // ReSharper disable once InconsistentlySynchronizedField
     Logger.Finest("Destroying connection " + connection);
     if (address != null)
     {
         ClientConnection conn;
         if (_addresses.TryRemove(address, out conn))
         {
             connection.Close();
             FireConnectionListenerEvent(f => f.ConnectionRemoved(connection));
         }
     }
     else
     {
         // connection has not authenticated yet
         ((ClientInvocationService) _client.GetInvocationService()).CleanUpConnectionResources(connection);
     }
 }