Skip to content

Commit 43ce223

Browse files
Remove GlobalServiceRegistry context qualifier constants (helidon-io#9827)
Remove the following (unreleased) constants to minimize temporary API surface of 4.2.0 - GlobalServiceRegistry.STATIC_CONTEXT_CLASSIFIER - GlobalServiceRegistry.CONTEXT_CLASSIFIER
1 parent 2de63a8 commit 43ce223

5 files changed

Lines changed: 10 additions & 38 deletions

File tree

microprofile/testing/testng/src/main/java/io/helidon/microprofile/testing/testng/HelidonTestNgListener.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@
4040
import io.helidon.microprofile.testing.HelidonTestInfo.MethodInfo;
4141
import io.helidon.microprofile.testing.HelidonTestScope;
4242
import io.helidon.microprofile.testing.Proxies;
43-
import io.helidon.service.registry.GlobalServiceRegistry;
4443
import io.helidon.service.registry.ServiceRegistry;
4544
import io.helidon.service.registry.ServiceRegistryManager;
4645

@@ -302,10 +301,10 @@ private Context staticContext(Class<?> testClass) {
302301
.build();
303302

304303
// self-register, so this context is used even if the current context is some child of it
305-
context.register(GlobalServiceRegistry.STATIC_CONTEXT_CLASSIFIER, context);
304+
context.register("helidon-registry-static-context", context);
306305

307306
// supply registry
308-
context.supply(GlobalServiceRegistry.CONTEXT_QUALIFIER, ServiceRegistry.class,
307+
context.supply("helidon-registry", ServiceRegistry.class,
309308
() -> ServiceRegistryManager.create().registry());
310309

311310
return context;

microprofile/tests/testing/junit5/src/test/java/io/helidon/microprofile/tests/testing/junit5/TestGlobalServiceRegistry.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ void firstTest() {
6969
assertThat(INSTANCES.size(), is(1));
7070
assertThat(INSTANCES.iterator().next(),
7171
is(not(System.identityHashCode(Contexts.globalContext()
72-
.get(GlobalServiceRegistry.CONTEXT_QUALIFIER, ServiceRegistry.class)
72+
.get("helidon-registry", ServiceRegistry.class)
7373
.orElse(null)))));
7474
}
7575

microprofile/tests/testing/testng/src/test/java/io/helidon/microprofile/tests/testing/testng/TestGlobalServiceRegistry.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ void firstTest() {
6969
assertThat(INSTANCES.size(), is(1));
7070
assertThat(INSTANCES.iterator().next(),
7171
is(not(System.identityHashCode(Contexts.globalContext()
72-
.get(GlobalServiceRegistry.CONTEXT_QUALIFIER, ServiceRegistry.class)
72+
.get("helidon-registry", ServiceRegistry.class)
7373
.orElse(null)))));
7474
}
7575

service/registry/src/main/java/io/helidon/service/registry/GlobalServiceRegistry.java

Lines changed: 4 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -25,36 +25,9 @@
2525
import io.helidon.common.context.Contexts;
2626

2727
/**
28-
* Represents an application wide service registry.
29-
* <p>
30-
* The registry instance is shared through {@link io.helidon.common.context.Context}, using the current context
31-
* to obtain a context with classifier {@link #STATIC_CONTEXT_CLASSIFIER}. If such a context is found, the
32-
* registry instance is obtained/stored there. If the context does not exist, the
33-
* {@link io.helidon.common.context.Contexts#globalContext()} is used to store the value.
34-
* <p>
35-
* The first option is designed for testing, to make sure the global registry is only "global" for a single test class.
36-
* The second option is the default for application runtime, where we intend to share the registry as a proper, static
37-
* singleton instance.
38-
* <p>
39-
* Helidon testing libraries support this approach and correctly configure appropriate context for each execution.
28+
* Application wide service registry backed by {@link io.helidon.common.context.Context}.
4029
*/
4130
public final class GlobalServiceRegistry {
42-
/**
43-
* Classifier used to register a context that is to serve as the context that holds the
44-
* global registry instance.
45-
* <p>
46-
* This is to allow testing in parallel, where we need the global registry instance restricted to a single test.
47-
* <p>
48-
* In normal application runtime we use {@link io.helidon.common.context.Contexts#globalContext()}.
49-
*/
50-
public static final Object STATIC_CONTEXT_CLASSIFIER = new Object();
51-
52-
/**
53-
* Classifier used to register the global service registry.
54-
*
55-
* @see #STATIC_CONTEXT_CLASSIFIER
56-
*/
57-
public static final Object CONTEXT_QUALIFIER = new Object();
5831

5932
private static final ReadWriteLock RW_LOCK = new ReentrantReadWriteLock();
6033

@@ -137,7 +110,7 @@ public static ServiceRegistry registry(Supplier<ServiceRegistry> registrySupplie
137110
public static ServiceRegistry registry(ServiceRegistry newGlobalRegistry) {
138111
RW_LOCK.writeLock().lock();
139112
try {
140-
context().register(CONTEXT_QUALIFIER, newGlobalRegistry);
113+
context().register("helidon-registry", newGlobalRegistry);
141114
} finally {
142115
RW_LOCK.writeLock().unlock();
143116
}
@@ -150,14 +123,14 @@ private static Context context() {
150123
// this is the context we expect to get (and set global instances)
151124
return Contexts.context()
152125
.orElse(globalContext)
153-
.get(STATIC_CONTEXT_CLASSIFIER, Context.class)
126+
.get("helidon-registry-static-context", Context.class)
154127
.orElse(globalContext);
155128
}
156129

157130
private static Optional<ServiceRegistry> current() {
158131
RW_LOCK.readLock().lock();
159132
try {
160-
return context().get(CONTEXT_QUALIFIER, ServiceRegistry.class);
133+
return context().get("helidon-registry", ServiceRegistry.class);
161134
} finally {
162135
RW_LOCK.readLock().unlock();
163136
}

testing/junit5/src/main/java/io/helidon/testing/junit5/TestJunitExtension.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -204,10 +204,10 @@ protected void initStaticContext(ExtensionContext.Store store, ExtensionContext
204204
.build();
205205

206206
// self-register, so this context is used even if the current context is some child of it
207-
context.register(GlobalServiceRegistry.STATIC_CONTEXT_CLASSIFIER, context);
207+
context.register("helidon-registry-static-context", context);
208208

209209
// supply registry
210-
context.supply(GlobalServiceRegistry.CONTEXT_QUALIFIER, ServiceRegistry.class, () -> {
210+
context.supply("helidon-registry", ServiceRegistry.class, () -> {
211211
var manager = ServiceRegistryManager.create();
212212
var registry = manager.registry();
213213
store.put(ServiceRegistryManager.class, (CloseableResource) manager::shutdown);

0 commit comments

Comments
 (0)