2
2
3
3
import dev .openfeature .sdk .EvaluationContext ;
4
4
import dev .openfeature .sdk .ImmutableContext ;
5
- import dev .openfeature .sdk .ImmutableStructure ;
6
5
import dev .openfeature .sdk .ProviderEvent ;
7
- import dev .openfeature .sdk .Structure ;
8
6
import dev .openfeature .sdk .exceptions .GeneralError ;
9
7
import lombok .Getter ;
10
8
import lombok .Setter ;
11
- import lombok .extern .slf4j .Slf4j ;
12
9
13
10
/**
14
11
* Contains all fields we need to worry about locking, used as intrinsic lock
15
12
* for sync blocks in the {@link FlagdProvider}.
16
13
*/
17
- @ Slf4j
18
14
@ Getter
19
15
class FlagdProviderSyncResources {
20
16
@ Setter
21
17
private volatile ProviderEvent previousEvent = null ;
22
18
23
- private volatile ImmutableStructure syncMetadata = new ImmutableStructure ();
24
19
private volatile EvaluationContext enrichedContext = new ImmutableContext ();
25
20
private volatile boolean initialized ;
26
21
private volatile boolean isShutDown ;
27
22
28
- public void setSyncMetadata (Structure syncMetadata ) {
29
- this .syncMetadata = new ImmutableStructure (syncMetadata .asMap ());
30
- }
31
-
32
23
public void setEnrichedContext (EvaluationContext context ) {
33
24
this .enrichedContext = new ImmutableContext (context .asMap ());
34
25
}
@@ -40,14 +31,11 @@ public void setEnrichedContext(EvaluationContext context) {
40
31
* @return true iff this was the first call to {@code initialize()}
41
32
*/
42
33
public synchronized boolean initialize () {
43
- log .info ("initialize in wait" );
44
34
if (this .initialized ) {
45
35
return false ;
46
36
}
47
37
this .initialized = true ;
48
38
this .notifyAll ();
49
- log .info ("notified all " + this .toString ());
50
-
51
39
return true ;
52
40
}
53
41
@@ -66,7 +54,6 @@ public synchronized boolean initialize() {
66
54
* this object
67
55
*/
68
56
public void waitForInitialization (long deadline ) {
69
- log .info ("wait for init " + this );
70
57
long start = System .currentTimeMillis ();
71
58
long end = start + deadline ;
72
59
while (!initialized && !isShutDown ) {
@@ -78,34 +65,29 @@ public void waitForInitialization(long deadline) {
78
65
}
79
66
long remaining = end - now ;
80
67
synchronized (this ) {
81
- if (initialized ) { // might have changed in the meantime
82
- log .info ("post wait for init in loop" );
83
- return ;
84
- }
85
68
if (isShutDown ) {
86
69
break ;
87
70
}
88
- log .info ("waiting for " + remaining + " at " + System .currentTimeMillis ());
71
+ if (initialized ) { // might have changed in the meantime
72
+ return ;
73
+ }
89
74
try {
90
75
this .wait (remaining );
91
76
} catch (InterruptedException e ) {
92
77
// try again. Leave the continue to make PMD happy
93
78
continue ;
94
79
}
95
- log .info ("waiting ended at " + System .currentTimeMillis ());
96
80
}
97
81
}
98
82
if (isShutDown ) {
99
83
throw new IllegalStateException ("Already shut down" );
100
84
}
101
- log .info ("post wait for init" );
102
85
}
103
86
104
87
/**
105
88
* Signals a shutdown. Threads waiting for initialization will wake up and throw an {@link IllegalStateException}.
106
89
*/
107
90
public synchronized void shutdown () {
108
- log .info ("shutdown in wait" );
109
91
isShutDown = true ;
110
92
this .notifyAll ();
111
93
}
0 commit comments