Java API
class

SignalRouter

me.tamkungz.signals.internal.SignalRouter

Version
0.2.1-SNAPSHOT
Java
21
Source file
me/tamkungz/signals/internal/SignalRouter.java
Repository
View source ↗

Routes {@link SignalEnvelope}s arriving from GEB to the listeners registered for their key.

<p>

Internal: use {@link me.tamkungz.signals.SignalBus} instead. The class is public only because the

dispatcher GEB generates for {@link SignalEnvelope} lives in this package and must reach it.

public final class SignalRouter implements IListener

Methods 6

connect

public <T> Connection connect(SignalKey<T> key, Consumer<T> listener)

Registers a listener for a key.

@param
key key to listen on
@param
listener listener to call
@param
<T> payload type
@return
the connection for this listener

once

public <T> Connection once(SignalKey<T> key, Consumer<T> listener)

Registers a listener that is disconnected after its first value.

@param
key key to listen on
@param
listener listener to call at most once
@param
<T> payload type
@return
the connection for this listener

listenerCount

public int listenerCount(SignalKey<?> key)

Counts the listeners connected to a key.

@param
key key to inspect
@return
number of connected listeners

clear

public void clear(SignalKey<?> key)

Disconnects every listener of a key.

@param
key key to clear

clear

public void clear()

Disconnects every listener of every key.

onSignal

@Listen public void onSignal(SignalEnvelope<?> event)

GEB entry point: delivers an envelope to the listeners of its key. <p> A throwing listener does not stop the others; the first failure is rethrown afterwards with the rest attached as suppressed exceptions.

@param
event envelope to deliver