Module it.rebirthproject.ufoeb
Class UfoEventBus
java.lang.Object
it.rebirthproject.ufoeb.architecture.eventbus.UfoEventBus
- All Implemented Interfaces:
EventBus
The concrete implementation of the
EventBus interface-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final EventBusInfrastructureTheEventBusInfrastructureis a class that manage the internal components of theEventBusprivate static final org.slf4j.LoggerThe logger used by this class -
Constructor Summary
ConstructorsConstructorDescriptionUfoEventBus(EventBusInfrastructure eventBusInfrastructure) The constructor used to build theUfoEventBus -
Method Summary
Modifier and TypeMethodDescriptionisRegistered(Object possibleRegisteredListener) Checks if the passed object is already registered in the eventbus for listening to events.voidPosts the given event to the eventbus.voidpostSticky(Object event) Posts the given event to the eventbus that saves it (because it's sticky).voidTells the bus to log its memory state for debug pourpose.private voidPrints basic information about the used Java VM and the UfoEventBus versionvoidRegisters a listener to the eventbus to receive specific events.voidRemoves all the sticky events from eventbus.voidremoveSticky(Class<?> eventClass) Removes a sticky event from the eventbus given the event type.voidremoveSticky(Object event) Removes a sticky event from the eventbus.voidShutdown the eventbus infrastructure.voidunregister(Object listenerToUnregister) Unregisters the given listener from the eventbus.
-
Field Details
-
logger
private static final org.slf4j.Logger loggerThe logger used by this class -
eventBusInfrastructure
TheEventBusInfrastructureis a class that manage the internal components of theEventBus
-
-
Constructor Details
-
UfoEventBus
UfoEventBus(EventBusInfrastructure eventBusInfrastructure) The constructor used to build theUfoEventBus- Parameters:
eventBusInfrastructure- TheEventBusInfrastructure
-
-
Method Details
-
register
Description copied from interface:EventBusRegisters a listener to the eventbus to receive specific events. Listeners must callEventBus.unregister(Object)once they are no longer interested in receiving events. Listeners event handling methods must be annotated with theListenannotation.- Specified by:
registerin interfaceEventBus- Parameters:
listenerToRegister- The listener to register- Throws:
EventBusException- If the listener is null or something fails while registering
-
unregister
Description copied from interface:EventBusUnregisters the given listener from the eventbus.- Specified by:
unregisterin interfaceEventBus- Parameters:
listenerToUnregister- The listener to unregister- Throws:
EventBusException- If the given listener is null or something fails while unregistering- See Also:
-
post
Description copied from interface:EventBusPosts the given event to the eventbus. This event will always be notified to and listened by registered listeners. Depending on which inheritance policy is chosen during bus initialization and on which event class/interface is listened by the listeners, listeners could get other events too. For example if an event extends a superclass or implements an interface. For a detailed explanation about inheritance policies refers toEventBusBuilder documentation- Specified by:
postin interfaceEventBus- Parameters:
event- The event to post- Throws:
EventBusException- If the event is null or some internal error occurs while posting the event
-
postSticky
Description copied from interface:EventBusPosts the given event to the eventbus that saves it (because it's sticky). Once new listeners register to the same sticky event they will be notified about the sticky event on registration. In this way it's possible to not lose events which are being already sent before the listener is being registered.- Specified by:
postStickyin interfaceEventBus- Parameters:
event- The 'sticky' event to post- Throws:
EventBusException- If the sticky event is null or some internal error occurs while posting the sticky event
-
removeSticky
Description copied from interface:EventBusRemoves a sticky event from the eventbus given the event type.- Specified by:
removeStickyin interfaceEventBus- Parameters:
eventClass- The class of a sticky event to remove- Throws:
EventBusException- If the class of the sticky event to remove is null or some internal error occurs while posting the sticky event- See Also:
-
removeSticky
Description copied from interface:EventBusRemoves a sticky event from the eventbus.- Specified by:
removeStickyin interfaceEventBus- Parameters:
event- The sticky event to remove- Throws:
EventBusException- If the sticky event is null or some internal error occurs while posting the sticky event- See Also:
-
removeAllSticky
Description copied from interface:EventBusRemoves all the sticky events from eventbus.- Specified by:
removeAllStickyin interfaceEventBus- Throws:
EventBusException- If some error occurs while removing all the sticky events
-
isRegistered
Description copied from interface:EventBusChecks if the passed object is already registered in the eventbus for listening to events.- Specified by:
isRegisteredin interfaceEventBus- Parameters:
possibleRegisteredListener- An object which represents a possible registered listener- Returns:
- A future wrapping a boolean value which will be true if the object passed to the method is a listener for some events or false otherwise
- Throws:
EventBusException- If the possibleRegisteredListener is null or some error occurs during isRegistered method execution- See Also:
-
printBusState
Description copied from interface:EventBusTells the bus to log its memory state for debug pourpose.- Specified by:
printBusStatein interfaceEventBus- Throws:
EventBusException
-
shutdownBus
public void shutdownBus()Description copied from interface:EventBusShutdown the eventbus infrastructure. This is needed to free memory and to stop background workers behind the scenes. Note: Make sure to call this method when there is no more need for an eventbus in your application, so this can be usually done before the application shutdown.- Specified by:
shutdownBusin interfaceEventBus
-
printEventbusInformation
private void printEventbusInformation()Prints basic information about the used Java VM and the UfoEventBus version
-