Class ChoreographyEventBus
java.lang.Object
com.tnsai.coordination.choreography.ChoreographyEventBus
Event-driven bus for choreography coordination.
Supports topic-based publish/subscribe with event history.
Example usage:
ChoreographyEventBus bus = new ChoreographyEventBus();
bus.subscribe("order.placed", (name, event) -> processOrder(event));
bus.publish(ChoreographyEvent.of("order.placed", "system", "order-123"));
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final recordAn event published on the choreography bus. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidclear()Clears all subscribers and history.voidclose()Closes the event bus, rejecting further publishes.intReturns the number of events in history.Returns all events with a specific name.booleanChecks if a specific event name was ever published.history()Returns a copy of the event history.booleanisClosed()Returns whether the bus is closed.voidPublishes an event to all subscribers of that event name.voidsubscribe(String eventName, BiConsumer<String, ChoreographyEventBus.ChoreographyEvent> handler) Subscribes a handler to events with the given name.
-
Constructor Details
-
ChoreographyEventBus
public ChoreographyEventBus() -
ChoreographyEventBus
public ChoreographyEventBus(int maxHistory)
-
-
Method Details
-
subscribe
public void subscribe(String eventName, BiConsumer<String, ChoreographyEventBus.ChoreographyEvent> handler) Subscribes a handler to events with the given name. -
publish
Publishes an event to all subscribers of that event name. -
history
Returns a copy of the event history. -
eventCount
public int eventCount()Returns the number of events in history. -
hasEvent
Checks if a specific event name was ever published. -
eventsOf
Returns all events with a specific name. -
clear
public void clear()Clears all subscribers and history. -
close
public void close()Closes the event bus, rejecting further publishes. -
isClosed
public boolean isClosed()Returns whether the bus is closed.
-