hunt.shiro.event.EventBus

Undocumented in source.

Members

Interfaces

EventBus
interface EventBus

An event bus can publish events to event subscribers as well as provide a mechanism for registering and unregistering event subscribers. <p/> 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. <h2>Sending Events</h2> If a component wishes to publish events to other components: <pre> MyEvent myEvent = createMyEvent(); eventBus.publish(myEvent); </pre> The event bus will determine the type of event and then dispatch the event to components that wish to receive events of that type. <h2>Receiving Events</h2> A component can receive events of interest by doing the following. <ol> <li>For each type of event you wish to consume, create a method that accepts a single event argument. The method argument type indicates the type of event to receive.</li> <li>Annotate each of these methods with the {@link hunt.shiro.event.Subscribe Subscribe} annotation.</li> <li>Register the component with the event bus: <pre> eventBus.register(myComponent); </pre> </li> </ol> After registering the component, when when an event of a respective type is published, the component's {@code Subscribe}-annotated method(s) will be invoked as expected. <p/> This design (and its constituent helper components) was largely influenced by Guava's <a href="http://docs.guava-libraries.googlecode.com/git/javadoc/com/google/common/eventbus/EventBus.html">EventBus</a> concept, although no code was viewed/copied/imported (even though Guava code is Apache 2.0 licensed and could have been used).

Meta