Interface Instance
- All Known Subinterfaces:
-
BinaryInstance,BooleanInstance,JsonArrayInstance,JsonObjectInstance,LiveCounterInstance,LiveMapInstance,NumberInstance,StringInstance
LiveMap or
LiveCounter) or primitive value.
Unlike PathObject, which re-resolves its path on every call, an
Instance is identity-addressed: it wraps an already-resolved value (typically
obtained from a PathObject), so its type is fixed and known for the lifetime
of the instance, and it is dereferenced in O(1) regardless of where that value sits
in the graph. Read operations validate the access 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
wrapped type; everything else - including subscribe (RTTS7b) - is
partitioned onto the sub-types. Use the as* helpers to obtain a sub-type
view, or discriminate via getType(). Because the wrapped type is fixed and
known, a mismatched as* cast fails fast with an IllegalStateException
rather than returning a best-effort view (contrast PathObject, whose casts
never throw).
Spec: RTINS1, RTTS7
-
Method Summary
Modifier and TypeMethodDescription@NotNull BinaryInstanceasBinary()Returns this instance viewed as aBinaryInstance.@NotNull BooleanInstanceReturns this instance viewed as aBooleanInstance.@NotNull JsonArrayInstanceReturns this instance viewed as aJsonArrayInstance.@NotNull JsonObjectInstanceReturns this instance viewed as aJsonObjectInstance.@NotNull LiveCounterInstanceReturns this instance viewed as aLiveCounterInstance.@NotNull LiveMapInstanceReturns this instance viewed as aLiveMapInstance.@NotNull NumberInstanceasNumber()Returns this instance viewed as aNumberInstance.@NotNull StringInstanceasString()Returns this instance viewed as aStringInstance.@NotNull com.google.gson.JsonElementReturns a JSON-serializable, recursively compacted snapshot of the wrapped value.@NotNull ValueTypegetType()Returns theValueTypeof the value wrapped by this instance.
-
Method Details
-
getType
Returns theValueTypeof the value wrapped by this instance. Use this instead of dedicatedisLiveMap/isLiveCounter/etc. checks.An
Instanceis always constructed from a resolved value, so this never returnsValueType.UNKNOWNin normal operation.Spec: RTTS8a
- Returns:
- the wrapped value type
-
compactJson
@NotNull @NotNull com.google.gson.JsonElement compactJson()Returns a JSON-serializable, recursively compacted snapshot of the wrapped value. Behaves identically toPathObject#compactJsonexcept that it operates on the wrapped value directly instead of resolving a path. AnInstanceis always bound to a resolved value, so this always returns a non-null result; failures of the access API preconditions are signalled viaAblyException.Spec: RTINS11 / RTINS11c (universal non-null invariant - Instance is bound to an already-resolved value, so the path-resolution failure mode of PathObject#compactJson does not apply) / RTTS7a (typed-SDK signature reflects the universal invariant)
- Returns:
- the compacted JSON snapshot
-
asLiveMap
Returns this instance viewed as aLiveMapInstance.Because an
Instancewraps an already-resolved value of a known, fixed type, this fails fast: it throwsIllegalStateExceptionif the wrapped value is not aLiveMap, rather than returning a best-effort view. UsegetType()to discriminate the type before casting.Spec: RTTS9a / RTTS9d
- Returns:
- a
LiveMapInstanceview of this instance - Throws:
-
IllegalStateException- if the wrapped value is not aLiveMap
-
asLiveCounter
Returns this instance viewed as aLiveCounterInstance. Fails fast: throwsIllegalStateExceptionif the wrapped value is not aLiveCounter.Spec: RTTS9b / RTTS9d
- Returns:
- a
LiveCounterInstanceview of this instance - Throws:
-
IllegalStateException- if the wrapped value is not aLiveCounter
-
asNumber
Returns this instance viewed as aNumberInstance. Fails fast: throwsIllegalStateExceptionif the wrapped value is not aNumber.Spec: RTTS9c / RTTS9d
- Returns:
- a
NumberInstanceview of this instance - Throws:
-
IllegalStateException- if the wrapped value is not aNumber
-
asString
Returns this instance viewed as aStringInstance. Fails fast: throwsIllegalStateExceptionif the wrapped value is not aString.Spec: RTTS9c / RTTS9d
- Returns:
- a
StringInstanceview of this instance - Throws:
-
IllegalStateException- if the wrapped value is not aString
-
asBoolean
Returns this instance viewed as aBooleanInstance. Fails fast: throwsIllegalStateExceptionif the wrapped value is not aBoolean.Spec: RTTS9c / RTTS9d
- Returns:
- a
BooleanInstanceview of this instance - Throws:
-
IllegalStateException- if the wrapped value is not aBoolean
-
asBinary
Returns this instance viewed as aBinaryInstance. Fails fast: throwsIllegalStateExceptionif the wrapped value is not a binary value.Spec: RTTS9c / RTTS9d
- Returns:
- a
BinaryInstanceview of this instance - Throws:
-
IllegalStateException- if the wrapped value is not a binary value
-
asJsonObject
Returns this instance viewed as aJsonObjectInstance. Fails fast: throwsIllegalStateExceptionif the wrapped value is not a JSON object.Spec: RTTS9c / RTTS9d
- Returns:
- a
JsonObjectInstanceview of this instance - Throws:
-
IllegalStateException- if the wrapped value is not a JSON object
-
asJsonArray
Returns this instance viewed as aJsonArrayInstance. Fails fast: throwsIllegalStateExceptionif the wrapped value is not a JSON array.Spec: RTTS9c / RTTS9d
- Returns:
- a
JsonArrayInstanceview of this instance - Throws:
-
IllegalStateException- if the wrapped value is not a JSON array
-