Module it.rebirthproject.ufoeb
Class BusMemoryStateManager
java.lang.Object
it.rebirthproject.ufoeb.architecture.state.BusMemoryStateManager
- All Implemented Interfaces:
Runnable
The bus memory state manager which stores and manages events and listeners
-
Field Summary
Modifier and TypeFieldDescriptionprivate final BlockingQueue<Message>
The message queue is used by theBusMemoryStateManager
to receive internal system messages.private final CountDownLatch
ACountDownLatch
used during the shutdown phase to notify when theBusMemoryStateManager
is shutting down.private final ListenerMethodFinder
TheListenerMethodFinder
is a service used to retrieve registered listeners methods annotated withListen
and to store them inside theMemoryState
private static final org.slf4j.Logger
The logger used by this classprivate final MemoryState
TheMemoryState
of theEventBus
private final boolean
A boolean flag used to determine if a throwNoRegistrationsWarning should be raised or not.private final ExecutorService
This is the thread pool cache that handles thread parallelism to obtain bus scalability. -
Constructor Summary
ConstructorDescriptionBusMemoryStateManager
(BlockingQueue<Message> commandQueryMessageQueue, ExecutorService workersPoolExecutor, CountDownLatch countDownLatch, MemoryState memoryState, ListenerMethodFinder listenerMethodFinder, boolean throwNoRegistrationsWarning) The constructor used to build theBusMemoryStateManager
-
Method Summary
Modifier and TypeMethodDescriptionprivate void
manageEventToPost
(Object eventObjectToPost) Private method used to handle a message to post toEventExecutor
s workers.private void
Private method used to send an event toEventExecutor
s workersvoid
run()
This method is called when theBusMemoryStateManager
(which implements theRunnable
java interface) starts his work after being executed in a separated thread.
-
Field Details
-
logger
private static final org.slf4j.Logger loggerThe logger used by this class -
commandQueryMessageQueue
The message queue is used by theBusMemoryStateManager
to receive internal system messages.example: (REGISTER_MESSAGE, UNREGISTER_MESSAGE, SHUTDOWN_STATE_MANAGER, etc... )
Once one of those messages is received, it will be handled accordingly. -
workersPoolExecutor
This is the thread pool cache that handles thread parallelism to obtain bus scalability. -
countDownLatch
ACountDownLatch
used during the shutdown phase to notify when theBusMemoryStateManager
is shutting down. -
memoryState
TheMemoryState
of theEventBus
-
listenerMethodFinder
TheListenerMethodFinder
is a service used to retrieve registered listeners methods annotated withListen
and to store them inside theMemoryState
-
throwNoRegistrationsWarning
private final boolean throwNoRegistrationsWarningA boolean flag used to determine if a throwNoRegistrationsWarning should be raised or not. If the flag is false no warning be will be thrown when an event is posted and no listeners are registered to listen to that precise event.
-
-
Constructor Details
-
BusMemoryStateManager
public BusMemoryStateManager(BlockingQueue<Message> commandQueryMessageQueue, ExecutorService workersPoolExecutor, CountDownLatch countDownLatch, MemoryState memoryState, ListenerMethodFinder listenerMethodFinder, boolean throwNoRegistrationsWarning) The constructor used to build theBusMemoryStateManager
- Parameters:
commandQueryMessageQueue
- The message queue is used by theBusMemoryStateManager
to receive internal system messages.example: (REGISTER_MESSAGE, UNREGISTER_MESSAGE, SHUTDOWN_STATE_MANAGER, etc... )
Once one of those messages is received, it will be handled accordingly.workersPoolExecutor
- This is the thread pool cache that handles thread parallelism to obtain bus scalability.countDownLatch
- A countDownLatch used during the shutdown phase to notify when theBusMemoryStateManager
is shutting down.memoryState
- TheMemoryState
of theEventBus
listenerMethodFinder
- TheListenerMethodFinder
is a service used to retrieve registered listeners methods annotated withListen
and to store them inside theMemoryState
throwNoRegistrationsWarning
- A boolean flag used to determine if a throwNoRegistrationsWarning should be raised or not. If the flag is false no warning be will be thrown when an event is posted and no listeners are registered to listen to that precise event.
-
-
Method Details
-
run
public void run()This method is called when theBusMemoryStateManager
(which implements theRunnable
java interface) starts his work after being executed in a separated thread. -
manageEventToPost
Private method used to handle a message to post toEventExecutor
s workers. This method will save data intomemoryState
if needed and then call thepostEvent(Object, Class)
method to notify an event toEventExecutor
s- Parameters:
eventObjectToPost
- The event to postEventExecutor
s- Throws:
InterruptedException
- If there is an exception trying to send an event to workers.
-
postEvent
Private method used to send an event toEventExecutor
s workers- Parameters:
eventObjectToPost
- The event to post toEventExecutor
seventClass
- The event class- Throws:
InterruptedException
- If there is an exception trying to send an event to workers.
-