AbstractClientTransport

Abstract base class representing a client-side transport layer for communication.

This class is responsible for managing the lifecycle of a transport instance, including its initialization, state transitions, message transmission, and graceful shutdown. It provides a framework for implementing specific transport mechanisms by defining abstract methods that subclasses must implement.

Thread-safety is achieved through the use of atomic references to manage transport state transitions and to ensure invariants during lifecycle events. The initialization and shutdown logic is designed to handle async workflows, ensuring proper resource cleanup in the case of failure or cancellation.

Constructors

Link copied to clipboard
constructor()

Functions

Link copied to clipboard
open suspend override fun close()

Closes the client transport gracefully, transitioning its state to a non-operational state.

Link copied to clipboard
open override fun onClose(block: () -> Unit)

Callback for when the connection is closed for any reason.

Link copied to clipboard
open override fun onError(block: (Throwable) -> Unit)

Callback for when an error occurs.

Link copied to clipboard
open override fun onMessage(block: suspend (JSONRPCMessage) -> Unit)

Callback for when a message (request or response) is received over the connection.

Link copied to clipboard
open suspend override fun send(message: JSONRPCMessage, options: TransportSendOptions? = null)

Sends a JSON-RPC message using the transport layer.

Link copied to clipboard
open suspend override fun start()

Initiates the transport by transitioning through the required states to prepare it for operation.