Mmuzaf commented on code in PR #2133: URL: https://github.com/apache/cassandra/pull/2133#discussion_r1149859859
########## src/java/org/apache/cassandra/config/registry/Registry.java: ########## @@ -0,0 +1,95 @@ +/* + * 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 org.apache.cassandra.config.registry; + +import javax.annotation.Nullable; + +/** + * A registry of Cassandra's configuration properties that can be updated at runtime. The {@link org.apache.cassandra.config.Config} + * class is the source of configuration fields, types and other metadata available to the registry. The registry is used to + * handle configuration properties that are loaded from the configuration file, and are set via JMX or updated through + * the settings virtual table. + * <p> + * You can use {@link #set(String, Object)} to update a property, in case the property is not present in the registry, + * an exception will be thrown. If the property is present, the registry will try to convert given value to the property's + * type, and if the conversion fails, an exception will be thrown. You can use the {@code String} as a value to be converted, + * or you can use the property's type as a value. In the latter case, no conversion will be performed. + * <p> + * You can use {@link #get(Class, String)} to get a property's value, to read the value, the registry will try to convert the + * property's value if the {@link #getString(String)} to String type (the converter is called to convert the value to String). + */ +public interface Registry +{ + /** + * Update configuration property with the given name to the given value. The value may be the same + * as the property's value, or it may be represented as a string. In the latter case a corresponding + * will be called to get the property's value matching type. + * + * @param name Property name. + * @param value Value to set. + */ + void set(String name, @Nullable Object value); + + /** + * Get property's value by name, The exception will be thrown if the property is not present in the registry or + * the property's value cannot be converted to given generic type. + * + * @param <T> Type to convert to. + * @param cls Class to convert to. + * @param name Property name. + * @return Property's value matching the property's type in the Config. + */ + <T> T get(Class<T> cls, String name); + + /** + * Get property's value by name and convert it to the String type. The exception will be thrown if the property + * is not present in the registry. + * + * @param name Property name. + * @return Property's value converted to String. + */ + String getString(String name); Review Comment: This is actually not true. The `SettingsTable' is not the only system that does type conversions to and from the `String' type. For example, the same is also performed for JMX: ``` public String getPaxosOnLinearizabilityViolations() { return DatabaseDescriptor.paxosOnLinearizabilityViolations().toString(); } public void setPaxosOnLinearizabilityViolations(String v) { DatabaseDescriptor.setPaxosOnLinearizabilityViolations(Config.PaxosOnLinearizabilityViolation.valueOf(v)); logger.info("paxos on linearizability violations {} via jmx", v); } ``` ########## src/java/org/apache/cassandra/config/registry/Registry.java: ########## @@ -0,0 +1,95 @@ +/* + * 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 org.apache.cassandra.config.registry; + +import javax.annotation.Nullable; + +/** + * A registry of Cassandra's configuration properties that can be updated at runtime. The {@link org.apache.cassandra.config.Config} + * class is the source of configuration fields, types and other metadata available to the registry. The registry is used to + * handle configuration properties that are loaded from the configuration file, and are set via JMX or updated through + * the settings virtual table. + * <p> + * You can use {@link #set(String, Object)} to update a property, in case the property is not present in the registry, + * an exception will be thrown. If the property is present, the registry will try to convert given value to the property's + * type, and if the conversion fails, an exception will be thrown. You can use the {@code String} as a value to be converted, + * or you can use the property's type as a value. In the latter case, no conversion will be performed. + * <p> + * You can use {@link #get(Class, String)} to get a property's value, to read the value, the registry will try to convert the + * property's value if the {@link #getString(String)} to String type (the converter is called to convert the value to String). + */ +public interface Registry +{ + /** + * Update configuration property with the given name to the given value. The value may be the same + * as the property's value, or it may be represented as a string. In the latter case a corresponding + * will be called to get the property's value matching type. + * + * @param name Property name. + * @param value Value to set. + */ + void set(String name, @Nullable Object value); + + /** + * Get property's value by name, The exception will be thrown if the property is not present in the registry or + * the property's value cannot be converted to given generic type. + * + * @param <T> Type to convert to. + * @param cls Class to convert to. + * @param name Property name. + * @return Property's value matching the property's type in the Config. + */ + <T> T get(Class<T> cls, String name); + + /** + * Get property's value by name and convert it to the String type. The exception will be thrown if the property + * is not present in the registry. + * + * @param name Property name. + * @return Property's value converted to String. + */ + String getString(String name); Review Comment: This is actually not true. The `SettingsTable` is not the only system that does type conversions to and from the `String' type. For example, the same is also performed for JMX: ``` public String getPaxosOnLinearizabilityViolations() { return DatabaseDescriptor.paxosOnLinearizabilityViolations().toString(); } public void setPaxosOnLinearizabilityViolations(String v) { DatabaseDescriptor.setPaxosOnLinearizabilityViolations(Config.PaxosOnLinearizabilityViolation.valueOf(v)); logger.info("paxos on linearizability violations {} via jmx", v); } ``` -- 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: [email protected] For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]

