CassandraConnectionConfig is immutable

Developer
Aug 2, 2011 at 3:41 AM

CassandraConnectionConfig is immutable by design because 1) it is supposed to be stored in ConnectionPool to be referred later, and 2) it is used as a hash key.

But it is useful for developers if there's a version of CassandraConnectionConfig where they can change property, so that they can create config like:

var config = new CassandraConnectionConfig { ConsistencyLevel = ConsistencyLevel.ALL };

So, I'm thinking, just like .NET class DbConnectionStringBuilder, it might be a good idea to add a CassandraConnectionConfigBuilder class. By adding this, developers can do like this:

var builder = new CassandraConnectionConfigBuilder { ConsistencyLevel = ConsistencyLevel.ALL };
var config = builder.CassandraConnectionConfig;

So it's more readable and easier to create configurations.

Any thoughts?

Coordinator
Aug 5, 2011 at 1:16 AM
Edited Aug 5, 2011 at 1:20 AM

Now, we can write this.

var config = new CassandraConnectionCOnfig
                         (
                              new []{"host1", "host2"},
                              9160,
                              "keyspace1",
                              true,
                              new TimeSpan(0, 0, 10),
                              1,
                              3
                          );

If we bring in CassandraConnectionBuilder then

var builder = new CassandraConnectionBuilder
                    {
                         Hosts = new []{"host1", "host2"},
                         Port = 9160,
                         Keyspace = "keyspace1",
                         IsFlamed = true,
                         Timeout = new TimeSpan(0, 0, 10),
                         MinPoolCountPerHost = 1,
                         MaxPoolCountPerHost = 3
                     };
var config = builder.CassandraConnctionConfig;
I think builder is deffer little from constructor. If you know useful case, please teach me example.

Developer
Aug 5, 2011 at 3:02 AM

A few benefits of builder as I think are:

  1. With constructor, it isn't clear what "true" is. It can be clearer with named parameters in C#4 though.
  2. What if you want to specify host and ConsistencyLevel, but use default value for all other values?
  3. Think you want to build parameters from database, text file, or command line arguments. You could write, for instance:
    if (arg[i] == "max") { builder.MaxPoolCountPerHost = arg[i+1]; }
    but this becomes a little more complex without builder.

Do these use cases appeal enough to you?

Coordinator
Aug 5, 2011 at 6:09 AM

I see builder benefits. Adding builder class is no matter.

And I suggest another way that config infomation is written in App.config or better yet. Example, see following xml. What do you think?

<cassandraemon>
    <hosts>
        <host name="host1" port="9160" />
        <host name="host2" port="9160" />
    </hosts>
    <connection keyspace="keyspace1" isflamed="true" timeout="10" />
    <pool min="1" max="3" />
</cassandraemon>

Developer
Aug 6, 2011 at 5:16 AM

I agree that being able to specify it in App.config/web.config is a good feature.

I wonder, however, is it better to have a cassandra-schema defined as you indicated, or use connectionString approach like:

<connectionString="host=host1 host2;port=9160;isFramed=true" />

which is consistent with other data providres and can re-use connection-string specific features like encryption of web.config.

Cassandra-specific schema in your example is easier to read.

What do you think?

Coordinator
Aug 6, 2011 at 6:05 PM

Both schema and connectionString are no problem. If you implement this feature, you may select approach you think best.

Developer
Aug 7, 2011 at 8:05 PM
This discussion has been copied to a work item. Click here to go to the work item and continue the discussion.