A2uiMessageProcessor


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 functions

suspend Unit

Suspends and continuously processes all incoming messages queued by processMessage.

Unit

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

Unit

Enqueues a parsed protocol message to be processed.

Public properties

StateFlow<List<A2uiSurfaceModel>>

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

Flow<A2uiClientToServerMessage>

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

Extension functions

Unit
<T : Any?> A2uiMessageProcessor.processInput(
    parser: A2uiMessageParser<T>,
    input: T
)

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

Public functions

collectMessages

Added in 1.0.0-alpha01
suspend fun collectMessages(): Unit

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.

processError

Added in 1.0.0-alpha01
fun processError(error: A2uiClientErrorMessage): Unit

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

Parameters
error: A2uiClientErrorMessage

The client error message to transmit.

processMessage

Added in 1.0.0-alpha01
fun processMessage(message: A2uiServerToClientMessage): Unit

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.

Public properties

activeSurfaces

Added in 1.0.0-alpha01
val activeSurfacesStateFlow<List<A2uiSurfaceModel>>

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

outboundEvents

Added in 1.0.0-alpha01
val outboundEventsFlow<A2uiClientToServerMessage>

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

Extension functions

A2uiMessageProcessor.processInput

fun <T : Any?> A2uiMessageProcessor.processInput(
    parser: A2uiMessageParser<T>,
    input: T
): Unit

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
parser: A2uiMessageParser<T>

The parser to use for parsing the input.

input: T

The raw input to parse and process.