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 with
E - the kind of event being emitted
Direct Known Subclasses:
NodeViewStateEventSource, SelectionEventSource

public abstract class EventSource<T,E> extends Object
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 Details

    • EventSource

      protected EventSource(BiConsumer<String,Object> eventConsumer)
      Parameters:
      eventConsumer - consumes the emitted events
    • EventSource

      protected EventSource(EventConsumer eventConsumer)
      Parameters:
      eventConsumer - consumes the emitted events
  • Method Details

    • addEventListenerAndGetInitialEventFor

      public abstract Optional<E> addEventListenerAndGetInitialEventFor(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).
      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

      public void addEventListenerFor(T eventTypeEnt)
      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

      public void addEventListenerFor(T eventTypeEnt, String workflowProjectId)
      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 - see sendEvent(Object, String); can be null
      Throws:
      IllegalArgumentException - if object describing the event type isn't valid
    • removeEventListener

      public abstract void removeEventListener(T eventTypeEnt)
      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

      protected final void sendEvent(E event)
      Called by sub-classes to emit an event.
      Parameters:
      event - the event instance
    • sendEvent

      protected final void sendEvent(E event, String projectId)
      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 instance
      projectId -
    • getName

      protected abstract String getName()
      Returns:
      a name unique to the event source
    • setPreEventCreationCallback

      public final void setPreEventCreationCallback(Runnable callback)
      For testing purposes only!
      Parameters:
      callback -
    • preEventCreation

      protected void preEventCreation()
      For testing purposes only!