001/* 002 * Licensed to the Apache Software Foundation (ASF) under one or more 003 * contributor license agreements. See the NOTICE file distributed with 004 * this work for additional information regarding copyright ownership. 005 * The ASF licenses this file to You under the Apache License, Version 2.0 006 * (the "License"); you may not use this file except in compliance with 007 * the License. You may obtain a copy of the License at 008 * 009 * http://www.apache.org/licenses/LICENSE-2.0 010 * 011 * Unless required by applicable law or agreed to in writing, software 012 * distributed under the License is distributed on an "AS IS" BASIS, 013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 014 * See the License for the specific language governing permissions and 015 * limitations under the License. 016 */ 017package org.apache.juneau.rest.server.metrics; 018 019import java.time.*; 020 021/** 022 * Default {@link MetricsRecorder} implementation that drops every event on the floor. 023 * 024 * <p> 025 * Used whenever no consumer-provided {@code MetricsRecorder} bean is reachable from the 026 * {@code RestContext}'s bean store. Ensures the {@link MetricsRecorder} contract is always satisfied 027 * — the framework can call {@code record(...)} unconditionally without a null-check. 028 * 029 * <p> 030 * The implementation is a single static-field constant ({@link #INSTANCE}); the {@code record(...)} 031 * method does nothing, allocates nothing, and JIT-inlines to an empty method body, so the 032 * off-by-default path has no observable runtime cost. 033 * 034 * @since 10.0.0 035 */ 036@SuppressWarnings({ 037 "java:S6548" // Intentional process-wide no-op singleton; the Singleton pattern is required to satisfy the MetricsRecorder SPI contract with zero allocation. 038}) 039public final class NoOpMetricsRecorder implements MetricsRecorder { 040 041 /** Process-wide singleton instance. */ 042 public static final NoOpMetricsRecorder INSTANCE = new NoOpMetricsRecorder(); 043 044 private NoOpMetricsRecorder() {} 045 046 @Override /* MetricsRecorder */ 047 @SuppressWarnings({ 048 "java:S6213" // 'record' is the established MetricsRecorder SPI method name; renaming would break the public API. 049 }) 050 public void record(String opName, String httpMethod, String uriTemplate, int statusCode, Duration elapsed, Throwable error, String metricName, String metricTags) { 051 // Intentionally empty — the default off-by-default behaviour is to drop every event. 052 } 053}