• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

grpc / grpc-java / #19763

04 Apr 2025 05:53AM UTC coverage: 88.616% (+0.02%) from 88.598%
#19763

push

github

web-flow
refactor: prevents global stats config freeze in ConfiguratorRegistry.getConfigurators() (#11991)

34742 of 39205 relevant lines covered (88.62%)

0.89 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

64.71
/../api/src/main/java/io/grpc/ConfiguratorRegistry.java
1
/*
2
 * Copyright 2024 The gRPC Authors
3
 *
4
 * Licensed under the Apache License, Version 2.0 (the "License");
5
 * you may not use this file except in compliance with the License.
6
 * You may obtain a copy of the License at
7
 *
8
 *     http://www.apache.org/licenses/LICENSE-2.0
9
 *
10
 * Unless required by applicable law or agreed to in writing, software
11
 * distributed under the License is distributed on an "AS IS" BASIS,
12
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
 * See the License for the specific language governing permissions and
14
 * limitations under the License.
15
 */
16

17
package io.grpc;
18

19
import com.google.errorprone.annotations.concurrent.GuardedBy;
20
import java.util.ArrayList;
21
import java.util.Collections;
22
import java.util.List;
23

24
/**
25
 * A registry for {@link Configurator} instances.
26
 *
27
 * <p>This class is responsible for maintaining a list of configurators and providing access to
28
 * them. The default registry can be obtained using {@link #getDefaultRegistry()}.
29
 */
30
final class ConfiguratorRegistry {
31
  private static ConfiguratorRegistry instance;
32

33
  @GuardedBy("this")
34
  private boolean wasConfiguratorsSet;
35
  @GuardedBy("this")
1✔
36
  private List<Configurator> configurators = Collections.emptyList();
1✔
37
  @GuardedBy("this")
1✔
38
  private int configuratorsCallCountBeforeSet = 0;
39

40
  ConfiguratorRegistry() {}
1✔
41

42
  /**
43
   * Returns the default global instance of the configurator registry.
44
   */
45
  public static synchronized ConfiguratorRegistry getDefaultRegistry() {
46
    if (instance == null) {
1✔
47
      instance = new ConfiguratorRegistry();
1✔
48
    }
49
    return instance;
1✔
50
  }
51

52
  /**
53
   * Sets the configurators in this registry. This method can only be called once.
54
   *
55
   * @param configurators the configurators to set
56
   * @throws IllegalStateException if this method is called more than once
57
   */
58
  public synchronized void setConfigurators(List<? extends Configurator> configurators) {
59
    if (wasConfiguratorsSet) {
×
60
      throw new IllegalStateException("Configurators are already set");
×
61
    }
62
    this.configurators = Collections.unmodifiableList(new ArrayList<>(configurators));
×
63
    wasConfiguratorsSet = true;
×
64
  }
×
65

66
  /**
67
   * Returns a list of the configurators in this registry.
68
   */
69
  public synchronized List<Configurator> getConfigurators() {
70
    if (!wasConfiguratorsSet) {
1✔
71
      configuratorsCallCountBeforeSet++;
1✔
72
    }
73
    return configurators;
1✔
74
  }
75

76
  /**
77
   * Returns the number of times getConfigurators() was called before
78
   * setConfigurators() was successfully invoked.
79
   */
80
  public synchronized int getConfiguratorsCallCountBeforeSet() {
81
    return configuratorsCallCountBeforeSet;
×
82
  }
83

84
  public synchronized boolean wasSetConfiguratorsCalled() {
85
    return wasConfiguratorsSet;
1✔
86
  }
87
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc