java.lang.Object
it.rebirthproject.ufoeb.architecture.state.MemoryState

public class MemoryState extends Object
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 Details

    • logger

      private static final org.slf4j.Logger logger
      The logger used by this class
    • eventsRegistrations

      private final EventsRegistrationsMap eventsRegistrations
      Data structure used to map each listener's registration metadata stored into the memory state
    • listenerToEventsMap

      private final Map<Object,Set<EventMethodKey>> 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

      private final Map<BusEventKey,Object> stickyEventsMap
      Map data structure containing all the metadata related to sticky events
    • eventSuperClassesAndInterfacesCache

      private final Map<Class<?>,Set<Class<?>>> eventSuperClassesAndInterfacesCache
      A map used to cache superclasses and interfaces related to an event class
    • safeRegistrationsListNeeded

      private final boolean safeRegistrationsListNeeded
      This attribute ensures that workers gets an unmodifiable Registration'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

      private final EventsRegistrationsMap foundListenerStickyEventsRegistrations
      Partial registrations on sticky events for each Listener (used only in listener registration)
    • inheritancePolicy

      private final InheritancePolicy inheritancePolicy
      The chosen system inheritancePolicy is stored here.
      See Also:
    • verboseLogging

      private final boolean verboseLogging
      Attribute 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 safeRegistrationsListNeeded
      inheritancePolicy - The chosen system inheritancePolicy to use
      verboseLogging - If set to true verbose logging will be enabled
  • Method Details

    • getRegistrations

      public List<Registration> getRegistrations(BusEventKey busEventKey)
      Get the list of listeners registrations for a particular event
      Parameters:
      busEventKey - The BusEventKey is used to retrieve all related listeners registrations
      Returns:
      The list of listeners registrations for the specified event
    • registrationMapContainsKey

      public boolean registrationMapContainsKey(BusEventKey busEventKey)
      Check if the eventsRegistrations map contains the specified BusEventKey
      Parameters:
      busEventKey - The BusEventKey to check for
      Returns:
      True if the eventsRegistrations map contains the specified BusEventKey or false otherwise
    • isEventsRegistrationsEmpty

      public boolean isEventsRegistrationsEmpty()
      Check if the eventsRegistrations map is empty
      Returns:
      True if the eventsRegistrations is empty or false otherwise
    • getEventEventsRegistrationsSize

      public int getEventEventsRegistrationsSize()
      Get the eventsRegistrations map size
      Returns:
      The size of the eventsRegistrations
    • registerListener

      public void registerListener(BusEventKey eventKey, Registration registration)
      Method used to register a listener in the memory state
      Parameters:
      eventKey - The BusEventKey of the event to register
      registration - The Registration containing all the metadata of the listener to register
    • getFoundListenerStickyEventsRegistrations

      public EventsRegistrationsMap getFoundListenerStickyEventsRegistrations()
      Gets the found lister sticky events registrations
      Returns:
      The found listener sticky events registrations
    • isStickyEventRegistered

      public boolean isStickyEventRegistered(BusEventKey eventKey)
      Check if a sticky event with a specified BusEventKey is registered in the stickyEventsMap
      Parameters:
      eventKey - The BusEventKey to check
      Returns:
      True if the sticky event with the specified BusEventKey is already registered in the stickyEventsMap or false otherwise
    • getStickyEvent

      public Object getStickyEvent(BusEventKey eventKey)
      Get a saved sticky event into the stickyEventsMap if present specifying its BusEventKey
      Parameters:
      eventKey - The BusEventKey of the sticky event
      Returns:
      The sticky event with the specified BusEventKey
    • registerStickyEvent

      public void registerStickyEvent(BusEventKey eventKey, Object event)
      Register a sticky event in the memory state
      Parameters:
      eventKey - The BusEventKey of the sticky event to register
      event - The sticky event to register
    • unregisterStickyEvent

      public void unregisterStickyEvent(BusEventKey eventKey)
      Unregister a sticky event from the memory state
      Parameters:
      eventKey - The BusEventKey of the sticky event to register
    • removeAllStickyEvents

      public void removeAllStickyEvents()
      Remove all the sticky events from the memory state
    • isListenerRegistered

      public boolean isListenerRegistered(Object listener)
      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

      public void unregisterListener(Object listenerToUnregister)
      Method used to unregister a listener from the memory state
      Parameters:
      listenerToUnregister - The listener to unregister from memory state
    • getEventSuperClassesAndInterfaces

      public Set<Class<?>> getEventSuperClassesAndInterfaces(Object eventObjectToPost)
      Gets all the superclasses and interfaces for the event to post regarding the current InheritancePolicy
      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 the MemoryState
    • isNewListener

      private boolean isNewListener(Object listener)
      Checks if the specified listener is already registered in the listenerToEventsMap
      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 the eventsRegistrations
    • printListenerToEventsMap

      private void printListenerToEventsMap()
      Print all the data in the listenerToEventsMap