Class EventSource<T,E>
java.lang.Object
org.knime.gateway.impl.service.events.EventSource<T,E>
- Type Parameters:
T- the event type this event source is associated withE- the kind of event being emitted
- Direct Known Subclasses:
NodeViewStateEventSource,SelectionEventSource
An event source produces events that are forwarded to an event consumer.
The implementations call
sendEvent(Object) to emit events.
An event source is directly associated with a certain event-type and is able to register event listener
(addEventListenerFor(Object) depending on the concrete event type instance.- Author:
- Martin Horn, KNIME GmbH, Konstanz
-
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedEventSource(BiConsumer<String, Object> eventConsumer) protectedEventSource(EventConsumer eventConsumer) -
Method Summary
Modifier and TypeMethodDescriptionaddEventListenerAndGetInitialEventFor(T eventTypeEnt) Registers a listener with the event source for the specified type of event and optionally returns the very first event to 'catch up' (instead of passing it to the associated event consumer).voidaddEventListenerFor(T eventTypeEnt) Registers a listener with the event source for the specified type of event.voidaddEventListenerFor(T eventTypeEnt, String workflowProjectId) Registers a listener with the event source for the specified type of event.protected abstract StringgetName()protected voidFor testing purposes only!abstract voidRemoves all event listeners registered with the event source.abstract voidremoveEventListener(T eventTypeEnt) Removes an event listener for a particular event type instance.protected final voidCalled by sub-classes to emit an event.protected final voidCalled by sub-classes to emit an event.final voidsetPreEventCreationCallback(Runnable callback) For testing purposes only!
-
Constructor Details
-
EventSource
- Parameters:
eventConsumer- consumes the emitted events
-
EventSource
- Parameters:
eventConsumer- consumes the emitted events
-
-
Method Details
-
addEventListenerAndGetInitialEventFor
Registers a listener with the event source for the specified type of event and optionally returns the very first event to 'catch up' (instead of passing it to the associated event consumer).- Parameters:
eventTypeEnt-- Returns:
- the very first event or an empty optional if there isn't any (method must not wait for events to arrive - only returns if there is an event at event listener registration time)
- Throws:
IllegalArgumentException- if object describing the event type isn't valid
-
addEventListenerFor
Registers a listener with the event source for the specified type of event.- Parameters:
eventTypeEnt-- Throws:
IllegalArgumentException- if object describing the event type isn't valid
-
addEventListenerFor
Registers a listener with the event source for the specified type of event.- Parameters:
eventTypeEnt-workflowProjectId- id of the workflow project this event listener is associated with (i.e. the initial event, if there is one, will be associated wit that workflow project - seesendEvent(Object, String); can benull- Throws:
IllegalArgumentException- if object describing the event type isn't valid
-
removeEventListener
Removes an event listener for a particular event type instance.- Parameters:
eventTypeEnt-
-
removeAllEventListeners
public abstract void removeAllEventListeners()Removes all event listeners registered with the event source. After this method, no events will be emitted anymore. -
sendEvent
Called by sub-classes to emit an event.- Parameters:
event- the event instance
-
sendEvent
Called by sub-classes to emit an event. This event is associated with a dedicated workflow project (specified by the project id).- Parameters:
event- the event instanceprojectId-
-
getName
- Returns:
- a name unique to the event source
-
setPreEventCreationCallback
For testing purposes only!- Parameters:
callback-
-
preEventCreation
protected void preEventCreation()For testing purposes only!
-