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
FieldsModifier and TypeFieldDescriptionprivate final EventsRegistrationsMapData 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 EventsRegistrationsMapPartial registrations on sticky events for each Listener (used only in listener registration)private final InheritancePolicyThe 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.LoggerThe logger used by this classprivate final booleanThis 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 booleanAttribute set to true if verbose logging is enabled or to false otherwise -
Constructor Summary
ConstructorsConstructorDescriptionMemoryState(boolean safeRegistrationsListNeeded, InheritancePolicy inheritancePolicy, boolean verboseLogging) The constructor used to build the memory state -
Method Summary
Modifier and TypeMethodDescriptionintGet theeventsRegistrationsmap sizegetEventSuperClassesAndInterfaces(Object eventObjectToPost) Gets all the superclasses and interfaces for the event to post regarding the currentInheritancePolicyGets 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 thestickyEventsMapif present specifying itsBusEventKeybooleanCheck if theeventsRegistrationsmap is emptybooleanisListenerRegistered(Object listener) Returns a boolean which is true if the passed listener is currently registered in the memory state, or false otherwise.private booleanisNewListener(Object listener) Checks if the specified listener is already registered in thelistenerToEventsMapbooleanisStickyEventRegistered(BusEventKey eventKey) Check if a sticky event with a specifiedBusEventKeyis registered in thestickyEventsMapprivate voidPrint all the data in theeventsRegistrationsprivate voidPrint all the data in thelistenerToEventsMapvoidPrint all the useful data in theMemoryStatevoidregisterListener(BusEventKey eventKey, Registration registration) Method used to register a listener in the memory statevoidregisterStickyEvent(BusEventKey eventKey, Object event) Register a sticky event in the memory statebooleanregistrationMapContainsKey(BusEventKey busEventKey) Check if theeventsRegistrationsmap contains the specifiedBusEventKeyvoidRemove all the sticky events from the memory statevoidunregisterListener(Object listenerToUnregister) Method used to unregister a listener from the memory statevoidunregisterStickyEvent(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- TheBusEventKeyis used to retrieve all related listeners registrations- Returns:
- The list of listeners registrations for the specified event
-
registrationMapContainsKey
Check if theeventsRegistrationsmap contains the specifiedBusEventKey- Parameters:
busEventKey- TheBusEventKeyto check for- Returns:
- True if the
eventsRegistrationsmap contains the specifiedBusEventKeyor false otherwise
-
isEventsRegistrationsEmpty
public boolean isEventsRegistrationsEmpty()Check if theeventsRegistrationsmap is empty- Returns:
- True if the
eventsRegistrationsis empty or false otherwise
-
getEventEventsRegistrationsSize
public int getEventEventsRegistrationsSize()Get theeventsRegistrationsmap size- Returns:
- The size of the
eventsRegistrations
-
registerListener
Method used to register a listener in the memory state- Parameters:
eventKey- TheBusEventKeyof the event to registerregistration- TheRegistrationcontaining 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 specifiedBusEventKeyis registered in thestickyEventsMap- Parameters:
eventKey- TheBusEventKeyto check- Returns:
- True if the sticky event with the specified
BusEventKeyis already registered in thestickyEventsMapor false otherwise
-
getStickyEvent
Get a saved sticky event into thestickyEventsMapif present specifying itsBusEventKey- Parameters:
eventKey- TheBusEventKeyof the sticky event- Returns:
- The sticky event with the specified
BusEventKey
-
registerStickyEvent
Register a sticky event in the memory state- Parameters:
eventKey- TheBusEventKeyof the sticky event to registerevent- The sticky event to register
-
unregisterStickyEvent
Unregister a sticky event from the memory state- Parameters:
eventKey- TheBusEventKeyof 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
-