public abstract class AbstractEventBus extends Object implements EventBus
This class implements the addition/removal of the various kinds of handlers and filters.
| Modifier and Type | Class and Description |
|---|---|
protected class |
AbstractEventBus.SubscriptionEntry<C>
Entity gathering all information regarding a subscription.
|
| Modifier and Type | Field and Description |
|---|---|
protected List<ExceptionHandler> |
exceptionHandlers
Registered unchecked exception handlers.
|
protected Map<Integer,AbstractEventBus.SubscriptionEntry<?>> |
idToSubscription
Mapping between subscription IDs and subscriptions.
|
protected Map<Topic<?>,Collection<AbstractEventBus.SubscriptionEntry<?>>> |
topicToSubscription
Mapping between subscriptions and topics.
|
protected List<EventHandler<Object>> |
undeliveredEventHandlers
Registerd handlers for undelivered events.
|
| Constructor and Description |
|---|
AbstractEventBus() |
| Modifier and Type | Method and Description |
|---|---|
void |
addExceptionHandler(ExceptionHandler handler)
Adds the specified exception handler that will be notified whenever and exception is thrown when an event is
being dispatched or processed by an event handler.
|
void |
addUndeliveredEventHandler(EventHandler<Object> handler)
Adds the specified event handler that will process events that have not been processed by any event handler
registered with
EventBus.subscribe(Topic, Channel, EventFilter, EventHandler). |
protected Channel |
createDefaultChannelForHandler(EventHandler<?> handler)
Creates a default, dedicated channel for the specified event handler.
|
void |
dispose()
Disposes the event bus by removing all event handlers, undelivered event handlers, stopping the dispatching
threads, etc.
|
protected abstract <C> void |
publish(Event<C> event)
Publishes the specified event on the event bus.
|
<C> void |
publish(Topic<C> topic,
C content)
Sends the specified content for the specified topic on the broadcast channel.
|
<C> void |
publish(Topic<C> topic,
Channel channel,
C content)
Sends the specified content for the specified topic on the specified channel.
|
void |
publish(Topic<Void> topic)
Sends null for the specified topic on the broadcast channel.
|
void |
removeExceptionHandler(ExceptionHandler handler)
Removes the specified exception handler
|
void |
removeUndeliveredEventHandler(EventHandler<Object> handler)
Removes the specified undelievered event handler.
|
<C> int |
subscribe(Topic<C> topic,
Channel channel,
EventFilter<? super C> filter,
EventHandler<? super C> handler)
Registers a subscriber for the specified topic on the specified channel with the specified filter by adding an
event handler.
|
<C> int |
subscribe(Topic<C> topic,
Channel channel,
EventHandler<? super C> handler)
Registers a subscriber for the specified topic on the specified channel by adding an event handler.
|
<C> int |
subscribe(Topic<C> topic,
EventFilter<? super C> filter,
EventHandler<? super C> handler)
Registers a subscriber for the specified topic with the specified filter by adding an event handler.
|
<C> int |
subscribe(Topic<C> topic,
EventHandler<? super C> handler)
Registers a subscriber for the specified topic by adding an event handler.
|
void |
unsubscribe(int id)
Unregisters a subscriber that was previously registered.
|
protected final List<ExceptionHandler> exceptionHandlers
protected final List<EventHandler<Object>> undeliveredEventHandlers
protected final Map<Topic<?>,Collection<AbstractEventBus.SubscriptionEntry<?>>> topicToSubscription
This mapping can be used to retrieve the event handlers interested in the topic used for the event being dispatched.
protected final Map<Integer,AbstractEventBus.SubscriptionEntry<?>> idToSubscription
This mapping can be used to unsubscribe event handlers.
public void addExceptionHandler(ExceptionHandler handler)
EventBusaddExceptionHandler in interface EventBushandler - Exception handler to be added.EventBus.addExceptionHandler(ExceptionHandler)public void removeExceptionHandler(ExceptionHandler handler)
EventBusremoveExceptionHandler in interface EventBushandler - Exception handler to be removed.EventBus.removeExceptionHandler(ExceptionHandler)public void addUndeliveredEventHandler(EventHandler<Object> handler)
EventBusEventBus.subscribe(Topic, Channel, EventFilter, EventHandler).addUndeliveredEventHandler in interface EventBushandler - Undelivered event handler to be added.EventBus.addUndeliveredEventHandler(EventHandler)public void removeUndeliveredEventHandler(EventHandler<Object> handler)
EventBusremoveUndeliveredEventHandler in interface EventBushandler - Undelivered event handler to be removed.EventBus.removeUndeliveredEventHandler(EventHandler)protected Channel createDefaultChannelForHandler(EventHandler<?> handler)
handler - Event handler to create a dedicated channel for.public final <C> int subscribe(Topic<C> topic, EventHandler<? super C> handler)
A default, dedicated channel will be used for this event handler.
C - Type of content to subscribe for.topic - Topic to subscribe for.handler - Event handler that will process the received events.unsubscribe(int).unsubscribe(int)public final <C> int subscribe(Topic<C> topic, Channel channel, EventHandler<? super C> handler)
A default, dedicated channel will be used for this event handler.
C - Type of content to subscribe for.topic - Topic to subscribe for.channel - Channel on which the events should be received.handler - Event handler that will process the received events.unsubscribe(int).public final <C> int subscribe(Topic<C> topic, EventFilter<? super C> filter, EventHandler<? super C> handler)
A default, dedicated channel will be used for this event handler.
C - Type of content to subscribe for.topic - Topic to subscribe for.filter - Additional filter that should be applied before receiving the events.handler - Event handler that will process the received events.unsubscribe(int).public final <C> int subscribe(Topic<C> topic, Channel channel, EventFilter<? super C> filter, EventHandler<? super C> handler)
EventBussubscribe in interface EventBusC - Type of content to subscribe for.topic - Topic to subscribe for.channel - Channel on which the events should be received.filter - Additional filter that should be applied before receiving the events.handler - Event handler that will process the received events.EventBus.unsubscribe(int).EventBus.subscribe(Topic, Channel, EventFilter, EventHandler)public void unsubscribe(int id)
EventBusunsubscribe in interface EventBusid - Identifier of a previous subscription.EventBus.unsubscribe(int)public final void publish(Topic<Void> topic)
The content will be wrapped in an Event that will be dispatched to the registered event handlers.
topic - Topic for which the content must be dispatched.publish(Topic, Channel, Object),
publish(Event)public final <C> void publish(Topic<C> topic, C content)
The content will be wrapped in an Event that will be dispatched to the registered event handlers.
C - Type of content to be dispatched.topic - Topic for which the content must be dispatched.content - Content to be dispatched.publish(Topic, Channel, Object),
publish(Event)public final <C> void publish(Topic<C> topic, Channel channel, C content)
EventBus
The content will be wrapped in an Event that will be dispatched to the registered event handlers.
publish in interface EventBusC - Type of content to be dispatched.topic - Topic for which the content must be dispatched.channel - Channel on which the event must be dispatched.content - Content to be dispatched.EventBus.publish(Topic, Channel, Object),
publish(Event)protected abstract <C> void publish(Event<C> event)
This method is called from the other publish methods.
C - Type of event content.event - Event to be dispatched.public void dispose()
EventBusAfter calling this method, the event bus may no longer be used, depending on the implementation.
dispose in interface EventBusEventBus.dispose()Copyright © 2017. All rights reserved.