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

grpc / grpc-java / #19192

06 May 2024 02:27PM UTC coverage: 88.351% (+0.06%) from 88.287%
#19192

push

github

web-flow
Migrate GlobalInterceptors to ConfiguratorRegistry

This should preserve all the existing behavior of GlobalInterceptors as
used by grpc-gcp-observability, including it disabling the implicit
OpenCensus integration.

Both the old and new API are internal. I hid Configurator and
ConfiguratorRegistry behind Internal-prefixed classes, like had been
done with GlobalInterceptors to further discourage use until the API is
ready.

GlobalInterceptorsTest was modified to become ConfiguratorRegistryTest.

31512 of 35667 relevant lines covered (88.35%)

0.88 hits per line

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

60.0
/../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 java.util.ArrayList;
20
import java.util.Collections;
21
import java.util.List;
22
import javax.annotation.concurrent.GuardedBy;
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")
36
  private boolean configFrozen;
37
  @GuardedBy("this")
1✔
38
  private List<Configurator> configurators = Collections.emptyList();
1✔
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 (configFrozen) {
×
60
      throw new IllegalStateException("Configurators are already set");
×
61
    }
62
    this.configurators = Collections.unmodifiableList(new ArrayList<>(configurators));
×
63
    configFrozen = true;
×
64
    wasConfiguratorsSet = true;
×
65
  }
×
66

67
  /**
68
   * Returns a list of the configurators in this registry.
69
   */
70
  public synchronized List<Configurator> getConfigurators() {
71
    configFrozen = true;
1✔
72
    return configurators;
1✔
73
  }
74

75
  public synchronized boolean wasSetConfiguratorsCalled() {
76
    return wasConfiguratorsSet;
1✔
77
  }
78
}
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