public void destroyConnection(final Connection connection) {
    final Address endPoint = connection.getEndPoint();
    final boolean removed = mapConnections.remove(endPoint, connection);
    if (!removed) {
      return;
    }

    logger.info("Removed connection to endpoint: " + endPoint + ", connection: " + connection);
    ioService
        .getEventService()
        .executeEventCallback(
            new StripedRunnable() {
              @Override
              public void run() {
                for (ConnectionListener listener : connectionListeners) {
                  listener.connectionRemoved(connection);
                }
              }

              @Override
              public int getKey() {
                return endPoint.hashCode();
              }
            });
  }
  private void fireConnectionRemovedEvent(final Connection connection, final Address endPoint) {
    if (live) {
      ioService
          .getEventService()
          .executeEventCallback(
              new StripedRunnable() {
                @Override
                public void run() {
                  for (ConnectionListener listener : connectionListeners) {
                    listener.connectionRemoved(connection);
                  }
                }

                @Override
                public int getKey() {
                  return endPoint.hashCode();
                }
              });
    }
  }
  @Override
  public boolean registerConnection(final Address remoteEndpoint, final Connection connection) {
    mapConnections.put(remoteEndpoint, (MockConnection) connection);
    ioService
        .getEventService()
        .executeEventCallback(
            new StripedRunnable() {
              @Override
              public void run() {
                for (ConnectionListener listener : connectionListeners) {
                  listener.connectionAdded(connection);
                }
              }

              @Override
              public int getKey() {
                return remoteEndpoint.hashCode();
              }
            });
    return true;
  }
  @Override
  public boolean registerConnection(final Address remoteEndPoint, final Connection connection) {
    if (remoteEndPoint.equals(ioService.getThisAddress())) {
      return false;
    }

    if (connection instanceof TcpIpConnection) {
      TcpIpConnection tcpConnection = (TcpIpConnection) connection;
      Address currentEndPoint = tcpConnection.getEndPoint();
      if (currentEndPoint != null && !currentEndPoint.equals(remoteEndPoint)) {
        throw new IllegalArgumentException(
            connection + " has already a different endpoint than: " + remoteEndPoint);
      }
      tcpConnection.setEndPoint(remoteEndPoint);

      if (!connection.isClient()) {
        TcpIpConnectionMonitor connectionMonitor = getConnectionMonitor(remoteEndPoint, true);
        tcpConnection.setMonitor(connectionMonitor);
      }
    }
    connectionsMap.put(remoteEndPoint, connection);
    connectionsInProgress.remove(remoteEndPoint);
    ioService
        .getEventService()
        .executeEventCallback(
            new StripedRunnable() {
              @Override
              public void run() {
                for (ConnectionListener listener : connectionListeners) {
                  listener.connectionAdded(connection);
                }
              }

              @Override
              public int getKey() {
                return remoteEndPoint.hashCode();
              }
            });
    return true;
  }