Skip to content

The bridges

The core of JOID never calls a window, graphics or audio library. Each thing it needs from the outside is an interface, called a bridge, and each bridge lives in a registry of BridgeHandler. A backend fills the registries; the core reads them.

Two groups of boxes, one per registry of BridgeHandler with the bridge it holds. The first group, on two rows, labelled registered by Backend.register(): UI with a WindowUIBridge by default, WINDOW and RENDER highlighted with your window and render bridges, AUDIO marked optional, THREAD with a FrameThreadBridge. The second group, labelled registered by JOID before any backend: CLOCK with SystemClockBridge, THREAD with DirectThreadBridge, SIGNAL_REPLAY with the identity. A line below reads: get() returns the bridge of the highest priority, only UI uses all of its bridges.

Who fills each registry: your backend fills five through its hooks, JOID fills three with its defaults. The two bridges you always write are the window and the render bridges.
RegistryBridgeFilled byContract
BridgeHandler.UIUIBridgethe backend (a default WindowUIBridge), the application, pluginsUI bridge
BridgeHandler.WINDOWIWindowBridgethe backendWindow bridge
BridgeHandler.RENDERIRenderBridgethe backendRender bridge
BridgeHandler.AUDIOIAudioBridgethe backend, optionalAudio bridge
BridgeHandler.THREADIThreadBridgeJOID (DirectThreadBridge), then the backend (FrameThreadBridge by default)Thread bridge
BridgeHandler.CLOCKIClockBridgeJOID (SystemClockBridge), testsClock bridge
BridgeHandler.SIGNAL_REPLAYISignalReplayBridgeJOID (an identity), a host that renames classesSignal replay bridge

Every bridge interface extends the empty marker IBridge. BridgeHandler.UI is a UIBridgeRegistry: a BridgeRegistry that also runs the frames and dispatches the input.

A registry keeps its bridges sorted by an int priority, and BridgeRegistry.get returns the bridge of the highest one. register(bridge) uses the priority 0; BridgeRegistry.registerDefault registers a bridge with the lowest priority, and only while the registry is empty. Add a UI bridge of your own gives the rules from the side of an application.

Registering and unregistering are thread-safe, and reading never locks: each change publishes a new immutable list. get() on an empty registry throws an IllegalStateException that names the registry, which is the usual sign that the backend was never registered.

The registries are static, and the core puts three bridges in them before any backend: the system clock, the direct thread bridge and the identity replay bridge. A backend registers the rest from Backend.register, one hook per bridge, then its defaults (Writing a backend lists the hooks). What happens at register() gives the whole sequence from the side of an application.

Application code and plugins add to the registries at any time. Code that must run after the backend, whatever the load order, goes into JOID.onReady (Run code once JOID is ready).

The core reads WINDOW, RENDER, AUDIO, THREAD, CLOCK and SIGNAL_REPLAY with get(): the highest bridge wins, the others wait below it. A test, for example, registers a ManualClockBridge above the system clock.

The UI registry uses all of its bridges at once, for the frames, the input and the opening of a UI. Add a UI bridge of your own gives that routing, and UI bridge the contract of a bridge.

Report a problem with this page