TP-0000 | Concurrent Hashmap fix in Pulse (#7385)

This commit is contained in:
rahul bhat
2023-08-02 15:17:22 +05:30
committed by GitHub
parent 1425d9c330
commit d84ac14b7c
4 changed files with 16 additions and 13 deletions

View File

@@ -11,6 +11,7 @@ import android.content.Context
import com.navi.pulse.event.PulseEventManager
import com.navi.pulse.network.PulseRetrofitProvider
import com.navi.pulse.util.PulseLogger
import java.util.concurrent.ConcurrentHashMap
/**
* A helper class that apps can interact with
@@ -36,7 +37,15 @@ object PulseHelper {
fun trackEvent(eventName: String, properties: Map<String, String>? = null) {
if (eventName.isEmpty()) return
PulseLogger.log("PULSE_EVENT : ", eventName.plus(" ").plus(properties?.toString()))
PulseEventManager.trackEvent(eventName, properties, applicationContext)
//PulseLogger.log("PULSE_EVENT : ", eventName.plus(" ").plus(properties?.toString()))
val propertiesConcurrentHashMap : ConcurrentHashMap<String, String> = ConcurrentHashMap()
properties?.let {
val iterator = it.entries.iterator()
while (iterator.hasNext()) {
val (key, value) = iterator.next()
propertiesConcurrentHashMap[key] = value
}
}
PulseEventManager.trackEvent(eventName, propertiesConcurrentHashMap, applicationContext)
}
}

View File

@@ -32,6 +32,7 @@ import kotlinx.coroutines.sync.Mutex
import kotlinx.coroutines.sync.withLock
import java.lang.reflect.Type
import java.util.*
import java.util.concurrent.ConcurrentHashMap
import java.util.concurrent.Executors
import java.util.concurrent.TimeUnit
import kotlin.concurrent.fixedRateTimer
@@ -45,7 +46,7 @@ object PulseEventManager {
fun trackEvent(
eventName: String,
properties: Map<String, String>? = null,
properties: ConcurrentHashMap<String, String> = ConcurrentHashMap(),
applicationContext: Context
) {
coroutineDispatcher.executor.execute {

View File

@@ -19,15 +19,7 @@ import java.util.concurrent.ConcurrentHashMap
object PulseUtils {
@WorkerThread
fun buildEvent(eventName: String, properties: Map<String, String>? = null): PulseEvent {
val propertiesConcurrentHashMap: ConcurrentHashMap<String, String> = ConcurrentHashMap()
properties?.let {
val iterator = it.entries.iterator()
while (iterator.hasNext()) {
val (key, value) = iterator.next()
propertiesConcurrentHashMap[key] = value
}
}
fun buildEvent(eventName: String, propertiesConcurrentHashMap: ConcurrentHashMap<String, String> = ConcurrentHashMap()): PulseEvent {
val timeStamp = System.currentTimeMillis()
PulseSDKConfig.getSessionId()?.let { sessionId ->
propertiesConcurrentHashMap[SESSION_ID] = sessionId

View File

@@ -11,6 +11,7 @@ import android.content.Context
import androidx.work.CoroutineWorker
import androidx.work.WorkerParameters
import com.navi.pulse.event.PulseEventManager
import java.util.concurrent.ConcurrentHashMap
/**
* This Worker's only job is to wake up the app,
@@ -20,7 +21,7 @@ class SyncEventsWorker(val context: Context, workerParameters: WorkerParameters)
CoroutineWorker(context, workerParameters) {
override suspend fun doWork(): Result {
PulseEventManager.trackEvent("heartbeat", null, context)
PulseEventManager.trackEvent("heartbeat", ConcurrentHashMap(), context)
return Result.success()
}
}