Interface LiveCounterInstance
- All Superinterfaces:
Instance
A
Instance bound to a LiveCounter. Provides type-safe
access to counter operations such as value(), increment(Number)
and decrement(Number).
Spec: RTTS10b
-
Method Summary
Modifier and TypeMethodDescription@NotNull com.google.gson.JsonPrimitiveReturns the compacted JSON snapshot of the wrapped value, narrowed to aJsonPrimitive: aLiveCounterInstancealways compacts to a numeric JSON primitive.@NotNull CompletableFuture<Void>Decrements the wrappedLiveCounterby1.@NotNull CompletableFuture<Void>Decrements the wrappedLiveCounterbyamount.@NotNull StringgetId()Returns the object id of the wrappedLiveCounter.@NotNull CompletableFuture<Void>Increments the wrappedLiveCounterby1.@NotNull CompletableFuture<Void>Increments the wrappedLiveCounterbyamount.@NotNull Subscriptionsubscribe(@NotNull InstanceListener listener) Subscribes a listener for updates on the wrappedLiveCounter.@NotNull Doublevalue()Returns the current value of the wrappedLiveCounter.Methods inherited from interface io.ably.lib.liveobjects.instance.Instance
asBinary, asBoolean, asJsonArray, asJsonObject, asLiveCounter, asLiveMap, asNumber, asString, getType
-
Method Details
-
getId
Returns the object id of the wrappedLiveCounter.Spec: RTINS3a
- Returns:
- the wrapped
LiveCounter's object id
-
value
Returns the current value of the wrappedLiveCounter.Spec: RTINS4 / RTLC5
- Returns:
- the counter value
-
compactJson
@NotNull @NotNull com.google.gson.JsonPrimitive compactJson()Returns the compacted JSON snapshot of the wrapped value, narrowed to aJsonPrimitive: aLiveCounterInstancealways compacts to a numeric JSON primitive.Spec: RTTS7a
- Specified by:
-
compactJsonin interfaceInstance - Returns:
- the compacted JSON primitive
-
increment
Increments the wrappedLiveCounterby1. Equivalent to callingincrement(Number)with1.Spec: RTINS14a1 (default
amountof1)- Returns:
- a future that completes when the operation has been acknowledged
-
increment
Increments the wrappedLiveCounterbyamount.Sends a
COUNTER_INCoperation to the realtime system; the local state is updated when the operation is echoed back.Spec: RTINS14
- Parameters:
-
amount- the amount to add (may be negative) - Returns:
- a future that completes when the operation has been acknowledged
-
decrement
Decrements the wrappedLiveCounterby1. Equivalent to callingdecrement(Number)with1.Spec: RTINS15a1 (default
amountof1)- Returns:
- a future that completes when the operation has been acknowledged
-
decrement
Decrements the wrappedLiveCounterbyamount. Equivalent to callingincrement(Number)with a negated value.Spec: RTINS15
- Parameters:
-
amount- the amount to subtract (may be negative) - Returns:
- a future that completes when the operation has been acknowledged
-
subscribe
Subscribes a listener for updates on the wrappedLiveCounter. The listener is invoked whenever the wrapped counter is changed by a local or remote operation. CallSubscription.unsubscribe()on the returned handle to stop receiving events for this listener.The subscription is identity-based: it follows the specific underlying
LiveCounter, regardless of where it sits in the LiveObjects graph.Spec: RTTS10b / RTINS16
- Parameters:
-
listener- the listener to invoke on updates - Returns:
- a subscription handle that can be used to unsubscribe this listener
-