Class GebBridge
SignalBus: custom
IEvents, @Listen listeners and sub-buses.
Obtain it with SignalBus.geb().
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionfoo.zaaarf.geb.api.IBusbus()Returns the underlying GEB bus.dispatcher(foo.zaaarf.geb.api.IEventDispatcher<?> dispatcher) Registers a dispatcher and returns a connection that unregisters it.dispatcher(ConnectionGroup group, foo.zaaarf.geb.api.IEventDispatcher<?> dispatcher) Registers a dispatcher and tracks its connection in a group.booleanTells whether any sub-bus is registered through this bridge.booleanisRegistered(foo.zaaarf.geb.api.IBus subBus) Tells whether a sub-bus is registered.booleanisRegistered(foo.zaaarf.geb.api.IListener listener) Tells whether a listener is registered.listen(foo.zaaarf.geb.api.IListener listener) Registers a listener and returns a connection that unregisters it.listen(ConnectionGroup group, foo.zaaarf.geb.api.IListener listener) Registers a listener and tracks its connection in a group.voidloadAndRegisterDispatchers(ClassLoader classLoader) Registers every dispatcher a class loader lists inMETA-INF/services/foo.zaaarf.geb.api.IEventDispatcher, the file GEB's annotation processor writes.loadDispatchers(ClassLoader classLoader) Registers every dispatcher a class loader lists inMETA-INF/services/foo.zaaarf.geb.api.IEventDispatcherand returns one connection that unregisters all of them.loadDispatchers(ConnectionGroup group, ClassLoader classLoader) Registers the dispatchers of a class loader and tracks their connection in a group.booleanpost(foo.zaaarf.geb.api.IEvent event) Posts an event to every registered listener.voidregisterDispatcher(foo.zaaarf.geb.api.IEventDispatcher<?> dispatcher) Registers the dispatcher of an event type.voidregisterListener(foo.zaaarf.geb.api.IListener listener) Registers a listener.voidregisterSubBus(foo.zaaarf.geb.api.IBus subBus, int priority) Registers a sub-bus.subBus(foo.zaaarf.geb.api.IBus subBus, int priority) Registers a sub-bus and returns a connection that unregisters it.subBus(ConnectionGroup group, foo.zaaarf.geb.api.IBus subBus, int priority) Registers a sub-bus and tracks its connection in a group.voidunregisterDispatcher(foo.zaaarf.geb.api.IEventDispatcher<?> dispatcher) Unregisters the dispatcher of an event type; its listeners stop being called.voidunregisterListener(foo.zaaarf.geb.api.IListener listener) Unregisters a listener.voidunregisterSubBus(foo.zaaarf.geb.api.IBus subBus) Unregisters a sub-bus.
-
Constructor Details
-
GebBridge
public GebBridge(foo.zaaarf.geb.api.IBus bus) Wraps a GEB bus.- Parameters:
bus- bus to expose
-
-
Method Details
-
bus
public foo.zaaarf.geb.api.IBus bus()Returns the underlying GEB bus.- Returns:
- the raw bus
-
post
public boolean post(foo.zaaarf.geb.api.IEvent event) Posts an event to every registered listener.- Parameters:
event- event to post- Returns:
falseif the event was cancelled,trueotherwise
-
registerDispatcher
public void registerDispatcher(foo.zaaarf.geb.api.IEventDispatcher<?> dispatcher) Registers the dispatcher of an event type.GEB only calls the listeners of an event type once its dispatcher is registered on the bus, and drops events that have none without any warning. Dispatchers are generated by GEB's annotation processor for classes with
@Listenmethods.A bus keeps one dispatcher per event type: registering a dispatcher replaces the one registered earlier for the same event type. To undo a registration later, prefer
dispatcher(IEventDispatcher), which returns a connection that does it.- Parameters:
dispatcher- dispatcher to register
-
unregisterDispatcher
public void unregisterDispatcher(foo.zaaarf.geb.api.IEventDispatcher<?> dispatcher) Unregisters the dispatcher of an event type; its listeners stop being called.Only the very same dispatcher instance is removed: if another one has replaced it for that event type in the meantime, nothing happens.
- Parameters:
dispatcher- dispatcher to unregister
-
dispatcher
Registers a dispatcher and returns a connection that unregisters it.Disconnecting removes the dispatcher only if it is still the one registered for its event type; see
unregisterDispatcher(IEventDispatcher). This is how a plugin that registers dispatchers on a bus that outlives it (such as the shared bus) cleans up after itself.- Parameters:
dispatcher- dispatcher to register- Returns:
- connection that unregisters the dispatcher
-
dispatcher
public Connection dispatcher(ConnectionGroup group, foo.zaaarf.geb.api.IEventDispatcher<?> dispatcher) Registers a dispatcher and tracks its connection in a group.- Parameters:
group- group that will unregister the dispatcherdispatcher- dispatcher to register- Returns:
- connection that unregisters the dispatcher
-
loadAndRegisterDispatchers
Registers every dispatcher a class loader lists inMETA-INF/services/foo.zaaarf.geb.api.IEventDispatcher, the file GEB's annotation processor writes.Pass the class loader of the plugin that defines the
@Listenmethods, for examplegetClass().getClassLoader()in the plugin's main class. The dispatchers stay registered until the bus is gone; useloadDispatchers(ClassLoader)to be able to unregister them.- Parameters:
classLoader- class loader to read the service file from
-
loadDispatchers
Registers every dispatcher a class loader lists inMETA-INF/services/foo.zaaarf.geb.api.IEventDispatcherand returns one connection that unregisters all of them.Disconnect it when your plugin disables: a bus that outlives the plugin (the shared bus does) would otherwise keep the plugin's dispatchers, and with them its class loader, alive after a reload.
It is all or nothing: if the service file is broken, the dispatchers registered up to that point are unregistered again before the failure is rethrown.
- Parameters:
classLoader- class loader to read the service file from- Returns:
- connection that unregisters every dispatcher this call registered
- Throws:
ServiceConfigurationError- if the service file lists a class that cannot be loaded or instantiated
-
loadDispatchers
Registers the dispatchers of a class loader and tracks their connection in a group.- Parameters:
group- group that will unregister the dispatchersclassLoader- class loader to read the service file from- Returns:
- connection that unregisters every dispatcher this call registered
- See Also:
-
listen
Registers a listener and returns a connection that unregisters it.The listener is only called for event types whose dispatcher is registered, see
registerDispatcher(IEventDispatcher).- Parameters:
listener- listener to register- Returns:
- connection that unregisters the listener
-
listen
Registers a listener and tracks its connection in a group.- Parameters:
group- group that will disconnect the listenerlistener- listener to register- Returns:
- connection that unregisters the listener
-
registerListener
public void registerListener(foo.zaaarf.geb.api.IListener listener) Registers a listener.- Parameters:
listener- listener to register
-
unregisterListener
public void unregisterListener(foo.zaaarf.geb.api.IListener listener) Unregisters a listener.- Parameters:
listener- listener to unregister
-
isRegistered
public boolean isRegistered(foo.zaaarf.geb.api.IListener listener) Tells whether a listener is registered.- Parameters:
listener- listener to check- Returns:
trueif registered
-
subBus
Registers a sub-bus and returns a connection that unregisters it.- Parameters:
subBus- bus to forward events topriority- sub-bus priority- Returns:
- connection that unregisters the sub-bus
-
subBus
Registers a sub-bus and tracks its connection in a group.- Parameters:
group- group that will unregister the sub-bussubBus- bus to forward events topriority- sub-bus priority- Returns:
- connection that unregisters the sub-bus
-
registerSubBus
public void registerSubBus(foo.zaaarf.geb.api.IBus subBus, int priority) Registers a sub-bus.- Parameters:
subBus- bus to forward events topriority- sub-bus priority
-
unregisterSubBus
public void unregisterSubBus(foo.zaaarf.geb.api.IBus subBus) Unregisters a sub-bus.- Parameters:
subBus- bus to stop forwarding to
-
isRegistered
public boolean isRegistered(foo.zaaarf.geb.api.IBus subBus) Tells whether a sub-bus is registered.- Parameters:
subBus- bus to check- Returns:
trueif registered
-
hasSubBuses
public boolean hasSubBuses()Tells whether any sub-bus is registered through this bridge.Everything fired on this bus is forwarded to its sub-buses, and what they do with it cannot be inspected. A sub-bus registered directly on the raw
bus()instead of through this bridge is not seen here.- Returns:
trueif at least one sub-bus is registered
-