Skip to content

Suggestion -- Go back on the strongly typed IConnection implementation, and revert back to path instead of uri in methods, and then implement the connection pool as a decoration class #537

@icanhasjonas

Description

@icanhasjonas

.. that way you can get rid of Sniff(), Ping() -> cleaner code
i.e

public class ConnectionPool : IConnection
{
    // pseudo.. 
    public ConnectionPool( IEnumerable<IConnection> connections )
    {
        _selector = new RandomSelector( connections );
        // ......
    }

    protected async Task<ElasticResponse> Execute( HttpMethod method, string path, string data )
    {
        // delegate the call to the connection
        var connection = await FindConnectionAsync();
        return await connection.Execute( method, path, data ); // Get, Post, .... 
    }

    protected virtual async Task<IConnection> FindConnectionAsync()
    {
        for( var i = 0; i < _settings.RetryCount; i++ ) {
            var connection = await _selector.MoveNext(); // could be implemented as an IEnumerator<Task<IConnection>>
            if( connection != null ) {
                return connection;
            }
            await Task.Delay( _settings.RetryWait );
        }
        throw new SomeExceptionAboutNotAbleToFindAcceptableConnection();
    }
}

... or.. you know, I could just do it for you ;-)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions