Class PingsDao
-
- All Implemented Interfaces:
public final class PingsDaoRevamped Data Access Object for managing Pings in the database. Directly uses InMobiDatabaseHelper (similar to AdQualityDao).
-
-
Field Summary
Fields Modifier and Type Field Description public final static StringCOLUMN_PRIORITYpublic final static StringCOLUMN_TIME_CREATEDpublic final static StringCOLUMN_RETRY_COUNTpublic final static StringCOLUMN_RETRY_AFTERpublic final static StringCOLUMN_STATUSpublic final static StringTABLE_NAMEpublic final static StringTABLE_SCHEMA
-
Constructor Summary
Constructors Constructor Description PingsDao(InMobiDatabaseHelper databaseHelper)
-
Method Summary
Modifier and Type Method Description final UnitaddPing(Ping ping)final InsertOutcomereserveAndInsert(Ping ping, Integer maxEntries)Atomically reserves a row slot for ping and inserts it, evicting the oldest existing row of an eligible priority when the maxEntries cap is reached. final UnitremovePing(Ping ping)final UnitupdatePing(Ping ping)final IntegergetCount(String priority)final IntegergetCount()final List<Ping>getPingsEligibleForRetry(String priority, Integer limit)final List<Ping>getUnExecutedFreshPings(Integer limit, String priority, Long createdAt)final List<Ping>getPingsByStatus(String priority, String status, Integer limit)Returns pings whose Ping.status equals status for the given priority. final List<Ping>getAllPings(String priority, Integer limit)final UnitresetStaleStatus()final UnitclearTable()final List<Pair<String, Integer>>deleteExpiredPings(Long normalExpirationTime, Long highExpirationTime)Deletes expired pings across priorities using their own expiry windows. -
-
Constructor Detail
-
PingsDao
PingsDao(InMobiDatabaseHelper databaseHelper)
-
-
Method Detail
-
reserveAndInsert
final InsertOutcome reserveAndInsert(Ping ping, Integer maxEntries)
Atomically reserves a row slot for ping and inserts it, evicting the oldest existing row of an eligible priority when the maxEntries cap is reached. The happy path — count check + insert — is a single SQL statement (conditional
INSERT ... SELECT ... WHERE (SELECT COUNT(*) ...) < ?), so two pings arriving on different coroutines can't both readcount<maxEntriesand both insert. The eviction fallback runs as separate statements inside a transaction so the SELECT-oldest + DELETE + INSERT triple is also atomic against other writers.Eviction policy:
Inserting HIGH: try evicting the oldest NORMAL row first; if none exists, evict the oldest HIGH row.
Inserting NORMAL: evict the oldest NORMAL row only. A NORMAL insert never displaces a HIGH row.
The DAO stays telemetry-free — the caller inspects InsertOutcome and submits the appropriate ping duplicate / eviction / cap-reached events.
-
removePing
final Unit removePing(Ping ping)
-
updatePing
final Unit updatePing(Ping ping)
-
getPingsEligibleForRetry
final List<Ping> getPingsEligibleForRetry(String priority, Integer limit)
-
getUnExecutedFreshPings
final List<Ping> getUnExecutedFreshPings(Integer limit, String priority, Long createdAt)
-
getPingsByStatus
final List<Ping> getPingsByStatus(String priority, String status, Integer limit)
Returns pings whose Ping.status equals status for the given priority. Used by the normal ping offline branch to pull only IDLE rows (skipping FAILED retries while there is no network).
-
getAllPings
final List<Ping> getAllPings(String priority, Integer limit)
-
resetStaleStatus
final Unit resetStaleStatus()
-
clearTable
final Unit clearTable()
-
-
-
-