class TimedReferrer<T> extends Object implements UntouchableReferrer<T>, TimeBomb
| Modifier and Type | Field and Description |
|---|---|
private long |
clock |
private boolean |
enqued |
private Object |
lock |
private TimedRefQueue |
queue |
private long |
read |
private T |
referent |
| Constructor and Description |
|---|
TimedReferrer(T k,
TimedRefQueue q) |
| Modifier and Type | Method and Description |
|---|---|
void |
clear() |
boolean |
enqueue() |
boolean |
equals(Object o)
Equals is calculated on IDENTITY or EQUALITY.
|
T |
get() |
int |
hashCode()
Standard hashCode calculation for IDENTITY based references, where k
is the referent.
|
boolean |
isEnqueued() |
T |
lookDontTouch() |
String |
toString() |
void |
updateClock(long time) |
private volatile long clock
private volatile long read
private final TimedRefQueue queue
private final T referent
private volatile boolean enqued
private final Object lock
TimedReferrer(T k, TimedRefQueue q)
public T get()
get in interface Referrer<T>Reference.get()public void clear()
clear in interface Referrer<T>Reference.clear()public boolean isEnqueued()
isEnqueued in interface Referrer<T>Reference.isEnqueued()public boolean enqueue()
enqueue in interface Referrer<T>Reference.enqueue()public void updateClock(long time)
updateClock in interface TimeBombpublic boolean equals(Object o)
ReferrerEquals is calculated on IDENTITY or EQUALITY.
IDENTITY calculation:
if (this == o) return true;
if (!(o instanceof Referrer)) return false;
Object k1 = get();
Object k2 = ((Referrer) o).get();
if ( k1 != null && k1 == k2 ) return true;
return ( k1 == null && k2 == null && hashCode() == o.hashCode());
if (this == o) return true; // Same reference.
if (!(o instanceof Referrer)) return false;
Object k1 = get();
Object k2 = ((Referrer) o).get();
if ( k1 != null && k1.equals(k2)) return true;
return ( k1 == null && k2 == null && hashCode() == o.hashCode());
public int hashCode()
ReferrerStandard hashCode calculation for IDENTITY based references, where k is the referent. This may be stored in a final field:
int hash = 7;
hash = 29 * hash + System.identityHashCode(k);
hash = 29 * hash + k.getClass().hashCode();
Standard hashCode calculation for EQUALITY based references, where k is the referent:
int hash = 7;
hash = 29 * hash + k.hashCode();
hash = 29 * hash + k.getClass().hashCode();
The hash must be calculated during construction and if the reference is cleared, the recorded hashCode returned. While the referent remains reachable the hashCode must be calculated each time.
public T lookDontTouch()
lookDontTouch in interface UntouchableReferrer<T>Copyright 2007-2013, multiple authors.
Licensed under the Apache License, Version 2.0, see the NOTICE file for attributions.