Class LeaseTimeSet<E>

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

    public class LeaseTimeSet<E>
    extends java.lang.Object
    implements ILeaseTimeSet<E>
    Collection that remove elements after a lease time automatically.
    • 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

      • LeaseTimeSet

        protected LeaseTimeSet()
        Create a new lease time handling object.
      • LeaseTimeSet

        protected LeaseTimeSet​(long leasetime)
        Create a new lease time handling object.
      • LeaseTimeSet

        protected LeaseTimeSet​(ICommand<Tuple2<E,​java.lang.Long>> removecmd)
        Create a new lease time handling object.
      • LeaseTimeSet

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

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

      • createLeaseTimeCollection

        public static <E> ILeaseTimeSet<E> createLeaseTimeCollection​(long leasetime)
        Create a lease time collection.
      • createLeaseTimeCollection

        public static <E> ILeaseTimeSet<E> createLeaseTimeCollection​(long leasetime,
                                                                     ICommand<Tuple2<E,​java.lang.Long>> removecmd)
        Create a lease time collection.
      • createLeaseTimeCollection

        public static <E> ILeaseTimeSet<E> createLeaseTimeCollection​(long leasetime,
                                                                     boolean passive,
                                                                     ICommand<Tuple2<E,​java.lang.Long>> removecmd)
        Create a lease time collection.
      • createLeaseTimeCollection

        public static <E> ILeaseTimeSet<E> createLeaseTimeCollection​(long leasetime,
                                                                     ICommand<Tuple2<E,​java.lang.Long>> removecmd,
                                                                     java.lang.Object mutex)
        Create a lease time collection.
      • createLeaseTimeCollection

        public static <E> ILeaseTimeSet<E> createLeaseTimeCollection​(long leasetime,
                                                                     ICommand<Tuple2<E,​java.lang.Long>> removecmd,
                                                                     boolean passive,
                                                                     IDelayRunner timer,
                                                                     boolean sync,
                                                                     java.lang.Object mutex)
        Create a lease time collection.
      • 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 proxies.
      • doWaitFor

        public java.lang.Runnable doWaitFor​(long delay,
                                            java.lang.Runnable step)
        Overriden wait for to not use platform clock.
      • getClockTime

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

        public long getLeaseTime()
        Get the leasetime.
      • getLeaseTime

        public java.lang.Long getLeaseTime​(E entry)
        Get the leasetime.
      • dispose

        public void dispose()
        Release all resources.
      • toString

        public java.lang.String toString()
        Get the string representation.
        Overrides:
        toString in class java.lang.Object
      • main

        public static void main​(java.lang.String[] args)
        Main for testing.