Class PassiveLeaseTimeSet<E>

  • All Implemented Interfaces:
    ILeaseTimeSet<E>, java.lang.Iterable<E>, java.util.Collection<E>

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

      Fields 
      Modifier and Type Field Description
      protected java.util.PriorityQueue<E> entries
      The entries.
      protected long leasetime
      The leasetime.
      static long NONE
      Constant for no leasetime.
      protected ICommand<Tuple2<E,​java.lang.Long>> removecmd
      The cleaner.
      protected java.util.Map<E,​Tuple2<java.lang.Long,​java.lang.Long>> times
      The timestamps.
      static long UNSET
      Constant for unset leasetime (use global default otherwise no leasetime).
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      boolean add​(E e)  
      boolean add​(E e, long leasetime)
      Add a new entry.
      boolean addAll​(java.util.Collection<? extends E> c)  
      void checkStale()
      Start removing discovered entries.
      void clear()  
      boolean contains​(java.lang.Object o)  
      boolean containsAll​(java.util.Collection<?> c)  
      boolean equals​(java.lang.Object o)  
      protected long getClockTime()
      Get the current time.
      protected java.lang.Long getExpirationTime​(long leasetime)
      Get the expiration time.
      long getLeaseTime()
      Get the leasetime.
      int hashCode()
      Get the hashcode.
      boolean isEmpty()  
      java.util.Iterator<E> iterator()  
      boolean remove​(java.lang.Object o)  
      boolean removeAll​(java.util.Collection<?> c)  
      boolean retainAll​(java.util.Collection<?> c)  
      void setRemoveCommand​(ICommand<Tuple2<E,​java.lang.Long>> cmd)
      Set the remove cmd.
      int size()  
      java.lang.Object[] toArray()  
      <T> T[] toArray​(T[] a)  
      void touch​(E e)
      Update the timestamp of e.
      void touch​(E e, long leasetime)
      Update the timestamp of e.
      boolean update​(E e)
      Add a new entry or update an existing entry.
      boolean update​(E e, long leasetime)
      Add a new entry or update an existing entry.
      • Methods inherited from class java.lang.Object

        clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
      • Methods inherited from interface java.util.Collection

        parallelStream, removeIf, spliterator, stream, toArray
      • Methods inherited from interface java.lang.Iterable

        forEach
    • Field Detail

      • UNSET

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

        protected java.util.PriorityQueue<E> entries
        The entries.
      • times

        protected java.util.Map<E,​Tuple2<java.lang.Long,​java.lang.Long>> times
        The timestamps.
      • leasetime

        protected long leasetime
        The leasetime.
      • removecmd

        protected ICommand<Tuple2<E,​java.lang.Long>> removecmd
        The cleaner.
    • Constructor Detail

      • 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​(ICommand<Tuple2<E,​java.lang.Long>> removecmd)
        Create a new lease time handling object.
      • PassiveLeaseTimeSet

        public PassiveLeaseTimeSet​(long leasetime,
                                   ICommand<Tuple2<E,​java.lang.Long>> removecmd)
        Create a new lease time handling object.
    • Method Detail

      • size

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

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

        public boolean contains​(java.lang.Object o)
        Specified by:
        contains in interface java.util.Collection<E>
      • iterator

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

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

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

        public boolean add​(E e)
        Specified by:
        add in interface java.util.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​(java.lang.Object o)
        Specified by:
        remove in interface java.util.Collection<E>
      • containsAll

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

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

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

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

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

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

        public int hashCode()
        Get the hashcode.
        Specified by:
        hashCode in interface java.util.Collection<E>
        Overrides:
        hashCode in class java.lang.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 java.lang.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.