@Test public void cancellableAncestorTest() { assertEquals(null, cancellableAncestor(null)); Context c = Context.current(); assertFalse(c.canBeCancelled()); assertEquals(null, cancellableAncestor(c)); Context.CancellableContext withCancellation = c.withCancellation(); assertEquals(withCancellation, cancellableAncestor(withCancellation)); Context child = withCancellation.withValue(COLOR, "blue"); assertFalse(child instanceof Context.CancellableContext); assertEquals(withCancellation, cancellableAncestor(child)); Context grandChild = child.withValue(COLOR, "red"); assertFalse(grandChild instanceof Context.CancellableContext); assertEquals(withCancellation, cancellableAncestor(grandChild)); }
static CancellableContext cancellableAncestor(Context parent) { if (parent == null) { return null; } if (parent instanceof CancellableContext) { return (CancellableContext) parent; } return parent.cancellableAncestor; }
Context { static CancellableContext cancellableAncestor(Context parent) { if (parent == null) { return null; } if (parent instanceof CancellableContext) { return (CancellableContext) parent; } return parent.cancellableAncestor; } }
Context { static CancellableContext cancellableAncestor(Context parent) { if (parent == null) { return null; } if (parent instanceof CancellableContext) { return (CancellableContext) parent; } return parent.cancellableAncestor; } private  Context(PersistentHashArrayMappedTrie<Key<?>, Object> keyValueEntries, int generation); private  Context(Context parent, PersistentHashArrayMappedTrie<Key<?>, Object> keyValueEntries); }
Context { static CancellableContext cancellableAncestor(Context parent) { if (parent == null) { return null; } if (parent instanceof CancellableContext) { return (CancellableContext) parent; } return parent.cancellableAncestor; } private  Context(PersistentHashArrayMappedTrie<Key<?>, Object> keyValueEntries, int generation); private  Context(Context parent, PersistentHashArrayMappedTrie<Key<?>, Object> keyValueEntries); static Key<T> key(String name); static Key<T> keyWithDefault(String name, T defaultValue); static Context current(); CancellableContext withCancellation(); CancellableContext withDeadlineAfter(long duration, TimeUnit unit,
                                              ScheduledExecutorService scheduler); CancellableContext withDeadline(Deadline deadline,
      ScheduledExecutorService scheduler); Context withValue(Key<V> k1, V v1); Context withValues(Key<V1> k1, V1 v1, Key<V2> k2, V2 v2); Context withValues(Key<V1> k1, V1 v1, Key<V2> k2, V2 v2, Key<V3> k3, V3 v3); Context withValues(Key<V1> k1, V1 v1, Key<V2> k2, V2 v2,
      Key<V3> k3, V3 v3, Key<V4> k4, V4 v4); Context fork(); Context attach(); void detach(Context toAttach); boolean isCancelled(); Throwable cancellationCause(); Deadline getDeadline(); void addListener(final CancellationListener cancellationListener,
                          final Executor executor); void removeListener(CancellationListener cancellationListener); void run(Runnable r); @CanIgnoreReturnValue V call(Callable<V> c); Runnable wrap(final Runnable r); Callable<C> wrap(final Callable<C> c); Executor fixedContextExecutor(final Executor e); static Executor currentContextExecutor(final Executor e); }
Context { static CancellableContext cancellableAncestor(Context parent) { if (parent == null) { return null; } if (parent instanceof CancellableContext) { return (CancellableContext) parent; } return parent.cancellableAncestor; } private  Context(PersistentHashArrayMappedTrie<Key<?>, Object> keyValueEntries, int generation); private  Context(Context parent, PersistentHashArrayMappedTrie<Key<?>, Object> keyValueEntries); static Key<T> key(String name); static Key<T> keyWithDefault(String name, T defaultValue); static Context current(); CancellableContext withCancellation(); CancellableContext withDeadlineAfter(long duration, TimeUnit unit,
                                              ScheduledExecutorService scheduler); CancellableContext withDeadline(Deadline deadline,
      ScheduledExecutorService scheduler); Context withValue(Key<V> k1, V v1); Context withValues(Key<V1> k1, V1 v1, Key<V2> k2, V2 v2); Context withValues(Key<V1> k1, V1 v1, Key<V2> k2, V2 v2, Key<V3> k3, V3 v3); Context withValues(Key<V1> k1, V1 v1, Key<V2> k2, V2 v2,
      Key<V3> k3, V3 v3, Key<V4> k4, V4 v4); Context fork(); Context attach(); void detach(Context toAttach); boolean isCancelled(); Throwable cancellationCause(); Deadline getDeadline(); void addListener(final CancellationListener cancellationListener,
                          final Executor executor); void removeListener(CancellationListener cancellationListener); void run(Runnable r); @CanIgnoreReturnValue V call(Callable<V> c); Runnable wrap(final Runnable r); Callable<C> wrap(final Callable<C> c); Executor fixedContextExecutor(final Executor e); static Executor currentContextExecutor(final Executor e); static final Context ROOT; }