Class PingResolutionStrategy
-
- All Implemented Interfaces:
public abstract class PingResolutionStrategyAbstract base class for ping resolution strategies. It handles common functionalities like managing database capacity based on configuration.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description public interfacePingResolutionStrategy.PingResolutionListenerInterface for listeners that want to be notified about ping resolution outcomes. Typically used by strategies that resolve pings immediately.
-
Field Summary
Fields Modifier and Type Field Description public final static StringDB_CAPACITY_EXCEEDEDpublic final static StringREDIRECT_MALFORMEDprivate final ConcurrentHashMap<String, WeakReference<PingResolutionStrategy.PingResolutionListener>>listeners
-
Constructor Summary
Constructors Constructor Description PingResolutionStrategy(PingsDao dao)
-
Method Summary
Modifier and Type Method Description final ConcurrentHashMap<String, WeakReference<PingResolutionStrategy.PingResolutionListener>>getListeners()final BooleanreservePing(Ping ping)Atomically persists ping (with caller-set status) into the pings DB, evicting an oldest displaceable row if the maxEntries cap is reached, and emits the matching telemetry event. final UnitaddListener(String id, PingResolutionStrategy.PingResolutionListener listener)final UnitremoveListener(String id)final UnitresolvePing(Ping ping)abstract UnitstartProcessing()Starts any executor or background process associated with this strategy. abstract UnitstopProcessing()Stops any executor or background process associated with this strategy. final UnitsetNetworkHandler(OkHttpPingNetworkHandler networkHandler)-
-
Constructor Detail
-
PingResolutionStrategy
PingResolutionStrategy(PingsDao dao)
-
-
Method Detail
-
getListeners
final ConcurrentHashMap<String, WeakReference<PingResolutionStrategy.PingResolutionListener>> getListeners()
-
reservePing
final Boolean reservePing(Ping ping)
Atomically persists ping (with caller-set status) into the pings DB, evicting an oldest displaceable row if the maxEntries cap is reached, and emits the matching telemetry event. Returns true if the row is in the DB after this call, false if the cap was met and no row could be displaced.
Replaces the previous
hasSpaceInDB(priority) → addPing(...)pair, whose read-decide-write window letPingManager's per-pingHIGH_PRIORITY_SCOPE.launchfan-out interleave: two pings could both readcount<maxEntries, both skip eviction, and both insert, leaving the table above the cap. PingsDao.reserveAndInsert does the count check + insert in a single SQL statement and runs the eviction fallback inside a transaction, so the race is gone.
-
addListener
final Unit addListener(String id, PingResolutionStrategy.PingResolutionListener listener)
-
removeListener
final Unit removeListener(String id)
-
resolvePing
final Unit resolvePing(Ping ping)
-
startProcessing
abstract Unit startProcessing()
Starts any executor or background process associated with this strategy.
-
stopProcessing
abstract Unit stopProcessing()
Stops any executor or background process associated with this strategy.
-
setNetworkHandler
final Unit setNetworkHandler(OkHttpPingNetworkHandler networkHandler)
-
-
-
-