gocql/gocql — pull request #213 by fmccann (2014-08-04 18:21:29+00:00)
Title: Connect handler

I'd like to have some way of knowing when a Cassandra cluster becomes completely unreachable. I think this would be when the Pool.Size() drops to zero. I don't believe there's currently an easy way to access this information at the time it changes, so I have a small patch that would add optional asyc callbacks to the cluster config that could be called when the adding or removing connections to the connection pool:

config := gocql.NewCluster(“localhost")
config.Keyspace = “foo"
config.Consistency = gocql.Quorum

config.DisconnectHandler = func(p gocql.ConnectionPool) {
fmt.Printf(“Disconnect- pool size = %v\n”, p.Size())
}

config.ConnectHandler = func(p gocql.ConnectionPool) {
fmt.Printf(“Connect- pool size = %v\n”, p.Size())
}

I think this would allow interested consumers of the API any easy way to get access to the pool when the the size of it changes without having to resort to some sort of polling.