Docs API Reference

API Reference

The complete public surface of Synapse v0.4.0.

API Reference

The complete public surface of v0.4.0. Anything not listed here (notably com.aaravlabs.synapse.internal) is internal and may change without notice.

com.aaravlabs.synapse — core

Orchestrator

The bus. One per robot. Created for you by SafeOpMode; in tests use Orchestrator.create(name) or Orchestrator.create(name, logSink).

MethodReturnsNotes
name()Stringthe name given at creation
getOrCreateTopic(name, type)Topic<T>existing-or-new; throws on type conflict; primitives ≡ wrappers
findTopic(name)Optional<Topic<?>>type-agnostic lookup
findTopic(name, type)Optional<Topic<T>>empty if absent or type-incompatible
publish(name, value)voidnon-blocking; lazy topic creation; latest cache updated synchronously; throws on null value or type conflict
subscribe(name, type, handler)Subscriptionhandler on callback pool; topic auto-created
getLatestValue(name, type)Optional<T>empty if unpublished or type-incompatible
registerNode(name, node)Nodebinds annotations; duplicate names are a no-op returning the prior node
unregisterNode(name)voidcancels the node’s loops, subscriptions, and actions; calls node.close()
findNode(name)Optional<Node>
runAction(actionName)CompletableFuture<Void>completes on normal return; exceptionally on missing name / closed / action throw
cancelAllActions()voidpermanently shuts the action pool
runPeriodically(task, hz)ScheduledFuture<?>programmatic non-hardware loop
runOnHardwareThread(task)voiddirect hardware-thread submission
hardware()HardwareActionsthe facade
log(msg) / log(tag, msg) / warn / errorvoidrouted through the LogSink
isClosed()booleantrue after close()
close()voididempotent; unregisters nodes (calls close()), shuts all workers

Node

Base class for robot logic. protected final Orchestrator orchestrator is available to subclasses; constructors must call super(orch).

MemberNotes
close()override to release resources; called on unregister/close

Topic<T>

MethodReturns
name() / type()identity
latestValue()Optional<T>
latestValueOr(default)T
latestPublishNanos()long, System.nanoTime() clock

Subscription

MethodNotes
unsubscribe()idempotent

LogSink

MemberNotes
info / warn / error / error(t)(tag, message) pairs
LogSink.STDERRwrites to System.err; used by Orchestrator.create(name)
LogSink.SILENTdrops everything; useful in tests

com.aaravlabs.synapse.annotation

@SubscribedTo

AttributeTypeDefault
topicString— (required, no shorthand)

Method: 0–1 parameters; single-parameter type must match or be a supertype of the topic’s type (primitives ≡ wrappers); mismatched messages are silently dropped. Repeatable. Handler on callback pool unless @OnHardwareThread.

@RunPeriodically

AttributeTypeDefault
hzint20
hardwarebooleanfalse

Method: no parameters, non-static. Fixed-delay scheduling (1000 / hz ms between completions; effective rate ≤ hz; first run immediate). Repeatable. hz <= 0 warns and skips.

@RunnableAction

AttributeTypeDefault
valueString— (the action name)

Method: no parameters, returns void, non-static, not repeatable. Fired by runAction(name) on the unbounded action pool — not the hardware thread. Duplicate names: first wins, second warns.

@OnHardwareThread

No attributes. Modifier for @SubscribedTo methods; re-routes the handler to the dedicated hardware thread.

com.aaravlabs.synapse.ftc

SafeOpMode

Abstract base extending OpMode. Provides fields orchestrator, hardware, safeMap (plus deprecated orch). Hooks: onSafeInit (abstract), onSafeInitLoop, onSafeStart, onSafeLoop, onSafeStop.

FtcOrchestrator

create() — orchestrator named "ftc" logging to android.util.Log via AndroidLogSink; create(sink) overrides the sink.

HardwareActions

Obtained via orchestrator.hardware() or the SafeOpMode hardware field.

MethodReturnsNotes
run(action)voidasync fire-and-forget
call(action)Tblocks; unwraps exceptions; deadlocks from the hardware thread
call(action, timeout, unit)Tas above with TimeoutException
callAsync(action)CompletableFuture<T>non-blocking; safe from the hardware thread
bulkRead(hz, reader)BulkReadHandleperiodic reader on the hardware thread
stopBulkRead(handle)voidcancel; null-safe
isHardwareThread()booleanthread identity check
assertNotHardwareThread()voidthrows IllegalStateException on the hardware thread
tick()voidreserved no-op; called by SafeOpMode.loop()
shutdown()voidcloses the whole orchestrator (sharp edge)

SafeDevice<T>

MethodReturnsNotes
run(action)voidasync; Consumer<T>
call(action)Rblocks; Function<T, R>; deadlocks from the hardware thread
callAsync(action)CompletableFuture<R>non-blocking
raw()Thardware-thread code only

SafeHardwareMap

MethodReturns
device(deviceClass, name)SafeDevice<T>
raw()the underlying HardwareMap

GamepadAdaptor

attach(orch, gamepad, parentTopic) → registers node GamepadAdaptor:<parentTopic> and returns that name. Publishes at 60 Hz on the scheduler pool: <btn> (Boolean), <btn>/rising, <btn>/falling (Boolean, true on the transition), <axis> (Float). Pre-creates all topics at attach time.

BulkReader

read(HardwareView view) — functional interface for bulkRead; runs on the hardware thread.

HardwareView

publish(topic, value) and getLatestValue(topic, type) — the write/read surface inside a bulk-read callback.

AndroidLogSink

LogSink forwarding to android.util.Log by reflection; no-op on desktop JVMs.

Next steps

  • Architecture — the behavior behind this surface.
  • Recipes — the surface composed into robot-validated patterns.