yifan-c commented on code in PR #200:
URL: https://github.com/apache/cassandra-sidecar/pull/200#discussion_r1980422336


##########
server/src/main/java/org/apache/cassandra/sidecar/modules/multibindings/RouteClassKey.java:
##########
@@ -0,0 +1,66 @@
+/*
+ * 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.sidecar.modules.multibindings;
+
+import io.vertx.core.http.HttpMethod;
+
+/**
+ * Used for defining the class key for VertxRoute multi-binding map.
+ * <p>The RouteClassKey also defines the contract on the existence of static 
fields in its implementations.
+ * The required static fields are read out using reflection. Below is the list:
+ * <ul>
+ *     <li>{@code HttpMethod HTTP_METHOD}</li>
+ *     <li>{@code String ROUTE_URI}</li>
+ * </ul>
+ */
+public interface RouteClassKey extends ClassKey
+{
+    String HTTP_METHOD_FIELD_NAME = "HTTP_METHOD";
+    String ROUTE_URI_FIELD_NAME = "ROUTE_URI";
+
+    /**
+     * Reads the static {@link HttpMethod} defined in the class
+     *
+     * @param classKey class to read
+     * @return http method
+     */
+    static HttpMethod httpMethod(Class<? extends RouteClassKey> classKey)
+    {
+        try
+        {
+            return (HttpMethod) 
classKey.getDeclaredField(HTTP_METHOD_FIELD_NAME).get(null);

Review Comment:
   They can be missed, since there is not enforcement from compiler. However, 
it is the tradeoff made regarding the design.
   Having instance methods means those keys are instantiated, which should be 
avoided, since it just uses the type/Class as keys. 
   If any of the fields are missed, the test should fail. Not at the compile 
time, but it should be caught before a patch can be merged. 



-- 
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

Reply via email to