pkuwm commented on a change in pull request #838: Make ConfigAccessor and
ZkUtil realm-aware
URL: https://github.com/apache/helix/pull/838#discussion_r386702148
##########
File path: helix-core/src/main/java/org/apache/helix/ConfigAccessor.java
##########
@@ -830,4 +857,75 @@ public void close() {
_zkClient.close();
}
}
+
+ public static class Builder {
+ private String _zkAddress;
+ private RealmAwareZkClient.RealmMode _realmMode;
+ private RealmAwareZkClient.RealmAwareZkConnectionConfig
_realmAwareZkConnectionConfig;
+ private RealmAwareZkClient.RealmAwareZkClientConfig
_realmAwareZkClientConfig;
+
+ public Builder() {
+ }
+
+ public Builder setZkAddress(String zkAddress) {
+ _zkAddress = zkAddress;
+ return this;
+ }
+
+ public Builder setRealmMode(RealmAwareZkClient.RealmMode realmMode) {
+ _realmMode = realmMode;
+ return this;
+ }
+
+ public Builder setRealmAwareZkConnectionConfig(
+ RealmAwareZkClient.RealmAwareZkConnectionConfig
realmAwareZkConnectionConfig) {
+ _realmAwareZkConnectionConfig = realmAwareZkConnectionConfig;
+ return this;
+ }
+
+ public Builder setRealmAwareZkClientConfig(
+ RealmAwareZkClient.RealmAwareZkClientConfig realmAwareZkClientConfig) {
+ _realmAwareZkClientConfig = realmAwareZkClientConfig;
+ return this;
+ }
+
+ public ConfigAccessor build() throws Exception {
+ validate();
+ return new ConfigAccessor(this);
+ }
+
+ /**
+ * Validate the given parameters before creating an instance of
ConfigAccessor.
+ */
+ private void validate() {
+ // Resolve RealmMode based on other parameters
+ boolean isRealmModeSet = _realmMode != null;
+ boolean isZkAddressSet = _zkAddress != null && !_zkAddress.isEmpty();
+ if (isRealmModeSet) {
+ if (_realmMode == RealmAwareZkClient.RealmMode.SINGLE_REALM &&
!isZkAddressSet) {
+ throw new HelixException(
+ "ConfigAccessor: RealmMode cannot be single-realm without a
valid ZkAddress set!");
+ }
+ // If realm mode is set to multi-realm, we simply ignore the given ZK
address
+ } else {
+ // If zkAddress is set, that implies single-realm mode. Otherwise,
multi-realm mode.
+ _realmMode = isZkAddressSet ? RealmAwareZkClient.RealmMode.SINGLE_REALM
+ : RealmAwareZkClient.RealmMode.MULTI_REALM;
Review comment:
It seems this could be simplified a bit to make it easier to read?
```
if (_realmMode == RealmAwareZkClient.RealmMode.SINGLE_REALM &&
!isZkAddressSet) {
throw new HelixException(
"ConfigAccessor: RealmMode cannot be single-realm without a valid
ZkAddress set!");
}
if (_realmMode == null) {
_realmMode = isZkAddressSet ? RealmAwareZkClient.RealmMode.SINGLE_REALM
: RealmAwareZkClient.RealmMode.MULTI_REALM;
}
```
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
With regards,
Apache Git Services
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]