Class SignalRouter

java.lang.Object
me.tamkungz.signals.internal.SignalRouter
All Implemented Interfaces:
foo.zaaarf.geb.api.IListener

public final class SignalRouter extends Object implements foo.zaaarf.geb.api.IListener
Routes SignalEnvelopes arriving from GEB to the listeners registered for their key.

Internal: use SignalBus instead. The class is public only because the dispatcher GEB generates for SignalEnvelope lives in this package and must reach it.

  • Constructor Details

    • SignalRouter

      public SignalRouter()
  • Method Details

    • connect

      public <T> Connection connect(SignalKey<T> key, Consumer<T> listener)
      Registers a listener for a key.
      Type Parameters:
      T - payload type
      Parameters:
      key - key to listen on
      listener - listener to call
      Returns:
      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.
      Type Parameters:
      T - payload type
      Parameters:
      key - key to listen on
      listener - listener to call at most once
      Returns:
      the connection for this listener
    • listenerCount

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

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

      public void clear()
      Disconnects every listener of every key.
    • onSignal

      public void onSignal(SignalEnvelope<?> event)
      GEB entry point: delivers an envelope to the listeners of its key.

      A throwing listener does not stop the others; the first failure is rethrown afterwards with the rest attached as suppressed exceptions.

      Parameters:
      event - envelope to deliver