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 class
LeaseTimeSet.Checker
The checker for removing entries.static class
LeaseTimeSet.SynchronizedLeaseTimeCollection<E>
Synchronized lease time collection.
-
Field Summary
Fields Modifier and Type Field Description protected LeaseTimeSet.Checker
checker
The current checker.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 IDelayRunner
timer
The timer.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 Modifier Constructor Description protected
LeaseTimeSet()
Create a new lease time handling object.protected
LeaseTimeSet(long leasetime)
Create a new lease time handling object.protected
LeaseTimeSet(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.protected
LeaseTimeSet(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 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 proxies.void
clear()
boolean
contains(java.lang.Object o)
boolean
containsAll(java.util.Collection<?> c)
static <E> ILeaseTimeSet<E>
createLeaseTimeCollection(long leasetime)
Create a lease time collection.static <E> ILeaseTimeSet<E>
createLeaseTimeCollection(long leasetime, boolean passive, 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)
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.void
dispose()
Release all resources.java.lang.Runnable
doWaitFor(long delay, java.lang.Runnable step)
Overriden wait for to not use platform clock.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.java.lang.Long
getLeaseTime(E entry)
Get the leasetime.int
hashCode()
Get the hashcode.boolean
isEmpty()
java.util.Iterator<E>
iterator()
static void
main(java.lang.String[] args)
Main for testing.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)
java.lang.String
toString()
Get the string representation.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, 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, 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.
-
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 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 classjava.lang.Object
-
main
public static void main(java.lang.String[] args)
Main for testing.
-
-