Package jadex.collection
Class PassiveLeaseTimeSet<E>
java.lang.Object
jadex.collection.PassiveLeaseTimeSet<E>
- All Implemented Interfaces:
ILeaseTimeSet<E>
,Iterable<E>
,Collection<E>
Collection that remove elements after a lease time on trigger.
This class is not synchronized.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected PriorityQueue
<E> The entries.protected long
The leasetime.static final long
Constant for no leasetime.The cleaner.The timestamps.static final long
Constant for unset leasetime (use global default otherwise no leasetime). -
Constructor Summary
ConstructorsConstructorDescriptionCreate a new lease time handling object.PassiveLeaseTimeSet
(long leasetime) Create a new lease time handling object.PassiveLeaseTimeSet
(long leasetime, Consumer<jadex.common.Tuple2<E, Long>> removecmd) Create a new lease time handling object.PassiveLeaseTimeSet
(Consumer<jadex.common.Tuple2<E, Long>> removecmd) Create a new lease time handling object. -
Method Summary
Modifier and TypeMethodDescriptionboolean
boolean
Add a new entry.boolean
addAll
(Collection<? extends E> c) void
Start removing discovered entries.void
clear()
boolean
boolean
containsAll
(Collection<?> c) boolean
protected long
Get the current time.protected Long
getExpirationTime
(long leasetime) Get the expiration time.long
Get the leasetime.int
hashCode()
Get the hashcode.boolean
isEmpty()
iterator()
boolean
boolean
removeAll
(Collection<?> c) boolean
retainAll
(Collection<?> c) void
setRemoveCommand
(Consumer<jadex.common.Tuple2<E, Long>> cmd) Set the remove cmd.int
size()
Object[]
toArray()
<T> T[]
toArray
(T[] a) void
Update the timestamp of e.void
Update the timestamp of e.boolean
Add a new entry or update an existing entry.boolean
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
-
Field Details
-
NONE
public static final long NONEConstant for no leasetime.- See Also:
-
UNSET
public static final long UNSETConstant for unset leasetime (use global default otherwise no leasetime).- See Also:
-
entries
The entries. -
times
The timestamps. -
leasetime
protected long leasetimeThe leasetime. -
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
Create a new lease time handling object. -
PassiveLeaseTimeSet
Create a new lease time handling object.
-
-
Method Details
-
setRemoveCommand
Set the remove cmd.- Specified by:
setRemoveCommand
in interfaceILeaseTimeSet<E>
-
size
public int size()- Specified by:
size
in interfaceCollection<E>
-
isEmpty
public boolean isEmpty()- Specified by:
isEmpty
in interfaceCollection<E>
-
contains
- Specified by:
contains
in interfaceCollection<E>
-
iterator
-
toArray
- Specified by:
toArray
in interfaceCollection<E>
-
toArray
public <T> T[] toArray(T[] a) - Specified by:
toArray
in interfaceCollection<E>
-
add
- Specified by:
add
in interfaceCollection<E>
-
add
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
- Specified by:
remove
in interfaceCollection<E>
-
containsAll
- Specified by:
containsAll
in interfaceCollection<E>
-
addAll
- Specified by:
addAll
in interfaceCollection<E>
-
removeAll
- Specified by:
removeAll
in interfaceCollection<E>
-
retainAll
- Specified by:
retainAll
in interfaceCollection<E>
-
clear
public void clear()- Specified by:
clear
in interfaceCollection<E>
-
equals
- Specified by:
equals
in interfaceCollection<E>
- Overrides:
equals
in classObject
-
hashCode
public int hashCode()Get the hashcode.- Specified by:
hashCode
in interfaceCollection<E>
- Overrides:
hashCode
in classObject
-
update
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
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
Update the timestamp of e.- Specified by:
touch
in interfaceILeaseTimeSet<E>
- Parameters:
entry
- The entry.
-
touch
Update the timestamp of e.- Specified by:
touch
in interfaceILeaseTimeSet<E>
- Parameters:
entry
- The entry.
-
getExpirationTime
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.
-