Top Description Inners Fields Constructors Methods
io.netty5.resolver.dns

pack-priv abstract Class Cache<E>

extends Object
Class Inheritance
Imports
io.netty5.channel.EventLoop, io.netty5.util.concurrent.EventExecutor, .Future, .FutureCompletionStage, .FutureContextListener, .FutureListener, .Promise, java.util.ArrayList, .Collections, .Iterator, .List, .Map, .Map.Entry, .Objects, java.util.concurrent.CancellationException, .ConcurrentHashMap, .ConcurrentMap, .Delayed, .TimeUnit, java.util.concurrent.atomic.AtomicReference, .AtomicReferenceFieldUpdater, java.util.function.Function

Abstract cache that automatically removes entries for a hostname once the TTL for an entry is reached.

Nested and Inner Type Summary

Modifier and TypeClass and Description
private class
private static class

Field Summary

Modifier and TypeField and Description
private static final Cache.FutureAndDelay
private static final Future<?>
private static final AtomicReferenceFieldUpdater<Cache.Entries, Cache.FutureAndDelay>
pack-priv static final int
private final ConcurrentMap<String, Cache<E>.Entries>

Constructor Summary

AccessConstructor and Description
pack-priv

Method Summary

Modifier and TypeMethod and Description
pack-priv final void
cache(String hostname, E value, int ttl, EventLoop loop)

Cache a value for the given hostname that will automatically expire once the TTL is reached.

pack-priv final void
clear()

Remove everything from the cache.

pack-priv final boolean
clear(String hostname)

Clear all entries (if anything exists) for the given hostname and return true if anything was removed.

protected abstract boolean
equals(E entry, E otherEntry)

Returns true if both entries are equal.

pack-priv final List<? extends E>
get(String hostname)

Returns all caches entries for the given hostname.

protected abstract boolean
shouldReplaceAll(E entry)

Returns true if this entry should replace all other entries that are already cached for the hostname.

pack-priv final int
size()

Return the number of hostnames for which we have cached something.

protected void
sortEntries(String hostname, List<E> entries)

Sort the List for a hostname before caching these.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

CANCELLEDback to summary
private static final Cache.FutureAndDelay CANCELLED
CANCELLED_FUTUREback to summary
private static final Future<?> CANCELLED_FUTURE
FUTURE_UPDATERback to summary
private static final AtomicReferenceFieldUpdater<Cache.Entries, Cache.FutureAndDelay> FUTURE_UPDATER
MAX_SUPPORTED_TTL_SECSback to summary
pack-priv static final int MAX_SUPPORTED_TTL_SECS
resolveCacheback to summary
private final ConcurrentMap<String, Cache<E>.Entries> resolveCache

Constructor Detail

Cacheback to summary
pack-priv Cache()

Method Detail

cacheback to summary
pack-priv final void cache(String hostname, E value, int ttl, EventLoop loop)

Cache a value for the given hostname that will automatically expire once the TTL is reached.

clearback to summary
pack-priv final void clear()

Remove everything from the cache.

clearback to summary
pack-priv final boolean clear(String hostname)

Clear all entries (if anything exists) for the given hostname and return true if anything was removed.

equalsback to summary
protected abstract boolean equals(E entry, E otherEntry)

Returns true if both entries are equal.

getback to summary
pack-priv final List<? extends E> get(String hostname)

Returns all caches entries for the given hostname.

shouldReplaceAllback to summary
protected abstract boolean shouldReplaceAll(E entry)

Returns true if this entry should replace all other entries that are already cached for the hostname.

sizeback to summary
pack-priv final int size()

Return the number of hostnames for which we have cached something.

sortEntriesback to summary
protected void sortEntries(String hostname, List<E> entries)

Sort the List for a hostname before caching these.

io.netty5.resolver.dns back to summary

private final Class Cache.Entries

extends AtomicReference<List<E>>
implements Runnable
Class Inheritance
All Implemented Interfaces
java.lang.Runnable

Field Summary

Modifier and TypeField and Description
pack-priv volatile Cache.FutureAndDelay
private final String

Constructor Summary

AccessConstructor and Description
pack-priv
Entries(String hostname)

Method Summary

Modifier and TypeMethod and Description
pack-priv void
add(E e, int ttl, EventLoop loop)

pack-priv boolean
public void
run()

Implements java.lang.Runnable.run.

Runs this operation.
private void
Inherited from java.util.concurrent.atomic.AtomicReference:
accumulateAndGetcompareAndExchangecompareAndExchangeAcquirecompareAndExchangeReleasecompareAndSetgetgetAcquiregetAndAccumulategetAndSetgetAndUpdategetOpaquegetPlainlazySetsetsetOpaquesetPlainsetReleasetoStringupdateAndGetweakCompareAndSetweakCompareAndSetAcquireweakCompareAndSetPlainweakCompareAndSetReleaseweakCompareAndSetVolatile

Field Detail

expirationFutureback to summary
pack-priv volatile Cache.FutureAndDelay expirationFuture
hostnameback to summary
private final String hostname

Constructor Detail

Entriesback to summary
pack-priv Entries(String hostname)

Method Detail

addback to summary
pack-priv void add(E e, int ttl, EventLoop loop)
clearAndCancelback to summary
pack-priv boolean clearAndCancel()
runback to summary
public void run()

Implements java.lang.Runnable.run.

Doc from java.lang.Runnable.run.

Runs this operation.

Annotations
@Override
scheduleCacheExpirationIfNeededback to summary
private void scheduleCacheExpirationIfNeeded(int ttl, EventLoop loop)
io.netty5.resolver.dns back to summary

private final Class Cache.FutureAndDelay

extends Object
implements Delayed
Class Inheritance
All Implemented Interfaces
java.util.concurrent.Delayed, java.lang.Comparable

Field Summary

Modifier and TypeField and Description
pack-priv final long
pack-priv final Future<?>

Constructor Summary

AccessConstructor and Description
private
FutureAndDelay(Future<?> future, int ttl)

Method Summary

Modifier and TypeMethod and Description
pack-priv void
public int
compareTo(Delayed
the object to be compared.
other
)

Implements java.lang.Comparable.compareTo.

Compares this object with the specified object for order.
public boolean
equals(Object
the reference object with which to compare.
o
)

Overrides java.lang.Object.equals.

Indicates whether some other object is "equal to" this one.
public long
getDelay(TimeUnit
the time unit
unit
)

Implements java.util.concurrent.Delayed.getDelay.

Returns the remaining delay associated with this object, in the given time unit.
public int
hashCode()

Overrides java.lang.Object.hashCode.

Returns a hash code value for this object.
Inherited from java.lang.Object:
clonefinalizegetClassnotifynotifyAlltoStringwaitwaitwait

Field Detail

deadlineNanosback to summary
pack-priv final long deadlineNanos
futureback to summary
pack-priv final Future<?> future

Constructor Detail

FutureAndDelayback to summary
private FutureAndDelay(Future<?> future, int ttl)

Method Detail

cancelback to summary
pack-priv void cancel()
compareToback to summary
public int compareTo(Delayed other)

Implements java.lang.Comparable.compareTo.

Doc from java.lang.Comparable.compareTo.

Compares this object with the specified object for order. Returns a negative integer, zero, or a positive integer as this object is less than, equal to, or greater than the specified object.

The implementor must ensure signum(x.compareTo(y)) == -signum(y.compareTo(x)) for all x and y. (This implies that x.compareTo(y) must throw an exception if and only if y.compareTo(x) throws an exception.)

The implementor must also ensure that the relation is transitive: (x.compareTo(y) > 0 && y.compareTo(z) > 0) implies x.compareTo(z) > 0.

Finally, the implementor must ensure that x.compareTo(y)==0 implies that signum(x.compareTo(z)) == signum(y.compareTo(z)), for all z.

Parameters
other:Delayed

the object to be compared.

Returns:int

a negative integer, zero, or a positive integer as this object is less than, equal to, or greater than the specified object.

Annotations
@Override
equalsback to summary
public boolean equals(Object o)

Overrides java.lang.Object.equals.

Doc from java.lang.Object.equals.

Indicates whether some other object is "equal to" this one.

The equals method implements an equivalence relation on non-null object references:

  • It is reflexive: for any non-null reference value x, x.equals(x) should return true.
  • It is symmetric: for any non-null reference values x and y, x.equals(y) should return true if and only if y.equals(x) returns true.
  • It is transitive: for any non-null reference values x, y, and z, if x.equals(y) returns true and y.equals(z) returns true, then x.equals(z) should return true.
  • It is consistent: for any non-null reference values x and y, multiple invocations of x.equals(y) consistently return true or consistently return false, provided no information used in equals comparisons on the objects is modified.
  • For any non-null reference value x, x.equals(null) should return false.

An equivalence relation partitions the elements it operates on into equivalence classes; all the members of an equivalence class are equal to each other. Members of an equivalence class are substitutable for each other, at least for some purposes.

Parameters
o:Object

the reference object with which to compare.

Returns:boolean

true if this object is the same as the obj argument; false otherwise.

Annotations
@Override
getDelayback to summary
public long getDelay(TimeUnit unit)

Implements java.util.concurrent.Delayed.getDelay.

Doc from java.util.concurrent.Delayed.getDelay.

Returns the remaining delay associated with this object, in the given time unit.

Parameters
unit:TimeUnit

the time unit

Returns:long

the remaining delay; zero or negative values indicate that the delay has already elapsed

Annotations
@Override
hashCodeback to summary
public int hashCode()

Overrides java.lang.Object.hashCode.

Doc from java.lang.Object.hashCode.

Returns a hash code value for this object. This method is supported for the benefit of hash tables such as those provided by java.util.HashMap.

The general contract of hashCode is:

  • Whenever it is invoked on the same object more than once during an execution of a Java application, the hashCode method must consistently return the same integer, provided no information used in equals comparisons on the object is modified. This integer need not remain consistent from one execution of an application to another execution of the same application.
  • If two objects are equal according to the equals method, then calling the hashCode method on each of the two objects must produce the same integer result.
  • It is not required that if two objects are unequal according to the equals method, then calling the hashCode method on each of the two objects must produce distinct integer results. However, the programmer should be aware that producing distinct integer results for unequal objects may improve the performance of hash tables.
Returns:int

a hash code value for this object

Annotations
@Override