Package jadex.commons.collection
Class PassiveLeaseTimeSet<E>
- java.lang.Object
-
- jadex.commons.collection.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).
-
Constructor Summary
Constructors Constructor Description PassiveLeaseTimeSet()
Create a new lease time handling object.PassiveLeaseTimeSet(long leasetime)
Create a new lease time handling object.PassiveLeaseTimeSet(long leasetime, ICommand<Tuple2<E,java.lang.Long>> removecmd)
Create a new lease time handling object.PassiveLeaseTimeSet(ICommand<Tuple2<E,java.lang.Long>> removecmd)
Create a new lease time handling object.
-
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
-
-
-
-
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.
-
leasetime
protected long leasetime
The leasetime.
-
-
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.
-
-
Method Detail
-
setRemoveCommand
public void setRemoveCommand(ICommand<Tuple2<E,java.lang.Long>> cmd)
Set the remove cmd.- Specified by:
setRemoveCommand
in interfaceILeaseTimeSet<E>
-
size
public int size()
- Specified by:
size
in interfacejava.util.Collection<E>
-
isEmpty
public boolean isEmpty()
- Specified by:
isEmpty
in interfacejava.util.Collection<E>
-
contains
public boolean contains(java.lang.Object o)
- Specified by:
contains
in interfacejava.util.Collection<E>
-
iterator
public java.util.Iterator<E> iterator()
-
toArray
public java.lang.Object[] toArray()
- Specified by:
toArray
in interfacejava.util.Collection<E>
-
toArray
public <T> T[] toArray(T[] a)
- Specified by:
toArray
in interfacejava.util.Collection<E>
-
add
public boolean add(E e, long leasetime)
Description copied from interface:ILeaseTimeSet
Add a new entry.- Specified by:
add
in interfaceILeaseTimeSet<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 interfacejava.util.Collection<E>
-
containsAll
public boolean containsAll(java.util.Collection<?> c)
- Specified by:
containsAll
in interfacejava.util.Collection<E>
-
addAll
public boolean addAll(java.util.Collection<? extends E> c)
- Specified by:
addAll
in interfacejava.util.Collection<E>
-
removeAll
public boolean removeAll(java.util.Collection<?> c)
- Specified by:
removeAll
in interfacejava.util.Collection<E>
-
retainAll
public boolean retainAll(java.util.Collection<?> c)
- Specified by:
retainAll
in interfacejava.util.Collection<E>
-
clear
public void clear()
- Specified by:
clear
in interfacejava.util.Collection<E>
-
equals
public boolean equals(java.lang.Object o)
- Specified by:
equals
in interfacejava.util.Collection<E>
- Overrides:
equals
in classjava.lang.Object
-
hashCode
public int hashCode()
Get the hashcode.- Specified by:
hashCode
in interfacejava.util.Collection<E>
- Overrides:
hashCode
in classjava.lang.Object
-
update
public boolean update(E e)
Add a new entry or update an existing entry.- Specified by:
update
in 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:
update
in interfaceILeaseTimeSet<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 interfaceILeaseTimeSet<E>
- Parameters:
entry
- The entry.
-
touch
public void touch(E e, long leasetime)
Update the timestamp of e.- Specified by:
touch
in 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 entries.
-
getClockTime
protected long getClockTime()
Get the current time.
-
getLeaseTime
public long getLeaseTime()
Get the leasetime.
-
-