chia7712 commented on code in PR #21163:
URL: https://github.com/apache/kafka/pull/21163#discussion_r2718342445
##########
server/src/main/java/org/apache/kafka/server/metrics/DefaultExternalKRaftMetrics.java:
##########
@@ -14,20 +14,20 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
+package org.apache.kafka.server.metrics;
-package kafka.raft
+import org.apache.kafka.controller.metrics.ControllerMetadataMetrics;
+import org.apache.kafka.raft.ExternalKRaftMetrics;
-import org.apache.kafka.controller.metrics.ControllerMetadataMetrics
-import org.apache.kafka.raft.ExternalKRaftMetrics
-import org.apache.kafka.server.metrics.BrokerServerMetrics
+import java.util.Optional;
-class DefaultExternalKRaftMetrics(
- val brokerServerMetrics: Option[BrokerServerMetrics],
- val controllerMetadataMetrics: Option[ControllerMetadataMetrics]
-) extends ExternalKRaftMetrics {
+public record DefaultExternalKRaftMetrics(
+ Optional<BrokerServerMetrics> brokerServerMetrics,
+ Optional<ControllerMetadataMetrics> controllerMetadataMetrics)
implements ExternalKRaftMetrics {
Review Comment:
IIRC, we discussed the appropriate usage of records previously. However, I
realized this can be simplified by using a lambda expression, since
`ExternalKRaftMetrics` is a functional interface
```scala
val externalKRaftMetrics = new
DefaultExternalKRaftMetrics(Optional.ofNullable(brokerMetrics),
Optional.ofNullable(controllerServerMetrics))
```
```scala
val externalKRaftMetrics: ExternalKRaftMetrics = ignoredStaticVoters
=> {
if (brokerMetrics != null)
brokerMetrics.setIgnoredStaticVoters(ignoredStaticVoters)
if (controllerServerMetrics != null)
controllerServerMetrics.setIgnoredStaticVoters(ignoredStaticVoters)
}
```
--
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]