Class SignalBus
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidclear()Disconnects every listener of every channel on this bus.voidDisconnects every listener of the default channel of a payload type.voidDisconnects every listener of a channel.<T> ConnectionConnects a listener to the default channel of a payload type.<T> Connectionconnect(ConnectionGroup group, Class<T> eventType, Consumer<T> listener) Connects a listener to the default channel of a payload type and tracks it in a group.<T> Connectionconnect(ConnectionGroup group, SignalKey<T> key, Consumer<T> listener) Connects a listener to a channel and tracks it in a group.<T> ConnectionConnects a listener to a channel.static SignalBuscreate()Creates a bus on top of a new GEB instance.<T> voidFires a value on the default channel of a payload type.<T> voidFires a value on a channel.geb()Gives direct access to GEB: custom events,@Listenlisteners and sub-buses.booleanhasReceivers(Class<?> eventType) Tells whether a value fired on the default channel of a payload type could reach anything.booleanhasReceivers(SignalKey<?> key) Tells whether a value fired on a channel could reach anything: a listener connected to it, or a sub-bus registered throughgeb().intlistenerCount(Class<?> eventType) Counts the listeners connected to the default channel of a payload type.intlistenerCount(SignalKey<?> key) Counts the listeners connected to a channel.<T> ConnectionConnects a listener to the default channel of a payload type that is disconnected after its first value.<T> Connectiononce(ConnectionGroup group, Class<T> eventType, Consumer<T> listener) Connects a one-shot listener to the default channel of a payload type and tracks it in a group.<T> Connectiononce(ConnectionGroup group, SignalKey<T> key, Consumer<T> listener) Connects a one-shot listener to a channel and tracks it in a group.<T> ConnectionConnects a listener to a channel that is disconnected after its first value.<T> Signal<T> Returns the signal on the default channel of a payload type.<T> Signal<T> Returns the signal on a named channel of a payload type.<T> Signal<T> Returns the signal on a channel.
-
Constructor Details
-
SignalBus
public SignalBus()Creates a bus on top of a new GEB instance. -
SignalBus
public SignalBus(foo.zaaarf.geb.api.IBus gebBus) Creates a bus on top of an existing GEB bus.The bus registers the dispatcher it needs for its own events on the given GEB bus. Dispatchers for your own events are not touched; see
GebBridge.loadDispatchers(ClassLoader).Every value fired on a bus travels through GEB as an event, so two
SignalBusinstances on the same GEB bus see each other's values, just like a bus and its sub-buses do. Give each bus its own GEB bus (the default) unless that is what you want.- Parameters:
gebBus- GEB bus to use
-
-
Method Details
-
create
-
geb
Gives direct access to GEB: custom events,@Listenlisteners and sub-buses.- Returns:
- the GEB bridge of this bus
-
signal
-
signal
-
signal
-
connect
Connects a listener to the default channel of a payload type.- Type Parameters:
T- payload type- Parameters:
eventType- payload typelistener- listener to call- Returns:
- the connection for this listener
-
connect
Connects a listener to a channel.- Type Parameters:
T- payload type- Parameters:
key- channel keylistener- listener to call- Returns:
- the connection for this listener
-
connect
Connects a listener to the default channel of a payload type and tracks it in a group.- Type Parameters:
T- payload type- Parameters:
group- group that will disconnect the listenereventType- payload typelistener- listener to call- Returns:
- the connection for this listener
-
connect
Connects a listener to a channel and tracks it in a group.- Type Parameters:
T- payload type- Parameters:
group- group that will disconnect the listenerkey- channel keylistener- listener to call- Returns:
- the connection for this listener
-
once
Connects a listener to the default channel of a payload type that is disconnected after its first value.- Type Parameters:
T- payload type- Parameters:
eventType- payload typelistener- listener to call at most once- Returns:
- the connection for this listener
-
once
Connects a listener to a channel that is disconnected after its first value.- Type Parameters:
T- payload type- Parameters:
key- channel keylistener- listener to call at most once- Returns:
- the connection for this listener
-
once
Connects a one-shot listener to the default channel of a payload type and tracks it in a group.- Type Parameters:
T- payload type- Parameters:
group- group that will disconnect the listenereventType- payload typelistener- listener to call at most once- Returns:
- the connection for this listener
-
once
Connects a one-shot listener to a channel and tracks it in a group.- Type Parameters:
T- payload type- Parameters:
group- group that will disconnect the listenerkey- channel keylistener- listener to call at most once- Returns:
- the connection for this listener
-
fire
Fires a value on the default channel of a payload type.- Type Parameters:
T- payload type- Parameters:
eventType- payload typevalue- value to deliver
-
fire
Fires a value on a channel.Listeners run on the calling thread, in the order they were connected. A throwing listener does not stop the others; once all have run, the first exception is rethrown with the rest attached as suppressed exceptions. GEB does not catch it, so it reaches the caller of
fire.- Type Parameters:
T- payload type- Parameters:
key- channel keyvalue- value to deliver
-
listenerCount
Counts the listeners connected to the default channel of a payload type.- Parameters:
eventType- payload type- Returns:
- number of connected listeners
-
listenerCount
Counts the listeners connected to a channel.- Parameters:
key- channel key- Returns:
- number of connected listeners
-
hasReceivers
Tells whether a value fired on the default channel of a payload type could reach anything.- Parameters:
eventType- payload type- Returns:
- see
hasReceivers(SignalKey)
-
hasReceivers
Tells whether a value fired on a channel could reach anything: a listener connected to it, or a sub-bus registered throughgeb(). A sub-bus cannot be inspected, so one counts as a possible receiver for every channel.Platform bridges use this to skip building and dispatching an event nobody can receive. Prefer it to comparing
listenerCount(SignalKey)with zero, which ignores sub-buses.- Parameters:
key- channel key- Returns:
falseonly if firing on the channel could not reach any listener
-
clear
Disconnects every listener of the default channel of a payload type.- Parameters:
eventType- payload type
-
clear
Disconnects every listener of a channel.- Parameters:
key- channel key
-
clear
public void clear()Disconnects every listener of every channel on this bus.
-