@@ -88,6 +88,8 @@ public class MapboxEventManager {
88
88
private static long flushDelayInMillis = 1000 * 60 * 3 ; // 3 Minutes
89
89
private static final int SESSION_ID_ROTATION_HOURS = 24 ;
90
90
91
+ private static final int FLUSH_EVENTS_CAP = 1000 ;
92
+
91
93
private static MessageDigest messageDigest = null ;
92
94
93
95
private static final double locationEventAccuracy = 10000000 ;
@@ -310,6 +312,21 @@ void flushEventsQueueImmediately() {
310
312
new FlushTheEventsTask ().execute ();
311
313
}
312
314
315
+ /**
316
+ * Centralized method for adding populated event to the queue allowing for cap size checking
317
+ * @param event Event to add to the Events Queue
318
+ */
319
+ private void putEventOnQueue (@ NonNull Hashtable <String , Object > event ) {
320
+ if (event == null ) {
321
+ return ;
322
+ }
323
+ events .add (event );
324
+ if (events .size () == FLUSH_EVENTS_CAP ) {
325
+ Log .d (TAG , "eventsSize == flushCap so send data." );
326
+ flushEventsQueueImmediately ();
327
+ }
328
+ }
329
+
313
330
/**
314
331
* Adds a Location Event to the system for processing
315
332
* @param location Location event
@@ -337,7 +354,7 @@ public void addLocationEvent(Location location) {
337
354
event .put (MapboxEvent .ATTRIBUTE_OPERATING_SYSTEM , operatingSystem );
338
355
event .put (MapboxEvent .ATTRIBUTE_APPLICATION_STATE , getApplicationState ());
339
356
340
- events . add (event );
357
+ putEventOnQueue (event );
341
358
342
359
rotateSessionId ();
343
360
}
@@ -376,7 +393,7 @@ public void pushEvent(Hashtable<String, Object> eventWithAttributes) {
376
393
eventWithAttributes .put (MapboxEvent .ATTRIBUTE_WIFI , getConnectedToWifi ());
377
394
378
395
// Put Map Load on events before Turnstile clears it
379
- events . add (eventWithAttributes );
396
+ putEventOnQueue (eventWithAttributes );
380
397
381
398
// Turnstile
382
399
pushTurnstileEvent ();
@@ -403,7 +420,7 @@ public void pushEvent(Hashtable<String, Object> eventWithAttributes) {
403
420
return ;
404
421
}
405
422
406
- events . add (eventWithAttributes );
423
+ putEventOnQueue (eventWithAttributes );
407
424
}
408
425
409
426
/**
0 commit comments