Class StopCondition


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

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static java.util.function.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.
      static java.util.function.Predicate<ShardResponse> arrivalTimestampAfterNow​(java.time.Clock clock)
      Returns a stop condition that is true if at least one message contained in the ShardResponse has arrived after creating the predicate.
      static java.util.function.Predicate<ShardResponse> emptyResponse()
      Returns a stop condition that is true if the ShardResponse does not contain any messages.
      static java.util.function.Predicate<ShardResponse> endOfChannel()
      Returns a stop condition that is true if the end-of-channel is reached.
      static java.util.function.Predicate<ShardResponse> shutdown()
      Do not stop message consumption until the application is shutting down.
      static java.util.function.Predicate<ShardResponse> timestamp​(java.time.Instant timestamp)
      Returns a stop condition that is true after the given timestamp.
      static java.util.function.Predicate<ShardResponse> timestamp​(java.time.Instant timestamp, java.time.Clock clock)
      Returns a stop condition that is true after the given timestamp.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Method Detail

      • shutdown

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

        public static java.util.function.Predicate<ShardResponse> timestamp​(java.time.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 java.util.function.Predicate<ShardResponse> timestamp​(java.time.Instant timestamp,
                                                                            java.time.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 java.util.function.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 java.util.function.Predicate<ShardResponse> arrivalTimestampAfterNow​(java.time.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 java.util.function.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 java.util.function.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