A2uiMessageProcessor


public interface A2uiMessageProcessor

Known direct subclasses
A2uiCoreMessageProcessor

The central orchestration engine for the A2UI core data layer.


The A2UI message processor.

This processor is the central orchestration engine for the A2UI core data layer. It receives parsed protocol messages from the host application and exposes the outbound network events back to the host framework.

TODO(b/532001163): add an sample for this API and reference it from collectMessages and processMessage.

Summary

Public methods

abstract void

Suspends and continuously processes all incoming messages queued by processMessage.

abstract @NonNull StateFlow<@NonNull List<@NonNull A2uiSurfaceModel>>

A flow of the active surface models currently managed by the processor.

abstract @NonNull Flow<@NonNull A2uiClientToServerMessage>

A flow of user actions and error payloads to be transmitted to the server.

abstract void

Enqueues a client error message to be transmitted back to the server via outboundEvents.

abstract void

Enqueues a parsed protocol message to be processed.

Extension functions

default final void
<T extends Object> A2uiMessageProcessorKt.processInput(
    @NonNull A2uiMessageProcessor receiver,
    @NonNull A2uiMessageParser<@NonNull T> parser,
    @NonNull T input
)

Parses input using parser and enqueues the resulting message into this processor.

Public methods

collectMessages

Added in 1.0.0-alpha01
abstract void collectMessages()

Suspends and continuously processes all incoming messages queued by processMessage.

This method acts as the engine's main processing loop. It should be launched within a coroutine scope tied to the host application's lifecycle (such as a ViewModel). If this method is not running, any messages passed to processMessage will remain queued.

When the calling coroutine scope is cancelled, the processing loop will gracefully terminate.

getActiveSurfaces

Added in 1.0.0-alpha01
abstract @NonNull StateFlow<@NonNull List<@NonNull A2uiSurfaceModel>> getActiveSurfaces()

A flow of the active surface models currently managed by the processor.

getOutboundEvents

Added in 1.0.0-alpha01
abstract @NonNull Flow<@NonNull A2uiClientToServerMessagegetOutboundEvents()

A flow of user actions and error payloads to be transmitted to the server.

processError

Added in 1.0.0-alpha01
abstract void processError(@NonNull A2uiClientErrorMessage error)

Enqueues a client error message to be transmitted back to the server via outboundEvents.

Parameters
@NonNull A2uiClientErrorMessage error

The client error message to transmit.

processMessage

Added in 1.0.0-alpha01
abstract void processMessage(@NonNull A2uiServerToClientMessage message)

Enqueues a parsed protocol message to be processed.

Note that this method does not execute the processing itself. Messages are queued and will only be handled while collectMessages is actively running.

This method is thread-safe and can be called from any thread.

Extension functions

A2uiMessageProcessorKt.processInput

default final void <T extends Object> A2uiMessageProcessorKt.processInput(
    @NonNull A2uiMessageProcessor receiver,
    @NonNull A2uiMessageParser<@NonNull T> parser,
    @NonNull T input
)

Parses input using parser and enqueues the resulting message into this processor.

If parsing fails with an A2uiException (such as A2uiException.A2uiValidationException), the exception is caught, converted into an A2uiClientErrorMessage, and sent to processError. Unexpected runtime exceptions are not caught.

Parameters
@NonNull A2uiMessageParser<@NonNull T> parser

The parser to use for parsing the input.

@NonNull T input

The raw input to parse and process.