Interface Observer<T>

Type Parameters:
T - type of the observed event
Functional Interface:
This is a functional interface and can therefore be used as the assignment target for a lambda expression or method reference.

@FunctionalInterface public interface Observer<T>
Observes the events produced by an Observable. Once registered, it will receive all events currently in the backing Ringbuffer and then continue receiving any future events.

Jet calls this Observer's callbacks on an internal thread pool of limited size, shared with many other Hazelcast Jet services. Therefore the callbacks should take care to finish as quickly as possible.

Since:
Jet 4.0
  • Method Summary

    Modifier and Type
    Method
    Description
    static <T> Observer<T>
    of(ConsumerEx<? super T> onNext)
    Utility method for building an Observer only from its data callback, with default behaviour for completion & error.
    static <T> Observer<T>
    of(ConsumerEx<? super T> onNext, ConsumerEx<? super Throwable> onError, RunnableEx onComplete)
    Utility method for building an Observer from its basic callback components.
    default void
    Observes the completion event from the Observable it is registered with.
    default void
    onError(Throwable throwable)
    Observes an error event from the Observable it is registered with, in the form of an exception that reflects the underlying cause.
    void
    onNext(T t)
    Observes the next event from the Observable it is registered with.
  • Method Details

    • of

      @Nonnull static <T> Observer<T> of(@Nonnull ConsumerEx<? super T> onNext, @Nonnull ConsumerEx<? super Throwable> onError, @Nonnull RunnableEx onComplete)
      Utility method for building an Observer from its basic callback components.
    • of

      @Nonnull static <T> Observer<T> of(@Nonnull ConsumerEx<? super T> onNext)
      Utility method for building an Observer only from its data callback, with default behaviour for completion & error.
    • onNext

      void onNext(@Nonnull T t)
      Observes the next event from the Observable it is registered with.

      Although the Observable respects the order of events published to it, the publication order itself is generally non-deterministic. A Jet pipeline must be written with the specific goal of order preservation in mind. For example, a map/filter stage that doesn't explicitly set its local parallelism to 1 will reorder the data.

      After this observer has seen an error or completion event, it will see no further events.

    • onError

      default void onError(@Nonnull Throwable throwable)
      Observes an error event from the Observable it is registered with, in the form of an exception that reflects the underlying cause.

      After this observer has seen an error or completion event, it will see no further events.

    • onComplete

      default void onComplete()
      Observes the completion event from the Observable it is registered with. Only an observer attached to a batch job will ever see this event. Unbounded streaming jobs never complete without error.

      After this observer has seen an error or completion event, it will see no further events.