java.lang.Object
it.rebirthproject.ufoeb.architecture.state.MemoryState
The memory state of the
EventBus
. This class contains data structures
used by the bus to store events and registered classes (event listeners)- See Also:
-
Field Summary
Modifier and TypeFieldDescriptionprivate final EventsRegistrationsMap
Data structure used to map each listener's registration metadata stored into the memory stateA map used to cache superclasses and interfaces related to an event classprivate final EventsRegistrationsMap
Partial registrations on sticky events for each Listener (used only in listener registration)private final InheritancePolicy
The chosen system inheritancePolicy is stored here.private final Map<Object,
Set<EventMethodKey>> This map data structure contains all the registered listeners and their corresponding listened events keys A listener can listen to different events (one or more).private static final org.slf4j.Logger
The logger used by this classprivate final boolean
This attribute ensures that workers gets an unmodifiableRegistration
's list.private final Map<BusEventKey,
Object> Map data structure containing all the metadata related to sticky eventsprivate final boolean
Attribute set to true if verbose logging is enabled or to false otherwise -
Constructor Summary
ConstructorDescriptionMemoryState
(boolean safeRegistrationsListNeeded, InheritancePolicy inheritancePolicy, boolean verboseLogging) The constructor used to build the memory state -
Method Summary
Modifier and TypeMethodDescriptionint
Get theeventsRegistrations
map sizegetEventSuperClassesAndInterfaces
(Object eventObjectToPost) Gets all the superclasses and interfaces for the event to post regarding the currentInheritancePolicy
Gets the found lister sticky events registrationsgetRegistrations
(BusEventKey busEventKey) Get the list of listeners registrations for a particular eventgetStickyEvent
(BusEventKey eventKey) Get a saved sticky event into thestickyEventsMap
if present specifying itsBusEventKey
boolean
Check if theeventsRegistrations
map is emptyboolean
isListenerRegistered
(Object listener) Returns a boolean which is true if the passed listener is currently registered in the memory state, or false otherwise.private boolean
isNewListener
(Object listener) Checks if the specified listener is already registered in thelistenerToEventsMap
boolean
isStickyEventRegistered
(BusEventKey eventKey) Check if a sticky event with a specifiedBusEventKey
is registered in thestickyEventsMap
private void
Print all the data in theeventsRegistrations
private void
Print all the data in thelistenerToEventsMap
void
Print all the useful data in theMemoryState
void
registerListener
(BusEventKey eventKey, Registration registration) Method used to register a listener in the memory statevoid
registerStickyEvent
(BusEventKey eventKey, Object event) Register a sticky event in the memory stateboolean
registrationMapContainsKey
(BusEventKey busEventKey) Check if theeventsRegistrations
map contains the specifiedBusEventKey
void
Remove all the sticky events from the memory statevoid
unregisterListener
(Object listenerToUnregister) Method used to unregister a listener from the memory statevoid
unregisterStickyEvent
(BusEventKey eventKey) Unregister a sticky event from the memory state
-
Field Details
-
logger
private static final org.slf4j.Logger loggerThe logger used by this class -
eventsRegistrations
Data structure used to map each listener's registration metadata stored into the memory state -
listenerToEventsMap
This map data structure contains all the registered listeners and their corresponding listened events keys A listener can listen to different events (one or more). -
stickyEventsMap
Map data structure containing all the metadata related to sticky events -
eventSuperClassesAndInterfacesCache
A map used to cache superclasses and interfaces related to an event class -
safeRegistrationsListNeeded
private final boolean safeRegistrationsListNeededThis attribute ensures that workers gets an unmodifiableRegistration
's list. For best performance this attribute should be set to false (default) and avoid to register/unregister listeners at runtime time. Otherwise, set it to true. -
foundListenerStickyEventsRegistrations
Partial registrations on sticky events for each Listener (used only in listener registration) -
inheritancePolicy
The chosen system inheritancePolicy is stored here.- See Also:
-
verboseLogging
private final boolean verboseLoggingAttribute set to true if verbose logging is enabled or to false otherwise
-
-
Constructor Details
-
MemoryState
public MemoryState(boolean safeRegistrationsListNeeded, InheritancePolicy inheritancePolicy, boolean verboseLogging) The constructor used to build the memory state- Parameters:
safeRegistrationsListNeeded
- The parameter to select whether the safeRegistrationsListNeededinheritancePolicy
- The chosen system inheritancePolicy to useverboseLogging
- If set to true verbose logging will be enabled
-
-
Method Details
-
getRegistrations
Get the list of listeners registrations for a particular event- Parameters:
busEventKey
- TheBusEventKey
is used to retrieve all related listeners registrations- Returns:
- The list of listeners registrations for the specified event
-
registrationMapContainsKey
Check if theeventsRegistrations
map contains the specifiedBusEventKey
- Parameters:
busEventKey
- TheBusEventKey
to check for- Returns:
- True if the
eventsRegistrations
map contains the specifiedBusEventKey
or false otherwise
-
isEventsRegistrationsEmpty
public boolean isEventsRegistrationsEmpty()Check if theeventsRegistrations
map is empty- Returns:
- True if the
eventsRegistrations
is empty or false otherwise
-
getEventEventsRegistrationsSize
public int getEventEventsRegistrationsSize()Get theeventsRegistrations
map size- Returns:
- The size of the
eventsRegistrations
-
registerListener
Method used to register a listener in the memory state- Parameters:
eventKey
- TheBusEventKey
of the event to registerregistration
- TheRegistration
containing all the metadata of the listener to register
-
getFoundListenerStickyEventsRegistrations
Gets the found lister sticky events registrations- Returns:
- The found listener sticky events registrations
-
isStickyEventRegistered
Check if a sticky event with a specifiedBusEventKey
is registered in thestickyEventsMap
- Parameters:
eventKey
- TheBusEventKey
to check- Returns:
- True if the sticky event with the specified
BusEventKey
is already registered in thestickyEventsMap
or false otherwise
-
getStickyEvent
Get a saved sticky event into thestickyEventsMap
if present specifying itsBusEventKey
- Parameters:
eventKey
- TheBusEventKey
of the sticky event- Returns:
- The sticky event with the specified
BusEventKey
-
registerStickyEvent
Register a sticky event in the memory state- Parameters:
eventKey
- TheBusEventKey
of the sticky event to registerevent
- The sticky event to register
-
unregisterStickyEvent
Unregister a sticky event from the memory state- Parameters:
eventKey
- TheBusEventKey
of the sticky event to register
-
removeAllStickyEvents
public void removeAllStickyEvents()Remove all the sticky events from the memory state -
isListenerRegistered
Returns a boolean which is true if the passed listener is currently registered in the memory state, or false otherwise.- Parameters:
listener
- The listener to check- Returns:
- A boolean true if the passed listener is registered in the memory state, or false otherwise
-
unregisterListener
Method used to unregister a listener from the memory state- Parameters:
listenerToUnregister
- The listener to unregister from memory state
-
getEventSuperClassesAndInterfaces
Gets all the superclasses and interfaces for the event to post regarding the currentInheritancePolicy
- Parameters:
eventObjectToPost
- The event to post- Returns:
- all the superclasses and interfaces for the event to post
regarding the current
InheritancePolicy
- See Also:
-
printState
public void printState()Print all the useful data in theMemoryState
-
isNewListener
Checks if the specified listener is already registered in thelistenerToEventsMap
- Parameters:
listener
- The listener to check- Returns:
- True if the specified listener is not present and false otherwise
-
printEventsRegistrations
private void printEventsRegistrations()Print all the data in theeventsRegistrations
-
printListenerToEventsMap
private void printListenerToEventsMap()Print all the data in thelistenerToEventsMap
-