Class ProcessEventBus
java.lang.Object
neqsim.process.util.event.ProcessEventBus
- All Implemented Interfaces:
Serializable
Event bus for publishing and subscribing to process events.
Provides a publish-subscribe mechanism for process simulation events, enabling loose coupling between simulation components and external systems (like AI optimization platforms).
Supports:
- Type-based filtering
- Severity-based filtering
- Synchronous and asynchronous event delivery
- Event history for late subscribers
- Version:
- 1.0
- Author:
- ESOL
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate booleanprivate final List<ProcessEvent> private ExecutorServiceprivate final List<ProcessEventListener> private static ProcessEventBusprivate intprivate static final longprivate final Map<ProcessEvent.EventType, List<ProcessEventListener>> -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidClears event history.private voiddeliverAsync(ProcessEvent event) private voiddeliverSync(ProcessEvent event) getEventsBySeverity(ProcessEvent.Severity minSeverity, int count) Gets events by severity from history.getEventsByType(ProcessEvent.EventType type, int count) Gets events by type from history.intGets the total event count in history.static ProcessEventBusGets the singleton event bus instance.getRecentEvents(int count) Gets recent events from history.voidpublish(ProcessEvent event) Publishes an event to all subscribers.voidpublishAlarm(String source, String description) Publishes an alarm event.voidpublishInfo(String source, String description) Publishes an info event.voidpublishWarning(String source, String description) Publishes a warning event.static voidResets the singleton instance (for testing).voidsetAsyncDelivery(boolean async) Enables or disables asynchronous delivery.voidsetMaxHistorySize(int size) Sets the maximum history size.voidshutdown()Shuts down the event bus.voidsubscribe(ProcessEvent.EventType type, ProcessEventListener listener) Subscribes to events of a specific type.voidsubscribe(ProcessEventListener listener) Subscribes to all events.voidunsubscribe(ProcessEvent.EventType type, ProcessEventListener listener) Unsubscribes from a specific event type.voidunsubscribe(ProcessEventListener listener) Unsubscribes from all events.
-
Field Details
-
serialVersionUID
private static final long serialVersionUID- See Also:
-
instance
-
globalListeners
-
typeListeners
-
eventHistory
-
maxHistorySize
private int maxHistorySize -
asyncDelivery
private boolean asyncDelivery -
executor
-
-
Constructor Details
-
ProcessEventBus
public ProcessEventBus()Creates a new event bus (for non-singleton use).
-
-
Method Details
-
getInstance
Gets the singleton event bus instance.- Returns:
- event bus instance
-
subscribe
Subscribes to all events.- Parameters:
listener- event listener
-
subscribe
Subscribes to events of a specific type.- Parameters:
type- event typelistener- event listener
-
unsubscribe
Unsubscribes from all events.- Parameters:
listener- listener to remove
-
unsubscribe
Unsubscribes from a specific event type.- Parameters:
type- event typelistener- listener to remove
-
publish
Publishes an event to all subscribers.- Parameters:
event- event to publish
-
publishInfo
-
publishWarning
-
publishAlarm
-
deliverSync
-
deliverAsync
-
setAsyncDelivery
public void setAsyncDelivery(boolean async) Enables or disables asynchronous delivery.- Parameters:
async- true for async delivery
-
setMaxHistorySize
public void setMaxHistorySize(int size) Sets the maximum history size.- Parameters:
size- maximum events to retain
-
getRecentEvents
Gets recent events from history.- Parameters:
count- number of events to retrieve- Returns:
- list of recent events
-
getEventsByType
Gets events by type from history.- Parameters:
type- event typecount- maximum events to retrieve- Returns:
- list of events
-
getEventsBySeverity
Gets events by severity from history.- Parameters:
minSeverity- minimum severity levelcount- maximum events to retrieve- Returns:
- list of events
-
clearHistory
public void clearHistory()Clears event history. -
getHistorySize
public int getHistorySize()Gets the total event count in history.- Returns:
- event count
-
shutdown
public void shutdown()Shuts down the event bus. -
resetInstance
public static void resetInstance()Resets the singleton instance (for testing).
-