src/Cassandra/ProtocolVersion.cs
/// <summary>
/// Gets the highest supported protocol version collectively by the given hosts.
/// </summary>
Gets the highest supported protocol version collectively by the given hosts.
Gets the highest supported protocol version collectively by the given hosts .
public static ProtocolVersion GetHighestCommon(this ProtocolVersion version, IEnumerable<Host> hosts)
        {
            var maxVersion = (byte)version;
            var v3Requirement = false;
            var maxVersionWith3OrMore = maxVersion;
            foreach (var host in hosts)
            {
                var cassandraVersion = host.CassandraVersion;
                if (cassandraVersion >= Version30)
                {
                    v3Requirement = true;
                    maxVersion = Math.Min((byte)ProtocolVersion.V4, maxVersion);
                    maxVersionWith3OrMore = maxVersion;
                }
                else if (cassandraVersion >= Version22)
                {
                    maxVersion = Math.Min((byte)ProtocolVersion.V4, maxVersion);
                    maxVersionWith3OrMore = maxVersion;
                }
                else if (cassandraVersion >= Version21)
                {
                    maxVersion = Math.Min((byte)ProtocolVersion.V3, maxVersion);
                    maxVersionWith3OrMore = maxVersion;
                }
                else if (cassandraVersion >= Version20)
                {
                    maxVersion = Math.Min((byte)ProtocolVersion.V2, maxVersion);
                }
                else
                {
                    maxVersion = Math.Min((byte)ProtocolVersion.V1, maxVersion);
                }
            }
            if (v3Requirement && maxVersion < (byte)ProtocolVersion.V3)
            {
                Logger.Error($"Detected hosts with maximum protocol version of {maxVersion} but there are some hosts " +
                             $"that require at least version 3. Will not be able to connect to these older hosts");
                maxVersion = maxVersionWith3OrMore;
            }
            return (ProtocolVersion) maxVersion;
        }
public static ProtocolVersion GetHighestCommon ( this ProtocolVersion version , IEnumerable < Host > hosts ) { var maxVersion = ( byte ) version ; var v3Requirement = false ; var maxVersionWith3OrMore = maxVersion ; foreach ( var host in hosts ) { var cassandraVersion = host . CassandraVersion ; if ( cassandraVersion >= Version30 ) { v3Requirement = true ; maxVersion = Math . Min ( ( byte ) ProtocolVersion . V4 , maxVersion ) ; maxVersionWith3OrMore = maxVersion ; } else if ( cassandraVersion >= Version22 ) { maxVersion = Math . Min ( ( byte ) ProtocolVersion . V4 , maxVersion ) ; maxVersionWith3OrMore = maxVersion ; } else if ( cassandraVersion >= Version21 ) { maxVersion = Math . Min ( ( byte ) ProtocolVersion . V3 , maxVersion ) ; maxVersionWith3OrMore = maxVersion ; } else if ( cassandraVersion >= Version20 ) { maxVersion = Math . Min ( ( byte ) ProtocolVersion . V2 , maxVersion ) ; } else { maxVersion = Math . Min ( ( byte ) ProtocolVersion . V1 , maxVersion ) ; } } if ( v3Requirement && maxVersion < ( byte ) ProtocolVersion . V3 ) { Logger . Error ( $" Detected hosts with maximum protocol version of  { maxVersion }  but there are some hosts  " + $" that require at least version 3. Will not be able to connect to these older hosts " ) ; maxVersion = maxVersionWith3OrMore ; } return ( ProtocolVersion ) maxVersion ; }
Gets the highest supported protocol version collectively by the given hosts.
Gets the highest supported protocol version collectively by the given hosts .
// Anything 3.0.0+ has a max protocol version of V4 and requires at least V3. // Cassandra 2.2.x has a max protocol version of V4. // Cassandra 2.1.x has a max protocol version of V3. // Cassandra 2.0.x has a max protocol version of V2. // Anything else is < 2.x and requires protocol version V1.
ProtocolVersion
this
hosts
IEnumerable<Host>