Interface PathObject
- All Known Subinterfaces:
-
BinaryPathObject,BooleanPathObject,JsonArrayPathObject,JsonObjectPathObject,LiveCounterPathObject,LiveMapPathObject,NumberPathObject,StringPathObject
LiveMap.
A PathObject stores a path as an ordered list of string segments and
resolves it against the local object graph each time a terminal method is called;
the freshly resolved value is the sole basis for that call's result. Resolution is
best-effort: the value at a path may change between two calls (e.g. between
exists() and a subsequent write) as updates from other clients are applied.
When the path does not resolve, or resolves to a type the called method does not
apply to, read operations degrade gracefully - returning null or an empty
result - whereas write operations fail with an AblyException (code 92005 if
the path does not resolve, 92007 on a type mismatch). All terminal operations
additionally validate the access/write API preconditions and fail with an
AblyException if those are not satisfied.
This base type exposes only the methods whose behaviour is independent of the
resolved type; map and counter reads/writes are partitioned onto the sub-types
(RTTS3e). Use the as* helpers to obtain a sub-type view without type
validation, e.g. pathObject.asLiveMap().at("a.b.c") (RTTS3g). The spec's
compact is not exposed; compactJson() is the supported equivalent
(RTTS3f).
Spec: RTPO1, RTPO2, RTTS3
-
Method Summary
Modifier and TypeMethodDescription@NotNull BinaryPathObjectasBinary()Returns thisPathObjectwrapped as aBinaryPathObject.@NotNull BooleanPathObjectReturns thisPathObjectwrapped as aBooleanPathObject.@NotNull JsonArrayPathObjectReturns thisPathObjectwrapped as aJsonArrayPathObject.@NotNull JsonObjectPathObjectReturns thisPathObjectwrapped as aJsonObjectPathObject.@NotNull LiveCounterPathObjectReturns thisPathObjectwrapped as aLiveCounterPathObject.@NotNull LiveMapPathObjectReturns thisPathObjectwrapped as aLiveMapPathObject.@NotNull NumberPathObjectasNumber()Returns thisPathObjectwrapped as aNumberPathObject.@NotNull StringPathObjectasString()Returns thisPathObjectwrapped as aStringPathObject.@Nullable com.google.gson.JsonElementReturns a JSON-serializable, recursively compacted snapshot of the value at this path.booleanexists()Returnstrueif a value currently resolves at this path in the local object graph.@Nullable ValueTypegetType()Returns theValueTypeof the value currently resolved at this path, ornullwhen the path does not resolve to any value.@Nullable Instanceinstance()Resolves this path and returns aInstancewrapping the resolved value, whether it is aLiveMap,LiveCounteror a primitive (RTPO8c/RTPO8f).@NotNull Stringpath()Returns a dot-delimited string representation of the stored path segments.@NotNull Subscriptionsubscribe(@NotNull PathObjectListener listener) Subscribes a listener for path-based update events.@NotNull Subscriptionsubscribe(@NotNull PathObjectListener listener, @Nullable PathObjectSubscriptionOptions options) Subscribes a listener for path-based update events using the providedPathObjectSubscriptionOptions.
-
Method Details
-
getType
Returns theValueTypeof the value currently resolved at this path, ornullwhen the path does not resolve to any value. Use this instead of dedicatedisLiveMap/isLiveCounter/etc. checks.A
nullresult means there is no value at this path - nothing is stored there (e.g. an absent or removed map entry). This is deliberately distinct fromValueType.UNKNOWN, which is returned only when a value is present but its type matches none of the known categories. In other words:nullmeans "no value",UNKNOWNmeans "a value of an unrecognized type".Spec: RTTS4b
- Returns:
- the resolved value type at this path, or
nullif the path does not resolve to a value
-
path
Returns a dot-delimited string representation of the stored path segments. Dot characters inside individual segments are escaped with a backslash, so a path with segments["a", "b.c", "d"]is represented as"a.b\.c.d". An empty path (i.e. the rootPathObject) returns the empty string.Spec: RTPO4 / RTTS3a
- Returns:
- the dot-delimited path from the root to this position
-
instance
Resolves this path and returns aInstancewrapping the resolved value, whether it is aLiveMap,LiveCounteror a primitive (RTPO8c/RTPO8f).Returns
nullwhen the path does not resolve (RTPO8e).Spec: RTPO8 / RTTS3b
- Returns:
- a
Instancewrapping the resolved value, ornull
-
compactJson
@Nullable @Nullable com.google.gson.JsonElement compactJson()Returns a JSON-serializable, recursively compacted snapshot of the value at this path. Behaves like the spec'scompactexcept thatBinaryvalues are base64-encoded and cyclic references are represented as{ "objectId": ... }markers, so the result is safe to serialise as JSON.Returns
nullwhen the path does not resolve.Spec: RTPO14 / RTTS3c
- Returns:
- the compacted JSON snapshot, or
nullif the path does not resolve
-
exists
boolean exists()Returnstrueif a value currently resolves at this path in the local object graph. This is a best-effort check evaluated at call time; the answer may change immediately afterwards as remote operations are applied. Useful as a guard before performing operations whose semantics depend on existence.Complexity is O(n) in the path length because the path must be resolved.
Spec: RTTS4a
- Returns:
-
trueif the path resolves to a value,falseotherwise
-
asLiveMap
Returns thisPathObjectwrapped as aLiveMapPathObject.This is a best-effort cast - it does not validate that the underlying value at this path is a
LiveMap. Read operations are always permitted on the returned wrapper; write or terminal operations that require resolution will fail at call time if the resolved value is not aLiveMap.Spec: RTTS5a
- Returns:
- a
LiveMapPathObjectview of this path
-
asLiveCounter
Returns thisPathObjectwrapped as aLiveCounterPathObject. Best-effort cast; does not validate the underlying type at this path.Spec: RTTS5b
- Returns:
- a
LiveCounterPathObjectview of this path
-
asNumber
Returns thisPathObjectwrapped as aNumberPathObject. Best-effort cast; does not validate the underlying type at this path.Spec: RTTS5c
- Returns:
- a
NumberPathObjectview of this path
-
asString
Returns thisPathObjectwrapped as aStringPathObject. Best-effort cast; does not validate the underlying type at this path.Spec: RTTS5c
- Returns:
- a
StringPathObjectview of this path
-
asBoolean
Returns thisPathObjectwrapped as aBooleanPathObject. Best-effort cast; does not validate the underlying type at this path.Spec: RTTS5c
- Returns:
- a
BooleanPathObjectview of this path
-
asBinary
Returns thisPathObjectwrapped as aBinaryPathObject. Best-effort cast; does not validate the underlying type at this path.Spec: RTTS5c
- Returns:
- a
BinaryPathObjectview of this path
-
asJsonObject
Returns thisPathObjectwrapped as aJsonObjectPathObject. Best-effort cast; does not validate the underlying type at this path.Spec: RTTS5c
- Returns:
- a
JsonObjectPathObjectview of this path
-
asJsonArray
Returns thisPathObjectwrapped as aJsonArrayPathObject. Best-effort cast; does not validate the underlying type at this path.Spec: RTTS5c
- Returns:
- a
JsonArrayPathObjectview of this path
-
subscribe
@NonBlocking @NotNull @NotNull Subscription subscribe(@NotNull @NotNull PathObjectListener listener) Subscribes a listener for path-based update events. The listener is invoked when an operation modifies the value at this path. The same path may be subscribed by multiple listeners independently. CallSubscription.unsubscribe()on the returned handle to stop receiving events for this listener.Spec: RTPO19 / RTTS3d
- Parameters:
-
listener- the listener to invoke on updates - Returns:
- a subscription handle that can be used to unsubscribe this listener
-
subscribe
@NonBlocking @NotNull @NotNull Subscription subscribe(@NotNull @NotNull PathObjectListener listener, @Nullable @Nullable PathObjectSubscriptionOptions options) Subscribes a listener for path-based update events using the providedPathObjectSubscriptionOptions. Options control coverage rules such as thedepthof nested updates that trigger the listener. CallSubscription.unsubscribe()on the returned handle to stop receiving events for this listener.Spec: RTPO19 / RTTS3d
- Parameters:
-
listener- the listener to invoke on updates -
options- optional subscription options, may benull - Returns:
- a subscription handle that can be used to unsubscribe this listener
-