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
FieldsModifier and TypeFieldDescriptionprivate final BlockingQueue<Message>The message queue is used by theBusMemoryStateManagerto receive internal system messages.private final CountDownLatchACountDownLatchused during the shutdown phase to notify when theBusMemoryStateManageris shutting down.private final ListenerMethodFinderTheListenerMethodFinderis a service used to retrieve registered listeners methods annotated withListenand to store them inside theMemoryStateprivate static final org.slf4j.LoggerThe logger used by this classprivate final MemoryStateTheMemoryStateof theEventBusprivate final booleanA boolean flag used to determine if a throwNoRegistrationsWarning should be raised or not.private final ExecutorServiceThis is the thread pool cache that handles thread parallelism to obtain bus scalability. -
Constructor Summary
ConstructorsConstructorDescriptionBusMemoryStateManager(BlockingQueue<Message> commandQueryMessageQueue, ExecutorService workersPoolExecutor, CountDownLatch countDownLatch, MemoryState memoryState, ListenerMethodFinder listenerMethodFinder, boolean throwNoRegistrationsWarning) The constructor used to build theBusMemoryStateManager -
Method Summary
Modifier and TypeMethodDescriptionprivate voidmanageEventToPost(Object eventObjectToPost) Private method used to handle a message to post toEventExecutors workers.private voidPrivate method used to send an event toEventExecutors workersvoidrun()This method is called when theBusMemoryStateManager(which implements theRunnablejava 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 theBusMemoryStateManagerto 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
ACountDownLatchused during the shutdown phase to notify when theBusMemoryStateManageris shutting down. -
memoryState
TheMemoryStateof theEventBus -
listenerMethodFinder
TheListenerMethodFinderis a service used to retrieve registered listeners methods annotated withListenand 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 theBusMemoryStateManagerto 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 theBusMemoryStateManageris shutting down.memoryState- TheMemoryStateof theEventBuslistenerMethodFinder- TheListenerMethodFinderis a service used to retrieve registered listeners methods annotated withListenand to store them inside theMemoryStatethrowNoRegistrationsWarning- 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 theRunnablejava interface) starts his work after being executed in a separated thread. -
manageEventToPost
Private method used to handle a message to post toEventExecutors workers. This method will save data intomemoryStateif needed and then call thepostEvent(Object, Class)method to notify an event toEventExecutors- Parameters:
eventObjectToPost- The event to postEventExecutors- Throws:
InterruptedException- If there is an exception trying to send an event to workers.
-
postEvent
Private method used to send an event toEventExecutors workers- Parameters:
eventObjectToPost- The event to post toEventExecutorseventClass- The event class- Throws:
InterruptedException- If there is an exception trying to send an event to workers.
-