All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.netflix.spectator.api.NoopRegistry Maven / Gradle / Ivy

There is a newer version: 1.7.21
Show newest version
/*
 * Copyright 2014-2019 Netflix, Inc.
 *
 * Licensed 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.netflix.spectator.api;

import java.util.Collections;
import java.util.Iterator;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;

/**
 * Registry implementation that does nothing. This is typically used to allow for performance tests
 * to see how much overhead is being added by instrumentation. This implementation tries to do the
 * minimum amount possible without requiring code changes for users.
 */
public final class NoopRegistry implements Registry {

  // Since we don't know how callers might be using this a noop implementation
  // of the map could cause unexpected issues.
  private final ConcurrentMap state = new ConcurrentHashMap<>();

  @Override public Clock clock() {
    return Clock.SYSTEM;
  }

  @Override public Id createId(String name) {
    return NoopId.INSTANCE;
  }

  @Override public Id createId(String name, Iterable tags) {
    return NoopId.INSTANCE;
  }

  @Override public void register(Meter meter) {
  }

  @Override public ConcurrentMap state() {
    return state;
  }

  @Override public Counter counter(Id id) {
    return NoopCounter.INSTANCE;
  }

  @Override public DistributionSummary distributionSummary(Id id) {
    return NoopDistributionSummary.INSTANCE;
  }

  @Override public Timer timer(Id id) {
    return NoopTimer.INSTANCE;
  }

  @Override public Gauge gauge(Id id) {
    return NoopGauge.INSTANCE;
  }

  @Override public Gauge maxGauge(Id id) {
    return NoopGauge.INSTANCE;
  }

  @Override public Meter get(Id id) {
    return null;
  }

  @Override public Iterator iterator() {
    return Collections.emptyList().iterator();
  }

  @Override public void propagate(String msg, Throwable t) {
    // Since everything will have the same id when using this registry, it can result
    // in type errors when checking against the state, see #503.
  }

  @Override public void propagate(Throwable t) {
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy