Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Fetching contributors…

Cannot retrieve contributors at this time

74 lines (63 sloc) 1.538 kB
using System;
using System.Net.Sockets;
using FluentCassandra.Operations;
namespace FluentCassandra.Connections
{
public class NormalConnectionProvider : ConnectionProvider
{
/// <summary>
///
/// </summary>
/// <param name="builder"></param>
public NormalConnectionProvider(IConnectionBuilder builder)
: base(builder)
{
if (builder.Servers.Count > 1 && builder.ConnectionTimeout == TimeSpan.Zero)
throw new CassandraException("You must specify a timeout when using multiple servers.");
ConnectionTimeout = builder.ConnectionTimeout;
}
/// <summary>
///
/// </summary>
public TimeSpan ConnectionTimeout { get; private set; }
/// <summary>
///
/// </summary>
/// <returns></returns>
public override IConnection Open()
{
IConnection conn = null;
while (Servers.HasNext)
{
try
{
conn = CreateConnection();
conn.Open();
break;
}
catch (SocketException exc)
{
conn.IsHealthy = false;
Servers.ErrorOccurred(conn.Server, exc);
Close(conn);
conn = null;
}
}
if (conn == null)
throw new CassandraOperationException("No connection could be made because all servers have failed.", false, false);
return conn;
}
/// <summary>
///
/// </summary>
/// <returns></returns>
public override IConnection CreateConnection()
{
if (!Servers.HasNext)
return null;
var server = Servers.Next();
var conn = new Connection(server, ConnectionBuilder);
return conn;
}
}
}
Jump to Line
Something went wrong with that request. Please try again.