Interface LiveMapInstance
- All Superinterfaces:
Instance
A
Instance bound to a LiveMap. Provides type-safe access to
map-specific operations such as get(String), entries() and
set(String, LiveMapValue).
Operations are bound to the specific underlying LiveMap, dereferenced in
O(1), and do not perform any path resolution.
Spec: RTTS10a
-
Method Summary
Modifier and TypeMethodDescription@NotNull com.google.gson.JsonObjectReturns the compacted JSON snapshot of the wrapped value, narrowed to aJsonObject: aLiveMapInstancecompacts to a JSON object (or, for a cyclic reference, an object-id reference object).entries()Returns the entries (key, childInstance) of the wrappedLiveMap.@Nullable InstanceReturns aInstancewrapping the value atkeyof the wrappedLiveMap, ornullwhen the key is absent / tombstoned.@NotNull StringgetId()Returns the object id of the wrappedLiveMap.keys()Returns the keys of the wrappedLiveMap.@NotNull CompletableFuture<Void>Removes a key from the wrappedLiveMap.@NotNull CompletableFuture<Void>set(@NotNull String key, @NotNull LiveMapValue value) Sets a key on the wrappedLiveMapto the provided value.@NotNull Longsize()Returns the number of (non-tombstoned) entries in the wrappedLiveMap.@NotNull Subscriptionsubscribe(@NotNull InstanceListener listener) Subscribes a listener for updates on the wrappedLiveMap.values()Returns the childInstances for each value in the wrappedLiveMap.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 wrappedLiveMap.Spec: RTINS3a
- Returns:
- the wrapped
LiveMap's object id
-
compactJson
@NotNull @NotNull com.google.gson.JsonObject compactJson()Returns the compacted JSON snapshot of the wrapped value, narrowed to aJsonObject: aLiveMapInstancecompacts to a JSON object (or, for a cyclic reference, an object-id reference object).Spec: RTTS7a
- Specified by:
-
compactJsonin interfaceInstance - Returns:
- the compacted JSON object
-
get
Returns aInstancewrapping the value atkeyof the wrappedLiveMap, ornullwhen the key is absent / tombstoned.Spec: RTINS5
- Parameters:
-
key- the key to look up - Returns:
- an instance wrapping the value at
key, ornull
-
entries
- Returns:
- an unmodifiable iterable of entries
-
keys
Returns the keys of the wrappedLiveMap.Spec: RTINS7
- Returns:
- an unmodifiable iterable of keys
-
values
- Returns:
- an unmodifiable iterable of value instances
-
size
Returns the number of (non-tombstoned) entries in the wrappedLiveMap.Spec: RTINS9
- Returns:
- the map size
-
set
@NotNull @NotNull CompletableFuture<Void> set(@NotNull @NotNull String key, @NotNull @NotNull LiveMapValue value) Sets a key on the wrappedLiveMapto the provided value. Sends aMAP_SEToperation to the realtime system; the local state is updated when the operation is echoed back.Spec: RTINS12
- Parameters:
-
key- the key to set -
value- the value to associate withkey - Returns:
- a future that completes when the operation has been acknowledged
-
remove
Removes a key from the wrappedLiveMap. Sends aMAP_REMOVEoperation to the realtime system; the local state is updated when the operation is echoed back.Spec: RTINS13
- Parameters:
-
key- the key to remove - Returns:
- a future that completes when the operation has been acknowledged
-
subscribe
Subscribes a listener for updates on the wrappedLiveMap. The listener is invoked whenever the wrapped map 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
LiveMap, regardless of where it sits in the LiveObjects graph.Spec: RTTS10a / RTINS16
- Parameters:
-
listener- the listener to invoke on updates - Returns:
- a subscription handle that can be used to unsubscribe this listener
-