-
Notifications
You must be signed in to change notification settings - Fork 42
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(android): implement batch insertions of events and spans in db
- Loading branch information
Showing
16 changed files
with
527 additions
and
116 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
56 changes: 56 additions & 0 deletions
56
android/measure/src/main/java/sh/measure/android/storage/PeriodicSignalStoreScheduler.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
package sh.measure.android.storage | ||
|
||
import sh.measure.android.config.ConfigProvider | ||
import sh.measure.android.executors.MeasureExecutorService | ||
import sh.measure.android.logger.LogLevel | ||
import sh.measure.android.logger.Logger | ||
import java.util.concurrent.Future | ||
import java.util.concurrent.RejectedExecutionException | ||
import java.util.concurrent.TimeUnit | ||
|
||
internal class PeriodicSignalStoreScheduler( | ||
private val logger: Logger, | ||
private val defaultExecutor: MeasureExecutorService, | ||
private val ioExecutor: MeasureExecutorService, | ||
private val signalStore: SignalStore, | ||
private val configProvider: ConfigProvider, | ||
) { | ||
|
||
@Volatile | ||
private var future: Future<*>? = null | ||
|
||
fun register() { | ||
if (future != null) { | ||
return | ||
} | ||
try { | ||
future = defaultExecutor.scheduleAtFixedRate( | ||
{ | ||
ioExecutor.submit { | ||
signalStore.flush() | ||
} | ||
}, | ||
initialDelay = configProvider.inMemorySignalsQueueFlushRateMs, | ||
delayMillis = configProvider.inMemorySignalsQueueFlushRateMs, | ||
TimeUnit.MILLISECONDS, | ||
) | ||
} catch (e: RejectedExecutionException) { | ||
logger.log(LogLevel.Error, "Failed to start periodic signal store scheduler", e) | ||
return | ||
} | ||
} | ||
|
||
fun unregister() { | ||
future?.cancel(false) | ||
future = null | ||
ioExecutor.submit { | ||
signalStore.flush() | ||
} | ||
} | ||
|
||
fun onAppBackground() { | ||
ioExecutor.submit { | ||
signalStore.flush() | ||
} | ||
} | ||
} |
Oops, something went wrong.