I think using a map of hosts and the respective ports could be used to do this.
MongoDBConfiguration.java
private HashMap<String,Integer> hostPortMap;
public HashMap<String, Integer> getHostPortMap() {
return hostPortMap;
}
public void addNewHostAndPort(String host,Integer port){
hostPortMap.putIfAbsent( host, port );
}
MongoDBGlobalContext could have a new method replicaSet(String,Integer) which could add to this map if not already present. And in MongoDBDataStoreProvider.createMongoClient() use this map to create a list of ServerAddresses and finally create the MongoClient with the list. The problem would be to use addGlobalOption() to update the map. Does it make sense to approach the problem this way?