Home / Function/ scheduleCacheExpirationIfNeeded() — netty Function Reference

scheduleCacheExpirationIfNeeded() — netty Function Reference

Architecture documentation for the scheduleCacheExpirationIfNeeded() function in Cache.java from the netty codebase.

Entity Profile

Dependency Diagram

graph TD
  c13d2041_e562_e9af_db02_30f08b74c5b1["scheduleCacheExpirationIfNeeded()"]
  0a5c7e5a_0868_706c_64ef_570d8eda93ed["Entries"]
  c13d2041_e562_e9af_db02_30f08b74c5b1 -->|defined in| 0a5c7e5a_0868_706c_64ef_570d8eda93ed
  a3a06bb5_0cc7_b138_7d64_44cab8d3dafc["add()"]
  a3a06bb5_0cc7_b138_7d64_44cab8d3dafc -->|calls| c13d2041_e562_e9af_db02_30f08b74c5b1
  c0b89246_8ba9_ca82_e4a0_93b63e2ddcb9["get()"]
  c13d2041_e562_e9af_db02_30f08b74c5b1 -->|calls| c0b89246_8ba9_ca82_e4a0_93b63e2ddcb9
  style c13d2041_e562_e9af_db02_30f08b74c5b1 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

resolver-dns/src/main/java/io/netty/resolver/dns/Cache.java lines 233–260

        private void scheduleCacheExpirationIfNeeded(int ttl, EventLoop loop) {
            for (;;) {
                // We currently don't calculate a new TTL when we need to retry the CAS as we don't expect this to
                // be invoked very concurrently and also we use SECONDS anyway. If this ever becomes a problem
                // we can reconsider.
                ScheduledFuture<?> oldFuture = FUTURE_UPDATER.get(this);
                if (oldFuture == null || oldFuture.getDelay(TimeUnit.SECONDS) > ttl) {
                    ScheduledFuture<?> newFuture = loop.schedule(this, ttl, TimeUnit.SECONDS);
                    // It is possible that
                    // 1. task will fire in between this line, or
                    // 2. multiple timers may be set if there is concurrency
                    // (1) Shouldn't be a problem because we will fail the CAS and then the next loop will see CANCELLED
                    //     so the ttl will not be less, and we will bail out of the loop.
                    // (2) This is a trade-off to avoid concurrency resulting in contention on a synchronized block.
                    if (FUTURE_UPDATER.compareAndSet(this, oldFuture, newFuture)) {
                        if (oldFuture != null) {
                            oldFuture.cancel(true);
                        }
                        break;
                    } else {
                        // There was something else scheduled in the meantime... Cancel and try again.
                        newFuture.cancel(true);
                    }
                } else {
                    break;
                }
            }
        }

Subdomains

Calls

Called By

Frequently Asked Questions

What does scheduleCacheExpirationIfNeeded() do?
scheduleCacheExpirationIfNeeded() is a function in the netty codebase, defined in resolver-dns/src/main/java/io/netty/resolver/dns/Cache.java.
Where is scheduleCacheExpirationIfNeeded() defined?
scheduleCacheExpirationIfNeeded() is defined in resolver-dns/src/main/java/io/netty/resolver/dns/Cache.java at line 233.
What does scheduleCacheExpirationIfNeeded() call?
scheduleCacheExpirationIfNeeded() calls 1 function(s): get.
What calls scheduleCacheExpirationIfNeeded()?
scheduleCacheExpirationIfNeeded() is called by 1 function(s): add.

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free