Just assigned this issue to you. Thanks for taking over!
The problem I was speaking of is how would MongoDBGlobalContextImpl#member() know that MongoDBGlobalContextImpl#replicaSet() has been called before it?
You could work with different interfaces - all implemented by MongoDBGlobalContextImpl - which represent the state within the fluent invocation change and thus the allowed operations at a given time.
So you could add ReplicaSetMemberDefinitionContext with methods member(String host), member(String host, int port) and which is returned by replicaSet(). Then within MongoDBGlobalContextImpl#member() you'd register the given option value. Note that ReplicaSetOption must extend Option directly, not UniqueOption; The reason being that this option can have several values (one value for each replica set member), whereas unique options only can have exactly one value, like a switch turning on or off something.
ReplicaSetMemberDefinitionContext#member() could return ReplicaSetAnotherMemberDefinitionContext which extends both ReplicaSetMemberDefinitionContext and MongoDBGlobalContext; That way the user could define either another member or invoke other options on the global level. The idea of having the two interfaces is to ensure at least one member is added for a replica set definition.
Best is to check out the existing context + option implementations for MongoDB; There are also dedicated tests for those.
|