Package kos.core.events
Class EventBusSinkManager
- java.lang.Object
-
- kos.core.events.EventBusSinkManager
-
public class EventBusSinkManager extends Object
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description (package private) static classEventBusSinkManager.InitializationResult
-
Field Summary
Fields Modifier and Type Field Description private Set<Class>classesWhichCodedHaveBeenRegisteredprivate Iterable<EventPublisherSink>eventPublisherSinksprivate Iterable<EventSubscriptionSink>eventSubscriberSinksprotected KosContextkosContextprivate io.vertx.core.impl.logging.Loggerlogger
-
Constructor Summary
Constructors Constructor Description EventBusSinkManager(KosContext kosContext, Iterable<EventSubscriptionSink> eventSubscriberSinks, Iterable<EventPublisherSink> eventPublisherSinks)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description private <T> EventBusSink.EventBusSyncInitializationRequest<T>constructPublishingRequestFor(String address, Class<T> expectedType)<T> io.vertx.core.eventbus.MessageProducer<T>createProducer(String address, Class<T> expectedType)Creates aMessageProducerthat expects messages of typeEventBusSinkManager.<T> voidensureEventBusCanSerializeType(Class<T> targetType)private <T> EventBusSinkManager.InitializationResultperformInitialization(@NonNull String address, Class<T> expectedType, Iterable<? extends EventBusSink> eventBusSinks)<T> voidsubscribe(String address, Class<T> expectedType, io.vertx.core.Handler<io.vertx.core.eventbus.Message<T>> messageHandler)Registers a message consumermessageHandlerthat will receive messages of the typeEventBusSinkManagerpublished into the givenaddress.(package private) <T> EventBusSinkManager.InitializationResulttryInitializeSink(@NonNull String address, Class<T> expectedType, Iterable<? extends EventBusSink> eventBusSinks)Initializes the Sink responsible for bridging the communication between the localEventBuswith a remote broker, if any.
-
-
-
Field Detail
-
logger
private final io.vertx.core.impl.logging.Logger logger
-
kosContext
protected final KosContext kosContext
-
eventSubscriberSinks
private final Iterable<EventSubscriptionSink> eventSubscriberSinks
-
eventPublisherSinks
private final Iterable<EventPublisherSink> eventPublisherSinks
-
-
Constructor Detail
-
EventBusSinkManager
public EventBusSinkManager(KosContext kosContext, Iterable<EventSubscriptionSink> eventSubscriberSinks, Iterable<EventPublisherSink> eventPublisherSinks)
-
-
Method Detail
-
subscribe
public <T> void subscribe(String address, Class<T> expectedType, io.vertx.core.Handler<io.vertx.core.eventbus.Message<T>> messageHandler)
Registers a message consumermessageHandlerthat will receive messages of the typeEventBusSinkManagerpublished into the givenaddress.- Parameters:
address- a free-format String.EventPublisherSinkimplementations might have to parse this address to communicate with external services.expectedType- the expected contract used when serialising messages.- Throws:
KosException- whenever it reaches a terminal, but unrecoverable state.
-
createProducer
public <T> io.vertx.core.eventbus.MessageProducer<T> createProducer(String address, Class<T> expectedType)
Creates aMessageProducerthat expects messages of typeEventBusSinkManager.- Parameters:
address- a free-format String.EventPublisherSinkimplementations might have to parse this address to communicate with external services.expectedType- the expected contract used when serialising messages.- Throws:
KosException- whenever it reaches a terminal, but unrecoverable state.
-
tryInitializeSink
final <T> EventBusSinkManager.InitializationResult tryInitializeSink(@NonNull @NonNull String address, Class<T> expectedType, Iterable<? extends EventBusSink> eventBusSinks)
Initializes the Sink responsible for bridging the communication between the localEventBuswith a remote broker, if any. Sinks must be able to successfully finish its initialization. Any Exception thrown during this process will be considered a terminal, non-recoverable state - leading to an abrupt interruption of the whole application.- Returns:
-
performInitialization
private <T> EventBusSinkManager.InitializationResult performInitialization(@NonNull @NonNull String address, Class<T> expectedType, Iterable<? extends EventBusSink> eventBusSinks)
-
constructPublishingRequestFor
private <T> EventBusSink.EventBusSyncInitializationRequest<T> constructPublishingRequestFor(String address, Class<T> expectedType)
-
ensureEventBusCanSerializeType
public <T> void ensureEventBusCanSerializeType(Class<T> targetType)
-
-