- All Known Implementing Classes:
public interface EventBusAn event bus can publish events to event subscribers as well as provide a mechanism for registering and unregistering event subscribers. An event bus enables a publish/subscribe paradigm within Shiro - components can publish or consume events they find relevant without needing to be tightly coupled to other components. This affords great flexibility within Shiro by promoting loose coupling and high cohesion between components and a much safer pluggable architecture.
Sending EventsIf a component wishes to publish events to other components:
MyEvent myEvent = createMyEvent(); eventBus.publish(myEvent);The event bus will determine the type of event and then dispatch the event to components that wish to receive events of that type.
Receiving EventsA component can receive events of interest by doing the following.
- For each type of event you wish to consume, create a public method that accepts a single event argument. The method argument type indicates the type of event to receive.
- Annotate each of these public methods with the
- Register the component with the event bus:
Subscribe-annotated method(s) will be invoked as expected. This design (and its constituent helper components) was largely influenced by Guava's EventBus concept, although no code was viewed/copied/imported (even though Guava code is Apache 2.0 licensed and could have been used).
All Methods Instance Methods Abstract Methods Modifier and Type Method Description
publish(Object event)Publishes the specified event to an event subsystem that will deliver events to relevant
register(Object subscriber)Registers all event handler methods on the specified instance to receive relevant events.
unregister(Object subscriber)Unregisters all previously-registered event handler methods on the specified instance.
event- The event object to distribute to relevant subscribers.
registerRegisters all event handler methods on the specified instance to receive relevant events. The handler methods are determined by the
EventBusimplementation, typically by using an
subscriber- the object whose event handler methods should be registered to receive events.