Class DelayedConsumerHashMap<T>

  • Type Parameters:
    T - Type of the task the consumer will execute

    public class DelayedConsumerHashMap<T>
    extends Object
    Accepts a consumer which executes all provided tasks in a batch no more often than the delay specified. Tasks are labeled by id and will replace each other if they arrive within the grace period while ensuring that the task scheduled last will eventually be executed.
    1. Event( key = 1) arrives. Consumer has not executed a task therefore it is executed immediately.
    2. Event( key = 2) arrives. Consumer is currently sleeping
    3. Event( key = 1) arrives. Consumer is currently sleeping
    4. Event( key = 2) arrives. Consumer is currently sleeping. The first event with key 2 is replaced and will never be executed.
    5. Grace period over. Execute Event(key = 2) and Event( key = 1)
    6. Lay dormant until new tasks arrive
    Due to the use of internal locks no polling takes place.
    Since:
    1.0.0 com.github.kilianB
    Author:
    Kilian
    • Constructor Detail

      • DelayedConsumerHashMap

        public DelayedConsumerHashMap​(Consumer<T> consumer,
                                      int sleep)
    • Method Detail

      • put

        public void put​(Integer key,
                        T object)