5
5
import dev .openfeature .sdk .internal .AutoCloseableReentrantReadWriteLock ;
6
6
import lombok .extern .slf4j .Slf4j ;
7
7
8
- import java .util .ArrayList ;
9
- import java .util .Arrays ;
10
- import java .util .List ;
11
- import java .util .Optional ;
12
- import java .util .Set ;
8
+ import java .util .*;
13
9
import java .util .function .Consumer ;
14
10
15
11
/**
@@ -69,7 +65,7 @@ public Metadata getProviderMetadata(String domain) {
69
65
}
70
66
71
67
/**
72
- * A factory function for creating new, OpenFeature clients .
68
+ * A factory function for creating new, OpenFeature client .
73
69
* Clients can contain their own state (e.g. logger, hook, context).
74
70
* Multiple clients can be used to segment feature flag configuration.
75
71
* All un-named or unbound clients use the default provider.
@@ -81,12 +77,12 @@ public Client getClient() {
81
77
}
82
78
83
79
/**
84
- * A factory function for creating new domainless OpenFeature clients .
80
+ * A factory function for creating new domainless OpenFeature client .
85
81
* Clients can contain their own state (e.g. logger, hook, context).
86
82
* Multiple clients can be used to segment feature flag configuration.
87
83
* If there is already a provider bound to this domain, this provider will be used.
88
84
* Otherwise, the default provider is used until a provider is assigned to that domain.
89
- *
85
+ *
90
86
* @param domain an identifier which logically binds clients with providers
91
87
* @return a new client instance
92
88
*/
@@ -95,20 +91,22 @@ public Client getClient(String domain) {
95
91
}
96
92
97
93
/**
98
- * A factory function for creating new domainless OpenFeature clients .
94
+ * A factory function for creating new domainless OpenFeature client .
99
95
* Clients can contain their own state (e.g. logger, hook, context).
100
96
* Multiple clients can be used to segment feature flag configuration.
101
97
* If there is already a provider bound to this domain, this provider will be used.
102
98
* Otherwise, the default provider is used until a provider is assigned to that domain.
103
- *
104
- * @param domain a identifier which logically binds clients with providers
99
+ *
100
+ * @param domain a identifier which logically binds clients with providers
105
101
* @param version a version identifier
106
102
* @return a new client instance
107
103
*/
108
104
public Client getClient (String domain , String version ) {
109
- return new OpenFeatureClient (this ,
105
+ return new OpenFeatureClient (
106
+ this ,
110
107
domain ,
111
- version );
108
+ version
109
+ );
112
110
}
113
111
114
112
/**
@@ -193,8 +191,8 @@ public void setProvider(FeatureProvider provider) {
193
191
/**
194
192
* Add a provider for a domain.
195
193
*
196
- * @param domain The domain to bind the provider to.
197
- * @param provider The provider to set.
194
+ * @param domain The domain to bind the provider to.
195
+ * @param provider The provider to set.
198
196
*/
199
197
public void setProvider (String domain , FeatureProvider provider ) {
200
198
try (AutoCloseableLock __ = lock .writeLockAutoCloseable ()) {
@@ -226,8 +224,8 @@ public void setProviderAndWait(FeatureProvider provider) throws OpenFeatureError
226
224
/**
227
225
* Add a provider for a domain and wait for initialization to finish.
228
226
*
229
- * @param domain The domain to bind the provider to.
230
- * @param provider The provider to set.
227
+ * @param domain The domain to bind the provider to.
228
+ * @param provider The provider to set.
231
229
*/
232
230
public void setProviderAndWait (String domain , FeatureProvider provider ) throws OpenFeatureError {
233
231
try (AutoCloseableLock __ = lock .writeLockAutoCloseable ()) {
@@ -300,6 +298,7 @@ public void addHooks(Hook... hooks) {
300
298
301
299
/**
302
300
* Fetch the hooks associated to this client.
301
+ *
303
302
* @return A list of {@link Hook}s.
304
303
*/
305
304
public List <Hook > getHooks () {
@@ -394,17 +393,21 @@ void removeHandler(String domain, ProviderEvent event, Consumer<EventDetails> ha
394
393
void addHandler (String domain , ProviderEvent event , Consumer <EventDetails > handler ) {
395
394
try (AutoCloseableLock __ = lock .writeLockAutoCloseable ()) {
396
395
// if the provider is in the state associated with event, run immediately
397
- if (Optional .ofNullable (this .providerRepository .getProvider (domain ). getState ( ))
396
+ if (Optional .ofNullable (this .providerRepository .getProviderState (domain ))
398
397
.orElse (ProviderState .READY ).matchesEvent (event )) {
399
398
eventSupport .runHandler (handler , EventDetails .builder ().domain (domain ).build ());
400
399
}
401
400
eventSupport .addClientHandler (domain , event , handler );
402
401
}
403
402
}
404
403
404
+ FeatureProviderStateManager getFeatureProviderStateManager (String domain ) {
405
+ return providerRepository .getFeatureProviderStateManager (domain );
406
+ }
407
+
405
408
/**
406
409
* Runs the handlers associated with a particular provider.
407
- *
410
+ *
408
411
* @param provider the provider from where this event originated
409
412
* @param event the event type
410
413
* @param details the event details
0 commit comments