Class StopCondition

java.lang.Object
de.otto.synapse.channel.StopCondition

public final class StopCondition extends Object
Conditions used in receiver endpoints to specify under which circumstances message consumption should stop.
  • Method Details

    • shutdown

      public static Predicate<ShardResponse> shutdown()
      Do not stop message consumption until the application is shutting down.
      Returns:
      stop condition always returning false;
    • timestamp

      public static Predicate<ShardResponse> timestamp(Instant timestamp)
      Returns a stop condition that is true after the given timestamp.
      Parameters:
      timestamp - the point in time after which the predicate will return true.
      Returns:
      stop condition
    • timestamp

      public static Predicate<ShardResponse> timestamp(Instant timestamp, Clock clock)
      Returns a stop condition that is true after the given timestamp.
      Parameters:
      timestamp - the point in time after which the predicate will return true.
      clock - the clock used to get the current time
      Returns:
      stop condition
    • arrivalTimestampAfterNow

      public static Predicate<ShardResponse> arrivalTimestampAfterNow()
      Returns a stop condition that is true if at least one message contained in the ShardResponse has arrived after creating the predicate.
      Returns:
      stop condition
    • arrivalTimestampAfterNow

      public static Predicate<ShardResponse> arrivalTimestampAfterNow(Clock clock)
      Returns a stop condition that is true if at least one message contained in the ShardResponse has arrived after creating the predicate.
      Parameters:
      clock - the clock used to get the current time
      Returns:
      stop condition
    • endOfChannel

      public static Predicate<ShardResponse> endOfChannel()
      Returns a stop condition that is true if the end-of-channel is reached.

      It is assumed that end-of-channel is reached if ShardResponse.getDurationBehind() is Duration.ZERO, even if ShardResponse.getMessages() is not empty.

      Note that using this predicate as a stop condition for sharded message logs, the message consumption will stop after all shards have reached the end of the channels at least once.

      Returns:
      stop condition
    • emptyResponse

      public static Predicate<ShardResponse> emptyResponse()
      Returns a stop condition that is true if the ShardResponse does not contain any messages.

      An empty ShardResponse does not necessarily indicate that the end-of-channel is reached. Especially in case of Kinesis message logs it is possible that multiple ShardResponses contain no messages, while the ShardResponse.getDurationBehind() is greater ZERO.

      You might want to combine this predicate with endOfChannel() like this:

      
           StopCondition.endOfChannel().and(StopCondition.emptyResponse());
       

      Note that using this predicate as a stop condition for sharded message logs, the message consumption will stop after all shards have reached the end of the channels at least once.

      Returns:
      stop condition