|
21 | 21 | public class OpenFeatureAPI implements EventBus<OpenFeatureAPI> { |
22 | 22 | // package-private multi-read/single-write lock |
23 | 23 | static AutoCloseableReentrantReadWriteLock lock = new AutoCloseableReentrantReadWriteLock(); |
24 | | - private EvaluationContext evaluationContext; |
25 | 24 | private final List<Hook> apiHooks; |
26 | | - private ProviderRepository providerRepository = new ProviderRepository(); |
27 | | - private EventSupport eventSupport = new EventSupport(); |
| 25 | + private ProviderRepository providerRepository; |
| 26 | + private EventSupport eventSupport; |
| 27 | + private EvaluationContext evaluationContext; |
28 | 28 |
|
29 | 29 | protected OpenFeatureAPI() { |
30 | 30 | apiHooks = new ArrayList<>(); |
| 31 | + providerRepository = new ProviderRepository(); |
| 32 | + eventSupport = new EventSupport(); |
31 | 33 | } |
32 | 34 |
|
33 | 35 | private static class SingletonHolder { |
@@ -190,9 +192,19 @@ public void clearHooks() { |
190 | 192 | } |
191 | 193 | } |
192 | 194 |
|
| 195 | + /** |
| 196 | + * Shut down and reset the current status of OpenFeature API. |
| 197 | + * This call cleans up all active providers and attempts to shut down internal event handling mechanisms. |
| 198 | + * Once shut down is complete, API is reset and ready to use again. |
| 199 | + * */ |
193 | 200 | public void shutdown() { |
194 | | - providerRepository.shutdown(); |
195 | | - eventSupport.shutdown(); |
| 201 | + try (AutoCloseableLock __ = lock.writeLockAutoCloseable()) { |
| 202 | + providerRepository.shutdown(); |
| 203 | + eventSupport.shutdown(); |
| 204 | + |
| 205 | + providerRepository = new ProviderRepository(); |
| 206 | + eventSupport = new EventSupport(); |
| 207 | + } |
196 | 208 | } |
197 | 209 |
|
198 | 210 | /** |
@@ -264,15 +276,6 @@ void addHandler(String clientName, ProviderEvent event, Consumer<EventDetails> h |
264 | 276 | } |
265 | 277 | } |
266 | 278 |
|
267 | | - /** |
268 | | - * This method is only here for testing as otherwise all tests after the API |
269 | | - * shutdown test would fail. |
270 | | - */ |
271 | | - final void reset() { |
272 | | - providerRepository = new ProviderRepository(); |
273 | | - eventSupport = new EventSupport(); |
274 | | - } |
275 | | - |
276 | 279 | /** |
277 | 280 | * Runs the handlers associated with a particular provider. |
278 | 281 | * |
|
0 commit comments