Hi guys!
I've been recently looking into java driver code and it seems that there are several issues with code organization, I thought that, for example, ControlConnection may benefit from some refactoring.
So i've started a branch to see what can be done, but is seems a lot of work and a major code change (though most of it is copy-pasting) so I decided to ask if these are indeed "issues" to your opinion.
So here are some thoughs (about usages from ControlConnection mainly):
1. Cluster acts a a God-object, everybody have access to all its fields so it is not easy to check what methods are actually needed for specific class. Adding more granular interfaces (like ClusterHosts for Metadata with getHost/getAllHosts/addIfAbsent) and passing them via dependency injection would allow better unit testing, because such dependencies are more easily mocked.
2. Replacing static methods with instance ones (same dependency injection pricinple).
3. Moving metadata update code to owner class. Currently Host and some other data like partitioner can be updated from any part of code, for most cases it may be better to have a single place for such updates - in the class holding most of this data, for better encapsulation. Not sure about implementation details though.
4. Splitting ControlConnection into several small classes each with 1-2 methods doing something very specific - connection logic, quering data, parsing result set rows, updating metadata to match queried data, etc. Purpose - more granular unit testing.
5. Dependency injection for loggers (if messages should be asserted). Static loggers are easy to use but asserting messages requires too much code. Since most objects live for a long time dependency injecting logger into them should not be a problem.
So let's discuss it. If some of these issues are really considered issues I may try to contribute some code later.