ExtensionRegistry

class ExtensionRegistry(log: (String) -> Unit = {}, clock: () -> Long = { System.nanoTime() / 1_000_000 }, dispatch: (Runnable) -> Unit = { it.run() }, onStatusChanged: () -> Unit = {})(source)

Routes extension messages (protocol §7) between the links and the registered extensions, and keeps them from touching anything else: core types are never routed here or sent from here, sizes and rates are capped, an exception is logged and answered, an extension failing Ext.MAX_FAILURES times in a row is switched off.

dispatch is where handlers run (the Android phone: its extension thread; a client: its main thread; tests: inline).

Constructors

Link copied to clipboard
constructor(log: (String) -> Unit = {}, clock: () -> Long = { System.nanoTime() / 1_000_000 }, dispatch: (Runnable) -> Unit = { it.run() }, onStatusChanged: () -> Unit = {})

Types

Link copied to clipboard
object Companion

Properties

Link copied to clipboard

Functions

Link copied to clipboard
fun caps(): List<String>

What this side announces in caps: every enabled extension's majors.

Link copied to clipboard
fun capsJson(): JSONArray
Link copied to clipboard
fun debug(): JSONObject

For debug hooks: extensions, links and counters (no message contents).

Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard

fun peerCaps(link: ExtensionLink, caps: JSONArray?)

The peer's caps (from its latest sync or status; absent: none). Calls onLink for every change.

Link copied to clipboard

Adds an extension. Refused (IllegalArgumentException) when its id or a type is not in the extension namespace, names a core type, does not belong to its id, or is already taken: an extension can never replace a core message or another extension.

Link copied to clipboard
fun route(link: ExtensionLink, m: Message, size: Int = -1): Boolean

Called by the app's router for a message no core handler took (and for every error). True when it was an extension's: handled, refused or dropped. False for core types: the router carries on as before. size is the encoded envelope's length when the caller has it.

Link copied to clipboard

Live links on which e agreed a version (debug hooks and the extension's own host).

Link copied to clipboard
fun start()
Link copied to clipboard
fun statusFor(link: ExtensionLink): JSONObject?

status.ext for this link: the fields of every extension agreed with it that has some (each ≤ 1 KiB).

Link copied to clipboard
fun stop()
Link copied to clipboard