Package me.tamkungz.signals
Class SignalBus
java.lang.Object
me.tamkungz.signals.SignalBus
Minecraft-friendly facade over GEB.
Typed signals live here; custom GEB events, @Listen listeners and sub-buses are reached
through geb().
-
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.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.loadAndRegisterDispatchers(ClassLoader).- Parameters:
gebBus- GEB bus to use
-
-
Method Details
-
create
Creates a bus on top of a new GEB instance.- Returns:
- a new bus
-
geb
Gives direct access to GEB: custom events,@Listenlisteners and sub-buses.- Returns:
- the GEB bridge of this bus
-
signal
Returns the signal on the default channel of a payload type.- Type Parameters:
T- payload type- Parameters:
eventType- payload type- Returns:
- the signal for
SignalKey.of(eventType)
-
signal
Returns the signal on a named channel of a payload type.- Type Parameters:
T- payload type- Parameters:
eventType- payload typename- channel name- Returns:
- the signal for
SignalKey.named(eventType, name)
-
signal
Returns the signal on a channel.Signals are cheap views: every
Signalfor the same key shares the same listeners.- Type Parameters:
T- payload type- Parameters:
key- channel key- Returns:
- the signal for the key
-
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 router hands the first exception back to GEB, with the rest attached as suppressed exceptions.
- 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
-
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.
-