com.hazelcast.util.scheduler

## Class SecondsBasedEntryTaskScheduler<K,V>

- java.lang.Object
- - com.hazelcast.util.scheduler.SecondsBasedEntryTaskScheduler<K,V>

- Type Parameters:
    `K` - entry key type
    `V` - entry value type
  All Implemented Interfaces:
    EntryTaskScheduler<K,V>

      public final class SecondsBasedEntryTaskScheduler<K,V>
      extends Object
      implements EntryTaskScheduler<K,V>

  Schedule execution of an entry for seconds later. This is similar to a scheduled executor service, but instead of scheduling a execution for a specific millisecond, this service will schedule it with second proximity. For example, if delayMillis is 600 ms, then the entry will be scheduled to execute in 1 second. If delayMillis is 2400, then the entry will be scheduled to execute in 3 seconds. Therefore, delayMillis is ceil-ed to the next second. It gives up exact time scheduling to gain the power of: a) bulk execution of all operations within the same second or b) being able to reschedule (postpone) execution.

- - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `static double` | `FACTOR`

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `ScheduledEntry<K,V>` | `cancel(K key)` Cancel all scheduled executions with the given key.
    `void` | `cancelAll()` Cancel all scheduled executions
    `int` | `cancelIfExists(K key, V value)` Cancels the scheduled executions for the given key and value if present.
    `ScheduledEntry<K,V>` | `get(K key)` Return the entry for the scheduled key.
    `boolean` | `isEmpty()` Returns `true` if there are no scheduled entries.
    `boolean` | `schedule(long delayMillis, K key, V value)` Schedules (or reschedules) the execution of given entry.
    `String` | `toString()`

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait`

- - ### Field Detail

    - #### FACTOR

          public static final double FACTOR

      See Also:
        `ceilToSecond(long)`, Constant Field Values

  - ### Method Detail

    - #### schedule

          public boolean schedule(long delayMillis,
                                  K key,
                                  V value)

      Description copied from interface: `EntryTaskScheduler`
      Schedules (or reschedules) the execution of given entry. Key parameter is used to check whether there is an existing scheduling for this entry, see `ScheduleType` for possible behaviours in such case.
      Specified by:
        `schedule` in interface `EntryTaskScheduler<K,V>`
      Parameters:
        `delayMillis` - milliseconds to delay the execution.
        `key` - key of this scheduling.
        `value` - user object to pass back when it is time to execute.
      Returns:
        returns true if this call resulted in a new scheduling, false otherwise.

    - #### get

          public ScheduledEntry<K,V> get(K key)

      Description copied from interface: `EntryTaskScheduler`
      Return the entry for the scheduled key.
      Specified by:
        `get` in interface `EntryTaskScheduler<K,V>`
      Parameters:
        `key` - the scheduled key
      Returns:
        the scheduled execution, in case of `ScheduleType.FOR_EACH` a random one will be returned, or `null` if nothing was scheduled or everything already executed for this key

    - #### cancel

          public ScheduledEntry<K,V> cancel(K key)

      Description copied from interface: `EntryTaskScheduler`
      Cancel all scheduled executions with the given key.
      Specified by:
        `cancel` in interface `EntryTaskScheduler<K,V>`
      Parameters:
        `key` - the scheduled key
      Returns:
        the cancelled scheduled execution, in case of `ScheduleType.FOR_EACH` a random one will be returned, or `null` if nothing was scheduled or everything already executed for this key

    - #### cancelIfExists

          public int cancelIfExists(K key,
                                    V value)

      Description copied from interface: `EntryTaskScheduler`
      Cancels the scheduled executions for the given key and value if present. The method returns the number of cancelled scheduled entries.
      Specified by:
        `cancelIfExists` in interface `EntryTaskScheduler<K,V>`
      Parameters:
        `key` - the scheduled key
        `value` - the scheduled value
      Returns:
        the number of cancelled scheduled entries.

    - #### cancelAll

          public void cancelAll()

      Description copied from interface: `EntryTaskScheduler`
      Cancel all scheduled executions
      Specified by:
        `cancelAll` in interface `EntryTaskScheduler<K,V>`

    - #### toString

          public String toString()

      Overrides:
        `toString` in class `Object`

    - #### isEmpty

          public boolean isEmpty()

      Returns `true` if there are no scheduled entries.

Copyright © 2020. All rights reserved.