@@ -51,6 +51,27 @@ public Event add(Object element) {
51
51
}
52
52
}
53
53
54
+ @ JsonAdapter (UserEventSerializer .class )
55
+ final static class UserEvent extends Event {
56
+ private UserEvent (FBUser user ) {
57
+ super (user );
58
+ }
59
+
60
+ static UserEvent of (FBUser user ) {
61
+ return new UserEvent (user );
62
+ }
63
+
64
+ @ Override
65
+ public boolean isSendEvent () {
66
+ return user != null ;
67
+ }
68
+
69
+ @ Override
70
+ public Event add (Object element ) {
71
+ return this ;
72
+ }
73
+ }
74
+
54
75
@ JsonAdapter (FlagEventSerializer .class )
55
76
final static class FlagEvent extends Event {
56
77
private final List <FlagEventVariation > userVariations = new ArrayList <>();
@@ -170,6 +191,13 @@ public String getAppType() {
170
191
}
171
192
}
172
193
194
+ final static class UserEventSerializer implements JsonSerializer <UserEvent > {
195
+ @ Override
196
+ public JsonElement serialize (UserEvent userEvent , Type type , JsonSerializationContext jsonSerializationContext ) {
197
+ return serializeUser (userEvent .getUser ());
198
+ }
199
+ }
200
+
173
201
final static class FlagEventSerializer implements JsonSerializer <FlagEvent > {
174
202
175
203
@ Override
@@ -181,7 +209,7 @@ public JsonElement serialize(FlagEvent flagEvent, Type type, JsonSerializationCo
181
209
JsonObject var = new JsonObject ();
182
210
var .addProperty ("featureFlagKey" , variation .getFeatureFlagKeyName ());
183
211
var .addProperty ("sendToExperiment" , variation .getVariation ().isSendToExperiment ());
184
- var .addProperty ("timestamp" , Instant . now (). toEpochMilli ());
212
+ var .addProperty ("timestamp" , variation . getTimestamp ());
185
213
JsonObject v = new JsonObject ();
186
214
v .addProperty ("id" , variation .getVariation ().getIndex ());
187
215
v .addProperty ("value" , variation .getVariation ().getValue ());
@@ -232,26 +260,28 @@ private static JsonObject serializeUser(FBUser user) {
232
260
}
233
261
234
262
enum InsightMessageType {
235
- FLAGS , FLUSH , SHUTDOWN , METRICS ,
263
+ FLAGS , FLUSH , SHUTDOWN , METRICS , USERS , STATISTICS
236
264
}
237
265
238
266
static final class InsightMessage {
239
267
private final InsightMessageType type ;
240
268
private final Event event ;
241
- private final Semaphore waitLock ;
269
+ private final Object waitLock ;
242
270
243
271
// waitLock is initialized only when you need to wait until the message is completely handled
244
272
// Ex, shutdown, in this case, we should to wait until all events are sent to server
245
- InsightMessage (InsightMessageType type , Event event , boolean awaitTermination ) {
273
+ InsightMessage (InsightMessageType type , Event event , boolean awaitToComplete ) {
246
274
this .type = type ;
247
275
this .event = event ;
248
276
// permit = 0, so wait until a permit releases
249
- this .waitLock = awaitTermination ? new Semaphore ( 0 ) : null ;
277
+ this .waitLock = awaitToComplete ? new Object ( ) : null ;
250
278
}
251
279
252
280
public void completed () {
253
281
if (waitLock != null ) {
254
- waitLock .release ();
282
+ synchronized (waitLock ) {
283
+ waitLock .notifyAll ();
284
+ }
255
285
}
256
286
}
257
287
@@ -260,10 +290,12 @@ public void waitForComplete() {
260
290
return ;
261
291
}
262
292
while (true ) {
263
- try {
264
- waitLock .acquire ();
265
- return ;
266
- } catch (InterruptedException ignore ) {
293
+ synchronized (waitLock ) {
294
+ try {
295
+ waitLock .wait ();
296
+ return ;
297
+ } catch (InterruptedException ignore ) {
298
+ }
267
299
}
268
300
}
269
301
0 commit comments