@@ -51,6 +51,27 @@ public Event add(Object element) {
5151 }
5252 }
5353
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+
5475 @ JsonAdapter (FlagEventSerializer .class )
5576 final static class FlagEvent extends Event {
5677 private final List <FlagEventVariation > userVariations = new ArrayList <>();
@@ -170,6 +191,13 @@ public String getAppType() {
170191 }
171192 }
172193
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+
173201 final static class FlagEventSerializer implements JsonSerializer <FlagEvent > {
174202
175203 @ Override
@@ -181,7 +209,7 @@ public JsonElement serialize(FlagEvent flagEvent, Type type, JsonSerializationCo
181209 JsonObject var = new JsonObject ();
182210 var .addProperty ("featureFlagKey" , variation .getFeatureFlagKeyName ());
183211 var .addProperty ("sendToExperiment" , variation .getVariation ().isSendToExperiment ());
184- var .addProperty ("timestamp" , Instant . now (). toEpochMilli ());
212+ var .addProperty ("timestamp" , variation . getTimestamp ());
185213 JsonObject v = new JsonObject ();
186214 v .addProperty ("id" , variation .getVariation ().getIndex ());
187215 v .addProperty ("value" , variation .getVariation ().getValue ());
@@ -232,26 +260,28 @@ private static JsonObject serializeUser(FBUser user) {
232260 }
233261
234262 enum InsightMessageType {
235- FLAGS , FLUSH , SHUTDOWN , METRICS ,
263+ FLAGS , FLUSH , SHUTDOWN , METRICS , USERS , STATISTICS
236264 }
237265
238266 static final class InsightMessage {
239267 private final InsightMessageType type ;
240268 private final Event event ;
241- private final Semaphore waitLock ;
269+ private final Object waitLock ;
242270
243271 // waitLock is initialized only when you need to wait until the message is completely handled
244272 // 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 ) {
246274 this .type = type ;
247275 this .event = event ;
248276 // permit = 0, so wait until a permit releases
249- this .waitLock = awaitTermination ? new Semaphore ( 0 ) : null ;
277+ this .waitLock = awaitToComplete ? new Object ( ) : null ;
250278 }
251279
252280 public void completed () {
253281 if (waitLock != null ) {
254- waitLock .release ();
282+ synchronized (waitLock ) {
283+ waitLock .notifyAll ();
284+ }
255285 }
256286 }
257287
@@ -260,10 +290,12 @@ public void waitForComplete() {
260290 return ;
261291 }
262292 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+ }
267299 }
268300 }
269301
0 commit comments