Package jadex.collection
Class LeaseTimeSet<E>
java.lang.Object
jadex.collection.LeaseTimeSet<E>
- All Implemented Interfaces:
ILeaseTimeSet<E>
,Iterable<E>
,Collection<E>
Collection that remove elements after a lease time automatically.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionclass
The checker for removing entries.static class
Synchronized lease time collection. -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected LeaseTimeSet<E>.Checker
The current checker.protected PriorityQueue
<E> The entries.protected long
The leasetime.static final long
Constant for no leasetime.The cleaner.protected IDelayRunner
The timer.The timestamps.static final long
Constant for unset leasetime (use global default otherwise no leasetime). -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotected
Create a new lease time handling object.protected
LeaseTimeSet
(long leasetime) Create a new lease time handling object.protected
LeaseTimeSet
(long leasetime, Consumer<jadex.common.Tuple2<E, Long>> removecmd) Create a new lease time handling object.LeaseTimeSet
(long leasetime, Consumer<jadex.common.Tuple2<E, Long>> removecmd, IDelayRunner timer) Create a new lease time handling object.protected
LeaseTimeSet
(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 proxies.void
clear()
boolean
boolean
containsAll
(Collection<?> c) static <E> ILeaseTimeSet
<E> createLeaseTimeCollection
(long leasetime) Create a lease time collection.static <E> ILeaseTimeSet
<E> createLeaseTimeCollection
(long leasetime, boolean passive, Consumer<jadex.common.Tuple2<E, Long>> removecmd) Create a lease time collection.static <E> ILeaseTimeSet
<E> createLeaseTimeCollection
(long leasetime, Consumer<jadex.common.Tuple2<E, Long>> removecmd) Create a lease time collection.static <E> ILeaseTimeSet
<E> createLeaseTimeCollection
(long leasetime, Consumer<jadex.common.Tuple2<E, Long>> removecmd, boolean passive, IDelayRunner timer, boolean sync, Object mutex) Create a lease time collection.static <E> ILeaseTimeSet
<E> createLeaseTimeCollection
(long leasetime, Consumer<jadex.common.Tuple2<E, Long>> removecmd, Object mutex) Create a lease time collection.void
dispose()
Release all resources.Overriden wait for to not use platform clock.boolean
protected long
Get the current time.protected Long
getExpirationTime
(long leasetime) Get the expiration time.long
Get the leasetime.getLeaseTime
(E entry) Get the leasetime.int
hashCode()
Get the hashcode.boolean
isEmpty()
iterator()
static void
Main for testing.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) toString()
Get the string representation.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, 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. -
timer
The timer. -
leasetime
protected long leasetimeThe leasetime. -
checker
The current checker. -
removecmd
The cleaner.
-
-
Constructor Details
-
LeaseTimeSet
protected LeaseTimeSet()Create a new lease time handling object. -
LeaseTimeSet
protected LeaseTimeSet(long leasetime) Create a new lease time handling object. -
LeaseTimeSet
Create a new lease time handling object. -
LeaseTimeSet
Create a new lease time handling object. -
LeaseTimeSet
public LeaseTimeSet(long leasetime, Consumer<jadex.common.Tuple2<E, Long>> removecmd, IDelayRunner timer) Create a new lease time handling object.
-
-
Method Details
-
createLeaseTimeCollection
Create a lease time collection. -
createLeaseTimeCollection
public static <E> ILeaseTimeSet<E> createLeaseTimeCollection(long leasetime, Consumer<jadex.common.Tuple2<E, Long>> removecmd) Create a lease time collection. -
createLeaseTimeCollection
public static <E> ILeaseTimeSet<E> createLeaseTimeCollection(long leasetime, boolean passive, Consumer<jadex.common.Tuple2<E, Long>> removecmd) Create a lease time collection. -
createLeaseTimeCollection
public static <E> ILeaseTimeSet<E> createLeaseTimeCollection(long leasetime, Consumer<jadex.common.Tuple2<E, Long>> removecmd, Object mutex) Create a lease time collection. -
createLeaseTimeCollection
public static <E> ILeaseTimeSet<E> createLeaseTimeCollection(long leasetime, Consumer<jadex.common.Tuple2<E, Long>> removecmd, boolean passive, IDelayRunner timer, boolean sync, Object mutex) Create a lease time collection. -
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 proxies. -
doWaitFor
Overriden wait for to not use platform clock. -
getClockTime
protected long getClockTime()Get the current time. -
getLeaseTime
public long getLeaseTime()Get the leasetime. -
getLeaseTime
Get the leasetime. -
dispose
public void dispose()Release all resources. -
toString
Get the string representation. -
main
Main for testing.
-