aratno commented on code in PR #2036: URL: https://github.com/apache/cassandra-java-driver/pull/2036#discussion_r2220036816
########## core/src/main/java/com/datastax/oss/driver/internal/core/context/StartupOptionsBuilder.java: ########## @@ -142,4 +152,28 @@ protected String getDriverName() { protected String getDriverVersion() { return Session.OSS_DRIVER_COORDINATES.getVersion().toString(); } + + private Optional<String> driverBaggage() { + Joiner joiner = Joiner.on(": "); + Map<String, Optional<String>> lbpToBag = + Maps.transformValues(context.getLoadBalancingPolicies(), this::getDriverBaggage); + return Optional.of( + "{" + + lbpToBag.entrySet().stream() + .filter(e -> e.getValue().isPresent()) + .map( + entry -> + joiner.join(Strings.doubleQuote(entry.getKey()), entry.getValue().get())) + .collect(Collectors.joining(", ")) + + "}"); Review Comment: Why not depend on Jackson to do the serialization? I was thinking you could add a DriverBaggage class with `String toJson()` and `static DriverBaggage put(String key, DriverBaggage value)`, and in StartupOptionsBuilder here add all the load balancing policies' baggage. Then we wouldn't have the implicit "String that's actually JSON" type. ########## core/src/main/java/com/datastax/oss/driver/internal/core/loadbalancing/BasicLoadBalancingPolicy.java: ########## @@ -155,10 +158,52 @@ public BasicLoadBalancingPolicy(@NonNull DriverContext context, @NonNull String * Before initialization, this method always returns null. */ @Nullable - protected String getLocalDatacenter() { + @Override + public String getLocalDatacenter() { return localDc; } + @NonNull + @Override + public String getStartupConfiguration() { + StringBuilder builder = new StringBuilder(); + builder + .append("{") + .append(Strings.doubleQuote(BasicLoadBalancingPolicy.class.getSimpleName())) + .append(":") + .append("{") + .append(Strings.doubleQuote("localDc")) + .append(":") + .append(Strings.doubleQuoteNullable(localDc)); Review Comment: Same comment as above about using Jackson for JSON encoding ########## core/src/main/java/com/datastax/oss/driver/api/core/loadbalancing/LocalDcAwareLoadBalancingPolicy.java: ########## @@ -0,0 +1,33 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.datastax.oss.driver.api.core.loadbalancing; + +import edu.umd.cs.findbugs.annotations.NonNull; +import edu.umd.cs.findbugs.annotations.Nullable; + +/** Load balancing policy taking into account local datacenter of the application. */ +public interface LocalDcAwareLoadBalancingPolicy extends LoadBalancingPolicy { + + /** Returns the local datacenter name, if known; empty otherwise. */ + @Nullable + String getLocalDatacenter(); + + /** Returns JSON string containing all properties that impact C* node connectivity. */ + @NonNull + String getStartupConfiguration(); Review Comment: See comment below about String vs DriverBaggage. Could hoist this up to LoadBalancingPolicy with an empty default as well. -- 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. To unsubscribe, e-mail: pr-unsubscr...@cassandra.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: pr-unsubscr...@cassandra.apache.org For additional commands, e-mail: pr-h...@cassandra.apache.org