/* SPDX-License-Identifier: MIT */ package com.cecilia.event; import java.util.function.Consumer; public interface EventBus { /** * Subscribe to an event type. * * @param eventType the event type, can be a super class of all events to subscribe. * @param subscriber the subscriber which will consume the events. * @param the event type class. */ void subscribe(Class eventType, Consumer subscriber); /** * Unsubscribe from all event types. * * @param subscriber the subscriber to unsubscribe. */ void unsubscribe(Consumer subscriber); /** * Unsubscribe from an event type. * * @param eventType the event type, can be a super class of all events to unsubscribe. * @param subscriber the subscriber to unsubscribe. * @param the event type class. */ void unsubscribe(Class eventType, Consumer subscriber); /** * Publish an event to all subscribers. * *

The event type is the class of event. The event is published to all consumers which subscribed to * this event type or any super class. * * @param event the event. */ void publish(T event); }