Class PassiveLeaseTimeSet<E>

java.lang.Object
jadex.collection.PassiveLeaseTimeSet<E>
All Implemented Interfaces:
ILeaseTimeSet<E>, Iterable<E>, Collection<E>

public class PassiveLeaseTimeSet<E> extends Object implements ILeaseTimeSet<E>
Collection that remove elements after a lease time on trigger. This class is not synchronized.
  • Field Details

    • NONE

      public static final long NONE
      Constant for no leasetime.
      See Also:
    • UNSET

      public static final long UNSET
      Constant for unset leasetime (use global default otherwise no leasetime).
      See Also:
    • entries

      protected PriorityQueue<E> entries
      The entries.
    • times

      protected Map<E,jadex.common.Tuple2<Long,Long>> times
      The timestamps.
    • leasetime

      protected long leasetime
      The leasetime.
    • removecmd

      protected Consumer<jadex.common.Tuple2<E,Long>> removecmd
      The cleaner.
  • Constructor Details

    • PassiveLeaseTimeSet

      public PassiveLeaseTimeSet()
      Create a new lease time handling object.
    • PassiveLeaseTimeSet

      public PassiveLeaseTimeSet(long leasetime)
      Create a new lease time handling object.
    • PassiveLeaseTimeSet

      public PassiveLeaseTimeSet(Consumer<jadex.common.Tuple2<E,Long>> removecmd)
      Create a new lease time handling object.
    • PassiveLeaseTimeSet

      public PassiveLeaseTimeSet(long leasetime, Consumer<jadex.common.Tuple2<E,Long>> removecmd)
      Create a new lease time handling object.
  • Method Details

    • setRemoveCommand

      public void setRemoveCommand(Consumer<jadex.common.Tuple2<E,Long>> cmd)
      Set the remove cmd.
      Specified by:
      setRemoveCommand in interface ILeaseTimeSet<E>
    • size

      public int size()
      Specified by:
      size in interface Collection<E>
    • isEmpty

      public boolean isEmpty()
      Specified by:
      isEmpty in interface Collection<E>
    • contains

      public boolean contains(Object o)
      Specified by:
      contains in interface Collection<E>
    • iterator

      public Iterator<E> iterator()
      Specified by:
      iterator in interface Collection<E>
      Specified by:
      iterator in interface Iterable<E>
    • toArray

      public Object[] toArray()
      Specified by:
      toArray in interface Collection<E>
    • toArray

      public <T> T[] toArray(T[] a)
      Specified by:
      toArray in interface Collection<E>
    • add

      public boolean add(E e)
      Specified by:
      add in interface Collection<E>
    • add

      public boolean add(E e, long leasetime)
      Description copied from interface: ILeaseTimeSet
      Add a new entry.
      Specified by:
      add in interface ILeaseTimeSet<E>
      Parameters:
      e - The entry.
      leasetime - The leasetime.
      Returns:
      True, if new entry.
    • remove

      public boolean remove(Object o)
      Specified by:
      remove in interface Collection<E>
    • containsAll

      public boolean containsAll(Collection<?> c)
      Specified by:
      containsAll in interface Collection<E>
    • addAll

      public boolean addAll(Collection<? extends E> c)
      Specified by:
      addAll in interface Collection<E>
    • removeAll

      public boolean removeAll(Collection<?> c)
      Specified by:
      removeAll in interface Collection<E>
    • retainAll

      public boolean retainAll(Collection<?> c)
      Specified by:
      retainAll in interface Collection<E>
    • clear

      public void clear()
      Specified by:
      clear in interface Collection<E>
    • equals

      public boolean equals(Object o)
      Specified by:
      equals in interface Collection<E>
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Get the hashcode.
      Specified by:
      hashCode in interface Collection<E>
      Overrides:
      hashCode in class Object
    • update

      public boolean update(E e)
      Add a new entry or update an existing entry.
      Specified by:
      update in interface ILeaseTimeSet<E>
      Parameters:
      entry - The entry.
      Returns:
      True, if new entry.
    • update

      public boolean update(E e, long leasetime)
      Add a new entry or update an existing entry.
      Specified by:
      update in interface ILeaseTimeSet<E>
      Parameters:
      entry - The entry.
      Returns:
      True, if new entry.
    • touch

      public void touch(E e)
      Update the timestamp of e.
      Specified by:
      touch in interface ILeaseTimeSet<E>
      Parameters:
      entry - The entry.
    • touch

      public void touch(E e, long leasetime)
      Update the timestamp of e.
      Specified by:
      touch in interface ILeaseTimeSet<E>
      Parameters:
      entry - The entry.
    • getExpirationTime

      protected Long getExpirationTime(long leasetime)
      Get the expiration time.
      Parameters:
      leasetime -
      Returns:
    • checkStale

      public void checkStale()
      Start removing discovered entries.
    • getClockTime

      protected long getClockTime()
      Get the current time.
    • getLeaseTime

      public long getLeaseTime()
      Get the leasetime.