public final class SubscriptionRequest
- Object
- SubscriptionRequest
Which traits to watch, and how often you are willing to hear about them.
SubscriptionRequest req = new SubscriptionRequest()
.add(lamp, lamp.getPrimaryService(), Trait.ON_OFF)
.add(lamp, lamp.getPrimaryService(), Trait.BRIGHTNESS)
.setDeliverInitialValues(true);
TraitSubscription sub = SmartHome.getInstance().subscribe(req, listener);
Fields
public static final int DEFAULT_MIN_INTERVAL_MILLIS = 200 | The default coalescing window, in milliseconds. |
Constructors
public SubscriptionRequest() |
Methods
Inherited methods
Field details
DEFAULT_MIN_INTERVAL_MILLIS
public static final int DEFAULT_MIN_INTERVAL_MILLIS = 200The default coalescing window, in milliseconds.
A fifth of a second: fast enough that a light responding to a switch looks instant, slow enough that dragging a dimmer does not put a hundred deliveries through the EDT.
Constructor details
SubscriptionRequest
public SubscriptionRequest()Method details
add
public SubscriptionRequest add(Accessory accessory, AccessoryService service, Trait trait)Parameters
accessoryAccessory- the accessory to watch
serviceAccessoryService- the service on it
traitTrait- the trait to watch
Returns
Throws
IllegalArgumentException- when any argument is
null
add
public SubscriptionRequest add(String accessoryId, String serviceId, Trait trait)Parameters
accessoryIdString- the accessory to watch
serviceIdString- the service on it
traitTrait- the trait to watch
Returns
Throws
IllegalArgumentException- when any argument is
nullor empty
setMinIntervalMillis
public SubscriptionRequest setMinIntervalMillis(int minIntervalMillis)How long to gather changes before delivering them, in milliseconds.
Within the window, changes are coalesced per accessory, service and trait, keeping only the newest value; the batch then crosses to the EDT once. Dragging a dimmer emits a notification per step, and a home with a hundred watched accessories can produce a steady stream, so the window is what keeps the event loop usable.
Zero delivers every change as it arrives. That is occasionally right – a diagnostic view, a trace – and is a decision to make deliberately rather than a default to inherit.
Parameters
minIntervalMillisint- the window; zero to deliver everything
Returns
Throws
IllegalArgumentException- when the value is negative
getMinIntervalMillis
public int getMinIntervalMillis()Returns
DEFAULT_MIN_INTERVAL_MILLIS unless setsetDeliverInitialValues
public SubscriptionRequest setDeliverInitialValues(boolean deliverInitialValues)Whether to deliver each watched trait’s current value once, up front, as though it had just changed.
false by default. Turn it on when the subscription is what populates
a screen, so the same listener that keeps the screen live also fills
it, and there is no separate read whose result can race the first
change. The batch is marked with
TraitChangeBatch.isInitialDelivery().
Parameters
deliverInitialValuesboolean- whether to send current values first
Returns
isDeliverInitialValues
public boolean isDeliverInitialValues()Returns
true when they aresize
public int size()Returns
isEmpty
public boolean isEmpty()Returns
true when nothing has been addedgetAccessoryIds
public List<String> getAccessoryIds()getServiceIds() and
getTraits().Returns
getServiceIds
public List<String> getServiceIds()getAccessoryIds() and
getTraits().Returns
getTraits
public List<Trait> getTraits()getAccessoryIds() and
getServiceIds().