context: Remove superfluous cascadesCancellation field

This commit is contained in:
Eric Anderson 2017-08-26 13:43:36 -07:00
parent 32cd4a0660
commit 21cd244734
1 changed files with 3 additions and 21 deletions

View File

@ -106,7 +106,7 @@ public class Context {
* <p>Never assume this is the default context for new threads, because {@link Storage} may define * <p>Never assume this is the default context for new threads, because {@link Storage} may define
* a default context that is different from ROOT. * a default context that is different from ROOT.
*/ */
public static final Context ROOT = new Context(null, EMPTY_ENTRIES, false, false); public static final Context ROOT = new Context(null, EMPTY_ENTRIES, false);
// Lazy-loaded storage. Delaying storage initialization until after class initialization makes it // Lazy-loaded storage. Delaying storage initialization until after class initialization makes it
// much easier to avoid circular loading since there can still be references to Context as long as // much easier to avoid circular loading since there can still be references to Context as long as
@ -177,7 +177,6 @@ public class Context {
return current; return current;
} }
private final boolean cascadesCancellation;
private ArrayList<ExecutableListener> listeners; private ArrayList<ExecutableListener> listeners;
private CancellationListener parentListener = new ParentListener(); private CancellationListener parentListener = new ParentListener();
private final boolean canBeCancelled; private final boolean canBeCancelled;
@ -190,7 +189,6 @@ public class Context {
private Context(PersistentHashArrayMappedTrie<Key<?>, Object> keyValueEntries) { private Context(PersistentHashArrayMappedTrie<Key<?>, Object> keyValueEntries) {
cancellableAncestor = null; cancellableAncestor = null;
this.keyValueEntries = keyValueEntries; this.keyValueEntries = keyValueEntries;
cascadesCancellation = false;
canBeCancelled = false; canBeCancelled = false;
} }
@ -201,7 +199,6 @@ public class Context {
private Context(Context parent, PersistentHashArrayMappedTrie<Key<?>, Object> keyValueEntries) { private Context(Context parent, PersistentHashArrayMappedTrie<Key<?>, Object> keyValueEntries) {
cancellableAncestor = cancellableAncestor(parent); cancellableAncestor = cancellableAncestor(parent);
this.keyValueEntries = keyValueEntries; this.keyValueEntries = keyValueEntries;
cascadesCancellation = true;
canBeCancelled = cancellableAncestor != null; canBeCancelled = cancellableAncestor != null;
} }
@ -215,21 +212,6 @@ public class Context {
boolean isCancellable) { boolean isCancellable) {
cancellableAncestor = cancellableAncestor(parent); cancellableAncestor = cancellableAncestor(parent);
this.keyValueEntries = keyValueEntries; this.keyValueEntries = keyValueEntries;
cascadesCancellation = true;
canBeCancelled = isCancellable;
}
/**
* Constructs a context that can be arbitrarily configured.
*/
private Context(
Context parent,
PersistentHashArrayMappedTrie<Key<?>, Object> keyValueEntries,
boolean cascadesCancellation,
boolean isCancellable) {
cancellableAncestor = cancellableAncestor(parent);
this.keyValueEntries = keyValueEntries;
this.cascadesCancellation = cascadesCancellation;
canBeCancelled = isCancellable; canBeCancelled = isCancellable;
} }
@ -435,7 +417,7 @@ public class Context {
* Is this context cancelled. * Is this context cancelled.
*/ */
public boolean isCancelled() { public boolean isCancelled() {
if (cancellableAncestor == null || !cascadesCancellation) { if (cancellableAncestor == null) {
return false; return false;
} else { } else {
return cancellableAncestor.isCancelled(); return cancellableAncestor.isCancelled();
@ -451,7 +433,7 @@ public class Context {
* should generally assume that it has already been handled and logged properly. * should generally assume that it has already been handled and logged properly.
*/ */
public Throwable cancellationCause() { public Throwable cancellationCause() {
if (cancellableAncestor == null || !cascadesCancellation) { if (cancellableAncestor == null) {
return null; return null;
} else { } else {
return cancellableAncestor.cancellationCause(); return cancellableAncestor.cancellationCause();