add() — netty Function Reference
Architecture documentation for the add() function in Cache.java from the netty codebase.
Entity Profile
Dependency Diagram
graph TD a3a06bb5_0cc7_b138_7d64_44cab8d3dafc["add()"] 0a5c7e5a_0868_706c_64ef_570d8eda93ed["Entries"] a3a06bb5_0cc7_b138_7d64_44cab8d3dafc -->|defined in| 0a5c7e5a_0868_706c_64ef_570d8eda93ed 827c41b3_0841_4a5b_8441_f3c6c5c4672f["cache()"] 827c41b3_0841_4a5b_8441_f3c6c5c4672f -->|calls| a3a06bb5_0cc7_b138_7d64_44cab8d3dafc 202af483_a3a9_66d1_9043_d090b9c3b8cd["equals()"] a3a06bb5_0cc7_b138_7d64_44cab8d3dafc -->|calls| 202af483_a3a9_66d1_9043_d090b9c3b8cd 6a024b6a_506e_e679_4216_7ad493859ffd["shouldReplaceAll()"] a3a06bb5_0cc7_b138_7d64_44cab8d3dafc -->|calls| 6a024b6a_506e_e679_4216_7ad493859ffd c0b89246_8ba9_ca82_e4a0_93b63e2ddcb9["get()"] a3a06bb5_0cc7_b138_7d64_44cab8d3dafc -->|calls| c0b89246_8ba9_ca82_e4a0_93b63e2ddcb9 5895be98_e21c_d80b_17de_2b02e0f75f9c["size()"] a3a06bb5_0cc7_b138_7d64_44cab8d3dafc -->|calls| 5895be98_e21c_d80b_17de_2b02e0f75f9c c13d2041_e562_e9af_db02_30f08b74c5b1["scheduleCacheExpirationIfNeeded()"] a3a06bb5_0cc7_b138_7d64_44cab8d3dafc -->|calls| c13d2041_e562_e9af_db02_30f08b74c5b1 e6619101_3e0e_73bd_20de_3b399bad275a["sortEntries()"] a3a06bb5_0cc7_b138_7d64_44cab8d3dafc -->|calls| e6619101_3e0e_73bd_20de_3b399bad275a style a3a06bb5_0cc7_b138_7d64_44cab8d3dafc fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
resolver-dns/src/main/java/io/netty/resolver/dns/Cache.java lines 173–231
void add(E e, int ttl, EventLoop loop) {
if (!shouldReplaceAll(e)) {
for (;;) {
List<E> entries = get();
if (!entries.isEmpty()) {
final E firstEntry = entries.get(0);
if (shouldReplaceAll(firstEntry)) {
assert entries.size() == 1;
if (compareAndSet(entries, singletonList(e))) {
scheduleCacheExpirationIfNeeded(ttl, loop);
return;
} else {
// Need to try again as CAS failed
continue;
}
}
// Create a new List for COW semantics
List<E> newEntries = new ArrayList<E>(entries.size() + 1);
int i = 0;
E replacedEntry = null;
do {
E entry = entries.get(i);
// Only add old entry if the address is not the same as the one we try to add as well.
// In this case we will skip it and just add the new entry as this may have
// more up-to-date data and cancel the old after we were able to update the cache.
if (!Cache.this.equals(e, entry)) {
newEntries.add(entry);
} else {
replacedEntry = entry;
newEntries.add(e);
++i;
for (; i < entries.size(); ++i) {
newEntries.add(entries.get(i));
}
break;
}
} while (++i < entries.size());
if (replacedEntry == null) {
newEntries.add(e);
}
sortEntries(hostname, newEntries);
if (compareAndSet(entries, Collections.unmodifiableList(newEntries))) {
scheduleCacheExpirationIfNeeded(ttl, loop);
return;
}
} else if (compareAndSet(entries, singletonList(e))) {
scheduleCacheExpirationIfNeeded(ttl, loop);
return;
}
}
} else {
set(singletonList(e));
scheduleCacheExpirationIfNeeded(ttl, loop);
}
}
Domain
Subdomains
Called By
Source
Frequently Asked Questions
What does add() do?
add() is a function in the netty codebase, defined in resolver-dns/src/main/java/io/netty/resolver/dns/Cache.java.
Where is add() defined?
add() is defined in resolver-dns/src/main/java/io/netty/resolver/dns/Cache.java at line 173.
What does add() call?
add() calls 6 function(s): equals, get, scheduleCacheExpirationIfNeeded, shouldReplaceAll, size, sortEntries.
What calls add()?
add() is called by 1 function(s): cache.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free