Skip to content
This repository was archived by the owner on Aug 8, 2023. It is now read-only.

Commit 5fb0e87

Browse files
committedJul 14, 2016
[android] #5680 - Adding 1000 event cap to send telemetry data
1 parent 5300488 commit 5fb0e87

File tree

1 file changed

+20
-3
lines changed

1 file changed

+20
-3
lines changed
 

‎platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/telemetry/MapboxEventManager.java

+20-3
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,8 @@ public class MapboxEventManager {
8888
private static long flushDelayInMillis = 1000 * 60 * 3; // 3 Minutes
8989
private static final int SESSION_ID_ROTATION_HOURS = 24;
9090

91+
private static final int FLUSH_EVENTS_CAP = 1000;
92+
9193
private static MessageDigest messageDigest = null;
9294

9395
private static final double locationEventAccuracy = 10000000;
@@ -310,6 +312,21 @@ void flushEventsQueueImmediately() {
310312
new FlushTheEventsTask().execute();
311313
}
312314

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+
313330
/**
314331
* Adds a Location Event to the system for processing
315332
* @param location Location event
@@ -337,7 +354,7 @@ public void addLocationEvent(Location location) {
337354
event.put(MapboxEvent.ATTRIBUTE_OPERATING_SYSTEM, operatingSystem);
338355
event.put(MapboxEvent.ATTRIBUTE_APPLICATION_STATE, getApplicationState());
339356

340-
events.add(event);
357+
putEventOnQueue(event);
341358

342359
rotateSessionId();
343360
}
@@ -376,7 +393,7 @@ public void pushEvent(Hashtable<String, Object> eventWithAttributes) {
376393
eventWithAttributes.put(MapboxEvent.ATTRIBUTE_WIFI, getConnectedToWifi());
377394

378395
// Put Map Load on events before Turnstile clears it
379-
events.add(eventWithAttributes);
396+
putEventOnQueue(eventWithAttributes);
380397

381398
// Turnstile
382399
pushTurnstileEvent();
@@ -403,7 +420,7 @@ public void pushEvent(Hashtable<String, Object> eventWithAttributes) {
403420
return;
404421
}
405422

406-
events.add(eventWithAttributes);
423+
putEventOnQueue(eventWithAttributes);
407424
}
408425

409426
/**

0 commit comments

Comments
 (0)
This repository has been archived.