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
Modifier and TypeFieldDescriptionprivate final EventBusInfrastructure
TheEventBusInfrastructure
is a class that manage the internal components of theEventBus
private static final org.slf4j.Logger
The logger used by this class -
Constructor Summary
ConstructorDescriptionUfoEventBus
(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.void
Posts the given event to the eventbus.void
postSticky
(Object event) Posts the given event to the eventbus that saves it (because it's sticky).void
Tells the bus to log its memory state for debug pourpose.private void
Prints basic information about the used Java VM and the UfoEventBus versionvoid
Registers a listener to the eventbus to receive specific events.void
Removes all the sticky events from eventbus.void
removeSticky
(Class<?> eventClass) Removes a sticky event from the eventbus given the event type.void
removeSticky
(Object event) Removes a sticky event from the eventbus.void
Shutdown the eventbus infrastructure.void
unregister
(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
TheEventBusInfrastructure
is 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:EventBus
Registers 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 theListen
annotation.- Specified by:
register
in interfaceEventBus
- Parameters:
listenerToRegister
- The listener to register- Throws:
EventBusException
- If the listener is null or something fails while registering
-
unregister
Description copied from interface:EventBus
Unregisters the given listener from the eventbus.- Specified by:
unregister
in 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:EventBus
Posts 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:
post
in 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:EventBus
Posts 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:
postSticky
in 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:EventBus
Removes a sticky event from the eventbus given the event type.- Specified by:
removeSticky
in 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:EventBus
Removes a sticky event from the eventbus.- Specified by:
removeSticky
in 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:EventBus
Removes all the sticky events from eventbus.- Specified by:
removeAllSticky
in interfaceEventBus
- Throws:
EventBusException
- If some error occurs while removing all the sticky events
-
isRegistered
Description copied from interface:EventBus
Checks if the passed object is already registered in the eventbus for listening to events.- Specified by:
isRegistered
in 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:EventBus
Tells the bus to log its memory state for debug pourpose.- Specified by:
printBusState
in interfaceEventBus
- Throws:
EventBusException
-
shutdownBus
public void shutdownBus()Description copied from interface:EventBus
Shutdown 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:
shutdownBus
in interfaceEventBus
-
printEventbusInformation
private void printEventbusInformation()Prints basic information about the used Java VM and the UfoEventBus version
-