narendly commented on a change in pull request #855: Make ZkBaseDataAccessor
realm-aware
URL: https://github.com/apache/helix/pull/855#discussion_r388079677
##########
File path:
helix-core/src/main/java/org/apache/helix/manager/zk/ZkBaseDataAccessor.java
##########
@@ -1248,4 +1240,123 @@ 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 ZkBaseDataAccessor.Builder setZkAddress(String zkAddress) {
+ this.zkAddress = zkAddress;
+ return this;
+ }
+
+ public ZkBaseDataAccessor.Builder
setRealmMode(RealmAwareZkClient.RealmMode realmMode) {
+ this.realmMode = realmMode;
+ return this;
+ }
+
+ public ZkBaseDataAccessor.Builder setRealmAwareZkConnectionConfig(
+ RealmAwareZkClient.RealmAwareZkConnectionConfig
realmAwareZkConnectionConfig) {
+ this.realmAwareZkConnectionConfig = realmAwareZkConnectionConfig;
+ return this;
+ }
+
+ public ZkBaseDataAccessor.Builder setRealmAwareZkClientConfig(
+ RealmAwareZkClient.RealmAwareZkClientConfig realmAwareZkClientConfig) {
+ this.realmAwareZkClientConfig = realmAwareZkClientConfig;
+ return this;
+ }
+
+ public ZkBaseDataAccessor<?> build() throws Exception {
+ validate();
+ return new ZkBaseDataAccessor<>(this);
+ }
+
+ /**
+ * Validate the given parameters before creating an instance of
ConfigAccessor.
+ */
+ private void validate() {
+ // Resolve RealmMode based on other parameters
+ boolean isZkAddressSet = zkAddress != null && !zkAddress.isEmpty();
+ 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;
+ }
+
+ // Resolve RealmAwareZkClientConfig
+ boolean isZkClientConfigSet = realmAwareZkClientConfig != null;
+ // Resolve which clientConfig to use
+ realmAwareZkClientConfig =
+ isZkClientConfigSet ?
realmAwareZkClientConfig.createHelixZkClientConfig()
+ : new HelixZkClient.ZkClientConfig().setZkSerializer(new
ZNRecordSerializer());
+
+ // Resolve RealmAwareZkConnectionConfig
+ if (realmAwareZkConnectionConfig == null) {
+ // If not set, create a default one
+ realmAwareZkConnectionConfig =
+ new
RealmAwareZkClient.RealmAwareZkConnectionConfig.Builder().build();
+ }
+ }
+ }
+
+ private ZkBaseDataAccessor(Builder builder) throws IOException,
InvalidRoutingDataException {
Review comment:
Could we move up this constructor so it's with other public constructors?
----------------------------------------------------------------
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]