Package jadex.commons.collection
Class LeaseTimeSet<E>
- java.lang.Object
-
- jadex.commons.collection.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.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description classLeaseTimeSet.CheckerThe checker for removing entries.static classLeaseTimeSet.SynchronizedLeaseTimeCollection<E>Synchronized lease time collection.
-
Field Summary
Fields Modifier and Type Field Description protected LeaseTimeSet.CheckercheckerThe current checker.protected java.util.PriorityQueue<E>entriesThe entries.protected longleasetimeThe leasetime.static longNONEConstant for no leasetime.protected ICommand<Tuple2<E,java.lang.Long>>removecmdThe cleaner.protected IDelayRunnertimerThe timer.protected java.util.Map<E,Tuple2<java.lang.Long,java.lang.Long>>timesThe timestamps.static longUNSETConstant for unset leasetime (use global default otherwise no leasetime).
-
Constructor Summary
Constructors Modifier Constructor Description protectedLeaseTimeSet()Create a new lease time handling object.protectedLeaseTimeSet(long leasetime)Create a new lease time handling object.protectedLeaseTimeSet(long leasetime, ICommand<Tuple2<E,java.lang.Long>> removecmd)Create a new lease time handling object.LeaseTimeSet(long leasetime, ICommand<Tuple2<E,java.lang.Long>> removecmd, IDelayRunner timer)Create a new lease time handling object.protectedLeaseTimeSet(ICommand<Tuple2<E,java.lang.Long>> removecmd)Create a new lease time handling object.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description booleanadd(E e)booleanadd(E e, long leasetime)Add a new entry.booleanaddAll(java.util.Collection<? extends E> c)voidcheckStale()Start removing discovered proxies.voidclear()booleancontains(java.lang.Object o)booleancontainsAll(java.util.Collection<?> c)static <E> ILeaseTimeSet<E>createLeaseTimeCollection(long leasetime)Create a lease time collection.static <E> ILeaseTimeSet<E>createLeaseTimeCollection(long leasetime, ICommand<Tuple2<E,java.lang.Long>> removecmd)Create a lease time collection.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.static <E> ILeaseTimeSet<E>createLeaseTimeCollection(long leasetime, ICommand<Tuple2<E,java.lang.Long>> removecmd, java.lang.Object mutex)Create a lease time collection.voiddispose()Release all resources.java.lang.RunnabledoWaitFor(long delay, java.lang.Runnable step)Overriden wait for to not use platform clock.booleanequals(java.lang.Object o)protected longgetClockTime()Get the current time.protected java.lang.LonggetExpirationTime(long leasetime)Get the expiration time.longgetLeaseTime()Get the leasetime.java.lang.LonggetLeaseTime(E entry)Get the leasetime.inthashCode()Get the hashcode.booleanisEmpty()java.util.Iterator<E>iterator()static voidmain(java.lang.String[] args)Main for testing.booleanremove(java.lang.Object o)booleanremoveAll(java.util.Collection<?> c)booleanretainAll(java.util.Collection<?> c)voidsetRemoveCommand(ICommand<Tuple2<E,java.lang.Long>> cmd)Set the remove cmd.intsize()java.lang.Object[]toArray()<T> T[]toArray(T[] a)java.lang.StringtoString()Get the string representation.voidtouch(E e)Update the timestamp of e.voidtouch(E e, long leasetime)Update the timestamp of e.booleanupdate(E e)Add a new entry or update an existing entry.booleanupdate(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, wait, wait, wait
-
-
-
-
Field Detail
-
NONE
public static final long NONE
Constant for no leasetime.- See Also:
- Constant Field Values
-
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.
-
timer
protected IDelayRunner timer
The timer.
-
leasetime
protected long leasetime
The leasetime.
-
checker
protected LeaseTimeSet.Checker checker
The current checker.
-
-
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, 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.
-
setRemoveCommand
public void setRemoveCommand(ICommand<Tuple2<E,java.lang.Long>> cmd)
Set the remove cmd.- Specified by:
setRemoveCommandin interfaceILeaseTimeSet<E>
-
size
public int size()
- Specified by:
sizein interfacejava.util.Collection<E>
-
isEmpty
public boolean isEmpty()
- Specified by:
isEmptyin interfacejava.util.Collection<E>
-
contains
public boolean contains(java.lang.Object o)
- Specified by:
containsin interfacejava.util.Collection<E>
-
iterator
public java.util.Iterator<E> iterator()
-
toArray
public java.lang.Object[] toArray()
- Specified by:
toArrayin interfacejava.util.Collection<E>
-
toArray
public <T> T[] toArray(T[] a)
- Specified by:
toArrayin interfacejava.util.Collection<E>
-
add
public boolean add(E e, long leasetime)
Description copied from interface:ILeaseTimeSetAdd a new entry.- Specified by:
addin interfaceILeaseTimeSet<E>- Parameters:
e- The entry.leasetime- The leasetime.- Returns:
- True, if new entry.
-
remove
public boolean remove(java.lang.Object o)
- Specified by:
removein interfacejava.util.Collection<E>
-
containsAll
public boolean containsAll(java.util.Collection<?> c)
- Specified by:
containsAllin interfacejava.util.Collection<E>
-
addAll
public boolean addAll(java.util.Collection<? extends E> c)
- Specified by:
addAllin interfacejava.util.Collection<E>
-
removeAll
public boolean removeAll(java.util.Collection<?> c)
- Specified by:
removeAllin interfacejava.util.Collection<E>
-
retainAll
public boolean retainAll(java.util.Collection<?> c)
- Specified by:
retainAllin interfacejava.util.Collection<E>
-
clear
public void clear()
- Specified by:
clearin interfacejava.util.Collection<E>
-
equals
public boolean equals(java.lang.Object o)
- Specified by:
equalsin interfacejava.util.Collection<E>- Overrides:
equalsin classjava.lang.Object
-
hashCode
public int hashCode()
Get the hashcode.- Specified by:
hashCodein interfacejava.util.Collection<E>- Overrides:
hashCodein classjava.lang.Object
-
update
public boolean update(E e)
Add a new entry or update an existing entry.- Specified by:
updatein interfaceILeaseTimeSet<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:
updatein interfaceILeaseTimeSet<E>- Parameters:
entry- The entry.- Returns:
- True, if new entry.
-
touch
public void touch(E e)
Update the timestamp of e.- Specified by:
touchin interfaceILeaseTimeSet<E>- Parameters:
entry- The entry.
-
touch
public void touch(E e, long leasetime)
Update the timestamp of e.- Specified by:
touchin interfaceILeaseTimeSet<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:
toStringin classjava.lang.Object
-
main
public static void main(java.lang.String[] args)
Main for testing.
-
-