KafkaNet.BrokerRouter.UpsertConnectionToBrokerConnectionIndex C# (CSharp) Method

UpsertConnectionToBrokerConnectionIndex() private method

private UpsertConnectionToBrokerConnectionIndex ( int brokerId, KafkaNet.Model.KafkaEndpoint brokerEndpoint, IKafkaConnection>.Func connectionFactory ) : void
brokerId int
brokerEndpoint KafkaNet.Model.KafkaEndpoint
connectionFactory IKafkaConnection>.Func
return void
        private void UpsertConnectionToBrokerConnectionIndex(int brokerId, KafkaEndpoint brokerEndpoint, Func<int, IKafkaConnection> connectionFactory)
        {
            //associate the connection with the broker id, and add or update the reference
            _brokerConnectionIndex.AddOrUpdate(brokerId, connectionFactory,
                    (i, existingConnection) =>
                    {
                        //if a connection changes for a broker close old connection and create a new one
                        if (existingConnection.Endpoint.Equals(brokerEndpoint)) return existingConnection;
                        _kafkaOptions.Log.WarnFormat("Broker:{0} Uri changed from:{1} to {2}", brokerId, existingConnection.Endpoint, brokerEndpoint);
                        
                        existingConnection.Dispose();
                        return connectionFactory(i);
                    });
        }