Class MorkEventPublisher
java.lang.Object
es.urjc.etsii.grafo.events.MorkEventPublisher
- All Implemented Interfaces:
org.springframework.beans.factory.DisposableBean
@Component
public class MorkEventPublisher
extends Object
implements org.springframework.beans.factory.DisposableBean
Single async boundary between solver threads and event consumers.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic interfaceAutoCloseable mute scope. -
Constructor Summary
ConstructorsConstructorDescriptionMorkEventPublisher(Iterable<MorkEventListener> listeners, org.springframework.messaging.simp.SimpMessagingTemplate messagingTemplate, InMemoryEventLog eventLog) Build an event publisher with an explicit listener collection.MorkEventPublisher(org.springframework.beans.factory.ObjectProvider<MorkEventListener> listeners, org.springframework.messaging.simp.SimpMessagingTemplate messagingTemplate, InMemoryEventLog eventLog) Build event publisher, creating the single dispatcher thread. -
Method Summary
Modifier and TypeMethodDescriptionvoidAtomically start draining without waiting for it to finish.voiddestroy()Shut down the dispatcher when the Spring context closes.voidReject new external events, drain every accepted event (including events recursively published by listeners), and stop the dispatcher.booleanisMuted()Check whether events are muted.mute()Temporarily mute event publishing.voidPublish an event without executing listeners on the caller thread.voidpublishFinalAndBeginDraining(MorkEvent finalEvent) Atomically accept the terminal event and enter the draining state.
-
Constructor Details
-
MorkEventPublisher
@Autowired public MorkEventPublisher(org.springframework.beans.factory.ObjectProvider<MorkEventListener> listeners, org.springframework.messaging.simp.SimpMessagingTemplate messagingTemplate, InMemoryEventLog eventLog) Build event publisher, creating the single dispatcher thread.- Parameters:
listeners- backend event listeners provided by SpringmessagingTemplate- websocket messaging templateeventLog- in-memory replay log
-
MorkEventPublisher
public MorkEventPublisher(Iterable<MorkEventListener> listeners, org.springframework.messaging.simp.SimpMessagingTemplate messagingTemplate, InMemoryEventLog eventLog) Build an event publisher with an explicit listener collection.- Parameters:
listeners- backend event listenersmessagingTemplate- websocket messaging templateeventLog- in-memory replay log
-
-
Method Details
-
publish
Publish an event without executing listeners on the caller thread.- Parameters:
event- event payload
-
publishFinalAndBeginDraining
Atomically accept the terminal event and enter the draining state. No external publisher can insert an event after the terminal event.- Parameters:
finalEvent- terminal event payload
-
mute
Temporarily mute event publishing. Intended for warm-up or other unmeasured work.- Returns:
- scope that restores the previous mute depth when closed
-
isMuted
public boolean isMuted()Check whether events are muted.- Returns:
- true if events are muted
-
beginDraining
public void beginDraining()Atomically start draining without waiting for it to finish. New external publications are rejected as soon as this method returns. -
drainAndStop
public void drainAndStop()Reject new external events, drain every accepted event (including events recursively published by listeners), and stop the dispatcher. -
destroy
public void destroy()Shut down the dispatcher when the Spring context closes.- Specified by:
destroyin interfaceorg.springframework.beans.factory.DisposableBean
-