Class SignalBus

java.lang.Object
me.tamkungz.signals.SignalBus

public final class SignalBus extends Object
Minecraft-friendly facade over GEB.

Typed signals live here; custom GEB events, @Listen listeners and sub-buses are reached through geb().

  • 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.
      Parameters:
      gebBus - GEB bus to use
  • Method Details

    • create

      public static SignalBus create()
      Creates a bus on top of a new GEB instance.
      Returns:
      a new bus
    • geb

      public GebBridge geb()
      Gives direct access to GEB: custom events, @Listen listeners and sub-buses.
      Returns:
      the GEB bridge of this bus
    • signal

      public <T> Signal<T> signal(Class<T> eventType)
      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

      public <T> Signal<T> signal(Class<T> eventType, String name)
      Returns the signal on a named channel of a payload type.
      Type Parameters:
      T - payload type
      Parameters:
      eventType - payload type
      name - channel name
      Returns:
      the signal for SignalKey.named(eventType, name)
    • signal

      public <T> Signal<T> signal(SignalKey<T> key)
      Returns the signal on a channel.

      Signals are cheap views: every Signal for the same key shares the same listeners.

      Type Parameters:
      T - payload type
      Parameters:
      key - channel key
      Returns:
      the signal for the key
    • connect

      public <T> Connection connect(Class<T> eventType, Consumer<T> listener)
      Connects a listener to the default channel of a payload type.
      Type Parameters:
      T - payload type
      Parameters:
      eventType - payload type
      listener - listener to call
      Returns:
      the connection for this listener
    • connect

      public <T> Connection connect(SignalKey<T> key, Consumer<T> listener)
      Connects a listener to a channel.
      Type Parameters:
      T - payload type
      Parameters:
      key - channel key
      listener - listener to call
      Returns:
      the connection for this listener
    • connect

      public <T> Connection connect(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.
      Type Parameters:
      T - payload type
      Parameters:
      group - group that will disconnect the listener
      eventType - payload type
      listener - listener to call
      Returns:
      the connection for this listener
    • connect

      public <T> Connection connect(ConnectionGroup group, SignalKey<T> key, Consumer<T> listener)
      Connects a listener to a channel and tracks it in a group.
      Type Parameters:
      T - payload type
      Parameters:
      group - group that will disconnect the listener
      key - channel key
      listener - listener to call
      Returns:
      the connection for this listener
    • once

      public <T> Connection once(Class<T> eventType, Consumer<T> listener)
      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 type
      listener - listener to call at most once
      Returns:
      the connection for this listener
    • once

      public <T> Connection once(SignalKey<T> key, Consumer<T> listener)
      Connects a listener to a channel that is disconnected after its first value.
      Type Parameters:
      T - payload type
      Parameters:
      key - channel key
      listener - listener to call at most once
      Returns:
      the connection for this listener
    • once

      public <T> Connection once(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.
      Type Parameters:
      T - payload type
      Parameters:
      group - group that will disconnect the listener
      eventType - payload type
      listener - listener to call at most once
      Returns:
      the connection for this listener
    • once

      public <T> Connection once(ConnectionGroup group, SignalKey<T> key, Consumer<T> listener)
      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 listener
      key - channel key
      listener - listener to call at most once
      Returns:
      the connection for this listener
    • fire

      public <T> void fire(Class<T> eventType, T value)
      Fires a value on the default channel of a payload type.
      Type Parameters:
      T - payload type
      Parameters:
      eventType - payload type
      value - value to deliver
    • fire

      public <T> void fire(SignalKey<T> key, T value)
      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 key
      value - value to deliver
    • listenerCount

      public int listenerCount(Class<?> eventType)
      Counts the listeners connected to the default channel of a payload type.
      Parameters:
      eventType - payload type
      Returns:
      number of connected listeners
    • listenerCount

      public int listenerCount(SignalKey<?> key)
      Counts the listeners connected to a channel.
      Parameters:
      key - channel key
      Returns:
      number of connected listeners
    • clear

      public void clear(Class<?> eventType)
      Disconnects every listener of the default channel of a payload type.
      Parameters:
      eventType - payload type
    • clear

      public void clear(SignalKey<?> key)
      Disconnects every listener of a channel.
      Parameters:
      key - channel key
    • clear

      public void clear()
      Disconnects every listener of every channel on this bus.