Class EmissionGate
State is held per key. The key must identify one logical signal: callers that serve
multiple devices through a single gate instance must include the device id in the key (e.g.
"<deviceID>.<channelID>"), otherwise identically named channels on different devices
share one throttle slot and suppress each other.
Two independent filters, both applied when enabled; a value is emitted only if it passes both:
- minIntervalMs — at most one emission per key per interval;
- onChange — suppress repeats of the last emitted value for a key.
Checking and committing are separate steps: allows(java.lang.String, java.lang.Object, long) is a side-effect-free check;
the two filters' state is committed independently. Callers performing fallible I/O should
commitAttempt(java.lang.String, long) the interval state when they start an emission attempt (so a
failing endpoint is probed at most once per interval instead of once per sample) and
commitValue(java.lang.String, java.lang.Object) the onChange state only after the receiver accepted the value (so
a failed or rejected send does not suppress an identical follow-up value). commit(java.lang.String, java.lang.Object, long) does
both at once; allow(java.lang.String, java.lang.Object, long) combines check and full commit for callers whose emission cannot
fail after the check. The check-then-commit pair is not atomic; concurrent callers may
occasionally both pass the check, which for a throttle is an acceptable extra emission (never a
loss).
With both filters disabled the gate is a pass-through. The clock is supplied by the caller so behaviour is deterministic in tests.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionbooleanbooleanChecks whethervalueonkeymay be emitted now, without recording anything.voidRecords a completed emission ofvalueonkey: both filters' state at once (commitAttempt(java.lang.String, long)+commitValue(java.lang.String, java.lang.Object)).voidcommitAttempt(String key, long nowMs) Records an emission attempt onkey: only the interval filter's state.voidcommitValue(String key, Object value) Records a delivered value onkey: only the onChange filter's state.static StringThe canonical device-scoped emission key (see class doc).static EmissionGateA pass-through gate that never suppresses.
-
Constructor Details
-
EmissionGate
public EmissionGate(boolean onChange, long minIntervalMs) - Parameters:
onChange- if true, suppress consecutive equal values per keyminIntervalMs- minimum milliseconds between emissions per key (0 disables the filter)
-
-
Method Details
-
passthrough
A pass-through gate that never suppresses. -
keyFor
The canonical device-scoped emission key (see class doc). All callers gating bus datapoints must build their key through this method so identically named channels on different devices never share a throttle slot.- Parameters:
deviceID- the device idchannelID- the channel id- Returns:
- the emission key
"<deviceID>.<channelID>"
-
allows
Checks whethervalueonkeymay be emitted now, without recording anything.- Parameters:
key- the emission key (device-scoped, see class doc)value- the latest valuenowMs- the current time in epoch millis- Returns:
trueif the value passes both filters
-
commitAttempt
Records an emission attempt onkey: only the interval filter's state. Call when starting a fallible emission, before its outcome is known — during an endpoint outage this throttles attempts to one per interval instead of one per sample, without affecting the onChange filter.- Parameters:
key- the emission keynowMs- the attempt time in epoch millis
-
commitValue
Records a delivered value onkey: only the onChange filter's state. Call only after the receiver accepted the value, so a failed or rejected send does not suppress an identical follow-up value.- Parameters:
key- the emission keyvalue- the delivered value (nullis ignored)
-
commit
Records a completed emission ofvalueonkey: both filters' state at once (commitAttempt(java.lang.String, long)+commitValue(java.lang.String, java.lang.Object)).- Parameters:
key- the emission keyvalue- the emitted valuenowMs- the emission time in epoch millis
-
allow
- Parameters:
key- the emission keyvalue- the latest valuenowMs- the current time in epoch millis- Returns:
trueif the value should be emitted
-
