Skip to content

本页为英文技术参考;字段、编号与支持状态直接来自同一契约源。中文学习路线见 开发文档。

State ​

Expose a current, revisioned value and observe changes. State is useful for a view of current data; event history and private durable storage serve different purposes.

Contract: nexa.state/100. API index.

Typical sequence ​

Define the owned state and schema, then read a snapshot before a conditional update. Pass the exact returned revision to CompareExchangeOwned and reconcile conflicts.

Behavior and limits ​

A watch can report a gap; recover with a fresh Read. Uninitialized state is explicit and must not be confused with a failed read or with a valid empty value.

The recorded Host maps 6 of 6 operations in this group. A mapping is subject to permission, phase, scope, platform and business preconditions. Host snapshot identifies the source revision; negotiate against the actual installed Host.

Operations ​

Describe · Read · Watch · DefineOwned · UpdateOwned · CompareExchangeOwned

Describe ​

QualifiedRequest → StateDescriptor

PropertyContract
Local SDK method ID1
KindQuery
Permissionnexa.state.read
Legal phasesInitialize, PostInitialize, Checkup, Finalize, Active
IdempotencyReadOnly
Host statusMapped in recorded snapshot

Request fields

FieldTypeMeaning
IdQualifiedIdIdentity in this model’s domain. Use the identity issued or declared for this object, not a display name or filesystem path.

Successful result

Decode the exact output model after Success. Preserve its identities, revision and schema metadata for subsequent domain operations.

Failure and retry

Unavailable capability, denied permission, wrong phase, malformed schema or foreign ownership fails the call. A read-only classification does not bypass budgets or guarantee a failed request can be retried indefinitely. Preserve structured errors; see recovery guidance.

C binding (call fragment; the caller supplies the encoded request and buffers):

c
nx_State_Describe(&reply, request, &options);

The next resume receives the reply. Check nx_reply_success before nx_State_Describe_result. See the complete continuation example and Wasm ownership rules. This fragment is not a standalone guest.

Read ​

StateReadRequest → StateSnapshot

PropertyContract
Local SDK method ID2
KindQuery
Permissionnexa.state.read
Legal phasesInitialize, PostInitialize, Checkup, Finalize, Active
IdempotencyReadOnly
Host statusMapped in recorded snapshot

Request fields

FieldTypeMeaning
IdQualifiedIdIdentity in this model’s domain. Use the identity issued or declared for this object, not a display name or filesystem path.
ScopeScopedTargetExplicit target scope. The Host checks that the caller is authorized for it.

Successful result

Decode the exact output model after Success. Preserve its identities, revision and schema metadata for subsequent domain operations.

Failure and retry

Unavailable capability, denied permission, wrong phase, malformed schema or foreign ownership fails the call. A read-only classification does not bypass budgets or guarantee a failed request can be retried indefinitely. Preserve structured errors; see recovery guidance.

C binding (call fragment; the caller supplies the encoded request and buffers):

c
nx_State_Read(&reply, request, &options);

The next resume receives the reply. Check nx_reply_success before nx_State_Read_result. See the complete continuation example and Wasm ownership rules. This fragment is not a standalone guest.

Watch ​

StateReadRequest → SubscriptionRef

PropertyContract
Local SDK method ID3
KindSubscription
Permissionnexa.state.read
Legal phasesInitialize, PostInitialize, Checkup, Finalize, Active
IdempotencyReadOnly
Host statusMapped in recorded snapshot

Request fields

FieldTypeMeaning
IdQualifiedIdIdentity in this model’s domain. Use the identity issued or declared for this object, not a display name or filesystem path.
ScopeScopedTargetExplicit target scope. The Host checks that the caller is authorized for it.

Successful result

Retain the subscription identity, consume bounded batches or callbacks as specified, handle gaps, and release it when no longer needed.

Failure and retry

Unavailable capability, denied permission, wrong phase, malformed schema or foreign ownership fails the call. A read-only classification does not bypass budgets or guarantee a failed request can be retried indefinitely. Preserve structured errors; see recovery guidance.

C binding (call fragment; the caller supplies the encoded request and buffers):

c
nx_State_Watch(&reply, request, &options);

The next resume receives the reply. Check nx_reply_success before nx_State_Watch_result. See the complete continuation example and Wasm ownership rules. This fragment is not a standalone guest.

DefineOwned ​

StateDescriptor → RegistrationRef

PropertyContract
Local SDK method ID4
KindRegistration
Permissionnexa.state.write
Legal phasesInitialize
IdempotencyRequiredKey
Host statusMapped in recorded snapshot

Request fields

FieldTypeMeaning
IdQualifiedIdIdentity in this model’s domain. Use the identity issued or declared for this object, not a display name or filesystem path.
SchemaSchemaRefExact schema identity, version and fingerprint used to validate Value.
ScopeScopedTargetExplicit target scope. The Host checks that the caller is authorized for it.

Successful result

Retain the registration identity for the permitted update/release operation. Staged registrations become visible only at group activation.

Failure and retry

Unavailable capability, denied permission, wrong phase, malformed schema or foreign ownership fails the call. Supply a key for the intended effect and retain that key and inputs while resolving an uncertain reply. Do not retry with changed inputs under the same key. Preserve structured errors; see recovery guidance.

C binding (call fragment; the caller supplies the encoded request and buffers):

c
nx_State_DefineOwned(&reply, request, &options);

The next resume receives the reply. Check nx_reply_success before nx_State_DefineOwned_result. See the complete continuation example and Wasm ownership rules. This fragment is not a standalone guest.

UpdateOwned ​

StateUpdate → StateSnapshot

PropertyContract
Local SDK method ID5
KindMutation
Permissionnexa.state.write
Legal phasesActive
IdempotencyRequiredKey
Host statusMapped in recorded snapshot

Request fields

FieldTypeMeaning
IdQualifiedIdIdentity in this model’s domain. Use the identity issued or declared for this object, not a display name or filesystem path.
ScopeScopedTargetExplicit target scope. The Host checks that the caller is authorized for it.
ValueAbiValuePayload interpreted using the accompanying or declared schema; Null is not a substitute for an error.
ExpectedRevisionRevisionRevision observed before this change. Preserve it exactly; a mismatch requires re-reading and reconciling the target.

Successful result

Decode the exact output model after Success. Preserve its identities, revision and schema metadata for subsequent domain operations.

Failure and retry

Unavailable capability, denied permission, wrong phase, malformed schema or foreign ownership fails the call. Supply a key for the intended effect and retain that key and inputs while resolving an uncertain reply. Do not retry with changed inputs under the same key. Re-read after revision conflicts; cancellation does not prove rollback. Preserve structured errors; see recovery guidance.

C binding (call fragment; the caller supplies the encoded request and buffers):

c
nx_State_UpdateOwned(&reply, request, &options);

The next resume receives the reply. Check nx_reply_success before nx_State_UpdateOwned_result. See the complete continuation example and Wasm ownership rules. This fragment is not a standalone guest.

CompareExchangeOwned ​

StateUpdate → StateSnapshot

PropertyContract
Local SDK method ID6
KindMutation
Permissionnexa.state.write
Legal phasesActive
IdempotencyRequiredKey
Host statusMapped in recorded snapshot

Use the revision from the latest authoritative snapshot. On conflict, re-read and reconcile; do not increment or synthesize a revision token.

Request fields

FieldTypeMeaning
IdQualifiedIdIdentity in this model’s domain. Use the identity issued or declared for this object, not a display name or filesystem path.
ScopeScopedTargetExplicit target scope. The Host checks that the caller is authorized for it.
ValueAbiValuePayload interpreted using the accompanying or declared schema; Null is not a substitute for an error.
ExpectedRevisionRevisionRevision observed before this change. Preserve it exactly; a mismatch requires re-reading and reconciling the target.

Successful result

Decode the exact output model after Success. Preserve its identities, revision and schema metadata for subsequent domain operations.

Failure and retry

Unavailable capability, denied permission, wrong phase, malformed schema or foreign ownership fails the call. Supply a key for the intended effect and retain that key and inputs while resolving an uncertain reply. Do not retry with changed inputs under the same key. Re-read after revision conflicts; cancellation does not prove rollback. Preserve structured errors; see recovery guidance.

C binding (call fragment; the caller supplies the encoded request and buffers):

c
nx_State_CompareExchangeOwned(&reply, request, &options);

The next resume receives the reply. Check nx_reply_success before nx_State_CompareExchangeOwned_result. See the complete continuation example and Wasm ownership rules. This fragment is not a standalone guest.


来源: NexaCL-Plugin-SDK · Apache-2.0.

Site documentation: CC BY-SA 4.0. Imported SDK documents: Apache-2.0 as marked.