Context.smali

.class public Lio/grpc/Context;
.super Ljava/lang/Object;


# annotations
.annotation system Ldalvik/annotation/MemberClasses;
    value = {
        Lio/grpc/Context$ParentListener;,
        Lio/grpc/Context$ExecutableListener;,
        Lio/grpc/Context$Storage;,
        Lio/grpc/Context$Key;,
        Lio/grpc/Context$CancellationListener;,
        Lio/grpc/Context$CancellableContext;
    }
.end annotation


# static fields
.field private static final k:Ljava/util/logging/Logger;

.field private static final l:Lio/grpc/PersistentHashArrayMappedTrie;
    .annotation system Ldalvik/annotation/Signature;
        value = {
            "Lio/grpc/PersistentHashArrayMappedTrie<",
            "Lio/grpc/Context$Key<",
            "*>;",
            "Ljava/lang/Object;",
            ">;"
        }
    .end annotation
.end field

.field public static final m:Lio/grpc/Context;

.field private static final n:Ljava/util/concurrent/atomic/AtomicReference;
    .annotation system Ldalvik/annotation/Signature;
        value = {
            "Ljava/util/concurrent/atomic/AtomicReference<",
            "Lio/grpc/Context$Storage;",
            ">;"
        }
    .end annotation
.end field


# instance fields
.field private f:Ljava/util/ArrayList;
    .annotation system Ldalvik/annotation/Signature;
        value = {
            "Ljava/util/ArrayList<",
            "Lio/grpc/Context$ExecutableListener;",
            ">;"
        }
    .end annotation
.end field

.field private g:Lio/grpc/Context$CancellationListener;

.field final h:Lio/grpc/Context$CancellableContext;

.field final i:Lio/grpc/PersistentHashArrayMappedTrie;
    .annotation system Ldalvik/annotation/Signature;
        value = {
            "Lio/grpc/PersistentHashArrayMappedTrie<",
            "Lio/grpc/Context$Key<",
            "*>;",
            "Ljava/lang/Object;",
            ">;"
        }
    .end annotation
.end field

.field final j:I


# direct methods
.method static constructor <clinit>()V
    .registers 3

    const-class v0, Lio/grpc/Context;

    invoke-virtual {v0}, Ljava/lang/Class;->getName()Ljava/lang/String;

    move-result-object v0

    invoke-static {v0}, Ljava/util/logging/Logger;->getLogger(Ljava/lang/String;)Ljava/util/logging/Logger;

    move-result-object v0

    sput-object v0, Lio/grpc/Context;->k:Ljava/util/logging/Logger;

    new-instance v0, Lio/grpc/PersistentHashArrayMappedTrie;

    invoke-direct {v0}, Lio/grpc/PersistentHashArrayMappedTrie;-><init>()V

    sput-object v0, Lio/grpc/Context;->l:Lio/grpc/PersistentHashArrayMappedTrie;

    new-instance v1, Lio/grpc/Context;

    const/4 v2, 0x0

    invoke-direct {v1, v2, v0}, Lio/grpc/Context;-><init>(Lio/grpc/Context;Lio/grpc/PersistentHashArrayMappedTrie;)V

    sput-object v1, Lio/grpc/Context;->m:Lio/grpc/Context;

    new-instance v0, Ljava/util/concurrent/atomic/AtomicReference;

    invoke-direct {v0}, Ljava/util/concurrent/atomic/AtomicReference;-><init>()V

    sput-object v0, Lio/grpc/Context;->n:Ljava/util/concurrent/atomic/AtomicReference;

    return-void
.end method

.method private constructor <init>(Lio/grpc/Context;Lio/grpc/PersistentHashArrayMappedTrie;)V
    .registers 5
    .annotation system Ldalvik/annotation/Signature;
        value = {
            "(",
            "Lio/grpc/Context;",
            "Lio/grpc/PersistentHashArrayMappedTrie<",
            "Lio/grpc/Context$Key<",
            "*>;",
            "Ljava/lang/Object;",
            ">;)V"
        }
    .end annotation

    invoke-direct {p0}, Ljava/lang/Object;-><init>()V

    new-instance v0, Lio/grpc/Context$ParentListener;

    const/4 v1, 0x0

    invoke-direct {v0, p0, v1}, Lio/grpc/Context$ParentListener;-><init>(Lio/grpc/Context;Lio/grpc/Context$1;)V

    iput-object v0, p0, Lio/grpc/Context;->g:Lio/grpc/Context$CancellationListener;

    invoke-static {p1}, Lio/grpc/Context;->g(Lio/grpc/Context;)Lio/grpc/Context$CancellableContext;

    move-result-object v0

    iput-object v0, p0, Lio/grpc/Context;->h:Lio/grpc/Context$CancellableContext;

    iput-object p2, p0, Lio/grpc/Context;->i:Lio/grpc/PersistentHashArrayMappedTrie;

    if-nez p1, :cond_17

    const/4 p1, 0x0

    goto :goto_1b

    :cond_17
    iget p1, p1, Lio/grpc/Context;->j:I

    add-int/lit8 p1, p1, 0x1

    :goto_1b
    iput p1, p0, Lio/grpc/Context;->j:I

    invoke-static {p1}, Lio/grpc/Context;->C(I)V

    return-void
.end method

.method private static C(I)V
    .registers 4

    const/16 v0, 0x3e8

    if-ne p0, v0, :cond_12

    sget-object p0, Lio/grpc/Context;->k:Ljava/util/logging/Logger;

    sget-object v0, Ljava/util/logging/Level;->SEVERE:Ljava/util/logging/Level;

    new-instance v1, Ljava/lang/Exception;

    invoke-direct {v1}, Ljava/lang/Exception;-><init>()V

    const-string v2, "Context ancestry chain length is abnormally long. This suggests an error in application code. Length exceeded: 1000"

    invoke-virtual {p0, v0, v2, v1}, Ljava/util/logging/Logger;->log(Ljava/util/logging/Level;Ljava/lang/String;Ljava/lang/Throwable;)V

    :cond_12
    return-void
.end method

.method static synthetic a()Ljava/util/logging/Logger;
    .registers 1

    sget-object v0, Lio/grpc/Context;->k:Ljava/util/logging/Logger;

    return-object v0
.end method

.method static synthetic b(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;
    .registers 2

    invoke-static {p0, p1}, Lio/grpc/Context;->k(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;

    return-object p0
.end method

.method static synthetic d(Lio/grpc/Context;Lio/grpc/Context$Key;)Ljava/lang/Object;
    .registers 2

    invoke-direct {p0, p1}, Lio/grpc/Context;->t(Lio/grpc/Context$Key;)Ljava/lang/Object;

    move-result-object p0

    return-object p0
.end method

.method static g(Lio/grpc/Context;)Lio/grpc/Context$CancellableContext;
    .registers 2

    if-nez p0, :cond_4

    const/4 p0, 0x0

    return-object p0

    :cond_4
    instance-of v0, p0, Lio/grpc/Context$CancellableContext;

    if-eqz v0, :cond_b

    check-cast p0, Lio/grpc/Context$CancellableContext;

    return-object p0

    :cond_b
    iget-object p0, p0, Lio/grpc/Context;->h:Lio/grpc/Context$CancellableContext;

    return-object p0
.end method

.method private static k(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;
    .registers 2
    .annotation system Ldalvik/annotation/Signature;
        value = {
            "<T:",
            "Ljava/lang/Object;",
            ">(TT;",
            "Ljava/lang/Object;",
            ")TT;"
        }
    .end annotation

    if-eqz p0, :cond_3

    return-object p0

    :cond_3
    new-instance p0, Ljava/lang/NullPointerException;

    invoke-static {p1}, Ljava/lang/String;->valueOf(Ljava/lang/Object;)Ljava/lang/String;

    move-result-object p1

    invoke-direct {p0, p1}, Ljava/lang/NullPointerException;-><init>(Ljava/lang/String;)V

    throw p0
.end method

.method private static n()Lio/grpc/Context$Storage;
    .registers 4

    const/4 v0, 0x0

    :try_start_1
    const-string v1, "io.grpc.override.ContextStorageOverride"

    invoke-static {v1}, Ljava/lang/Class;->forName(Ljava/lang/String;)Ljava/lang/Class;

    move-result-object v1

    const/4 v2, 0x0

    new-array v3, v2, [Ljava/lang/Class;

    invoke-virtual {v1, v3}, Ljava/lang/Class;->getConstructor([Ljava/lang/Class;)Ljava/lang/reflect/Constructor;

    move-result-object v1

    new-array v2, v2, [Ljava/lang/Object;

    invoke-virtual {v1, v2}, Ljava/lang/reflect/Constructor;->newInstance([Ljava/lang/Object;)Ljava/lang/Object;

    move-result-object v1

    check-cast v1, Lio/grpc/Context$Storage;

    sget-object v2, Lio/grpc/Context;->n:Ljava/util/concurrent/atomic/AtomicReference;

    invoke-virtual {v2, v0, v1}, Ljava/util/concurrent/atomic/AtomicReference;->compareAndSet(Ljava/lang/Object;Ljava/lang/Object;)Z
    :try_end_1b
    .catch Ljava/lang/ClassNotFoundException; {:try_start_1 .. :try_end_1b} :catch_25
    .catch Ljava/lang/Exception; {:try_start_1 .. :try_end_1b} :catch_1c

    goto :goto_3c

    :catch_1c
    move-exception v0

    new-instance v1, Ljava/lang/RuntimeException;

    const-string v2, "Storage override failed to initialize"

    invoke-direct {v1, v2, v0}, Ljava/lang/RuntimeException;-><init>(Ljava/lang/String;Ljava/lang/Throwable;)V

    throw v1

    :catch_25
    move-exception v1

    new-instance v2, Lio/grpc/ThreadLocalContextStorage;

    invoke-direct {v2}, Lio/grpc/ThreadLocalContextStorage;-><init>()V

    sget-object v3, Lio/grpc/Context;->n:Ljava/util/concurrent/atomic/AtomicReference;

    invoke-virtual {v3, v0, v2}, Ljava/util/concurrent/atomic/AtomicReference;->compareAndSet(Ljava/lang/Object;Ljava/lang/Object;)Z

    move-result v0

    if-eqz v0, :cond_3c

    sget-object v0, Lio/grpc/Context;->k:Ljava/util/logging/Logger;

    sget-object v2, Ljava/util/logging/Level;->FINE:Ljava/util/logging/Level;

    const-string v3, "Storage override doesn\'t exist. Using default"

    invoke-virtual {v0, v2, v3, v1}, Ljava/util/logging/Logger;->log(Ljava/util/logging/Level;Ljava/lang/String;Ljava/lang/Throwable;)V

    :cond_3c
    :goto_3c
    sget-object v0, Lio/grpc/Context;->n:Ljava/util/concurrent/atomic/AtomicReference;

    invoke-virtual {v0}, Ljava/util/concurrent/atomic/AtomicReference;->get()Ljava/lang/Object;

    move-result-object v0

    check-cast v0, Lio/grpc/Context$Storage;

    return-object v0
.end method

.method public static o()Lio/grpc/Context;
    .registers 1

    invoke-static {}, Lio/grpc/Context;->x()Lio/grpc/Context$Storage;

    move-result-object v0

    invoke-virtual {v0}, Lio/grpc/Context$Storage;->b()Lio/grpc/Context;

    move-result-object v0

    if-nez v0, :cond_c

    sget-object v0, Lio/grpc/Context;->m:Lio/grpc/Context;

    :cond_c
    return-object v0
.end method

.method public static s(Ljava/lang/String;)Lio/grpc/Context$Key;
    .registers 2
    .annotation system Ldalvik/annotation/Signature;
        value = {
            "<T:",
            "Ljava/lang/Object;",
            ">(",
            "Ljava/lang/String;",
            ")",
            "Lio/grpc/Context$Key<",
            "TT;>;"
        }
    .end annotation

    new-instance v0, Lio/grpc/Context$Key;

    invoke-direct {v0, p0}, Lio/grpc/Context$Key;-><init>(Ljava/lang/String;)V

    return-object v0
.end method

.method private t(Lio/grpc/Context$Key;)Ljava/lang/Object;
    .registers 3
    .annotation system Ldalvik/annotation/Signature;
        value = {
            "(",
            "Lio/grpc/Context$Key<",
            "*>;)",
            "Ljava/lang/Object;"
        }
    .end annotation

    iget-object v0, p0, Lio/grpc/Context;->i:Lio/grpc/PersistentHashArrayMappedTrie;

    invoke-virtual {v0, p1}, Lio/grpc/PersistentHashArrayMappedTrie;->a(Ljava/lang/Object;)Ljava/lang/Object;

    move-result-object p1

    return-object p1
.end method

.method static x()Lio/grpc/Context$Storage;
    .registers 1

    sget-object v0, Lio/grpc/Context;->n:Ljava/util/concurrent/atomic/AtomicReference;

    invoke-virtual {v0}, Ljava/util/concurrent/atomic/AtomicReference;->get()Ljava/lang/Object;

    move-result-object v0

    check-cast v0, Lio/grpc/Context$Storage;

    if-nez v0, :cond_e

    invoke-static {}, Lio/grpc/Context;->n()Lio/grpc/Context$Storage;

    move-result-object v0

    :cond_e
    return-object v0
.end method


# virtual methods
.method public D(Lio/grpc/Context$Key;Ljava/lang/Object;)Lio/grpc/Context;
    .registers 4
    .annotation system Ldalvik/annotation/Signature;
        value = {
            "<V:",
            "Ljava/lang/Object;",
            ">(",
            "Lio/grpc/Context$Key<",
            "TV;>;TV;)",
            "Lio/grpc/Context;"
        }
    .end annotation

    iget-object v0, p0, Lio/grpc/Context;->i:Lio/grpc/PersistentHashArrayMappedTrie;

    invoke-virtual {v0, p1, p2}, Lio/grpc/PersistentHashArrayMappedTrie;->b(Ljava/lang/Object;Ljava/lang/Object;)Lio/grpc/PersistentHashArrayMappedTrie;

    move-result-object p1

    new-instance p2, Lio/grpc/Context;

    invoke-direct {p2, p0, p1}, Lio/grpc/Context;-><init>(Lio/grpc/Context;Lio/grpc/PersistentHashArrayMappedTrie;)V

    return-object p2
.end method

.method public e()Lio/grpc/Context;
    .registers 2

    invoke-static {}, Lio/grpc/Context;->x()Lio/grpc/Context$Storage;

    move-result-object v0

    invoke-virtual {v0, p0}, Lio/grpc/Context$Storage;->d(Lio/grpc/Context;)Lio/grpc/Context;

    move-result-object v0

    if-nez v0, :cond_c

    sget-object v0, Lio/grpc/Context;->m:Lio/grpc/Context;

    :cond_c
    return-object v0
.end method

.method f()Z
    .registers 2

    iget-object v0, p0, Lio/grpc/Context;->h:Lio/grpc/Context$CancellableContext;

    if-eqz v0, :cond_6

    const/4 v0, 0x1

    goto :goto_7

    :cond_6
    const/4 v0, 0x0

    :goto_7
    return v0
.end method

.method public j()Ljava/lang/Throwable;
    .registers 2

    iget-object v0, p0, Lio/grpc/Context;->h:Lio/grpc/Context$CancellableContext;

    if-nez v0, :cond_6

    const/4 v0, 0x0

    return-object v0

    :cond_6
    invoke-virtual {v0}, Lio/grpc/Context$CancellableContext;->j()Ljava/lang/Throwable;

    move-result-object v0

    return-object v0
.end method

.method public p(Lio/grpc/Context;)V
    .registers 3

    const-string v0, "toAttach"

    invoke-static {p1, v0}, Lio/grpc/Context;->k(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;

    invoke-static {}, Lio/grpc/Context;->x()Lio/grpc/Context$Storage;

    move-result-object v0

    invoke-virtual {v0, p0, p1}, Lio/grpc/Context$Storage;->c(Lio/grpc/Context;Lio/grpc/Context;)V

    return-void
.end method

.method public r()Z
    .registers 2

    iget-object v0, p0, Lio/grpc/Context;->h:Lio/grpc/Context$CancellableContext;

    if-nez v0, :cond_6

    const/4 v0, 0x0

    return v0

    :cond_6
    invoke-virtual {v0}, Lio/grpc/Context$CancellableContext;->r()Z

    move-result v0

    return v0
.end method

.method u()V
    .registers 5

    invoke-virtual {p0}, Lio/grpc/Context;->f()Z

    move-result v0

    if-nez v0, :cond_7

    return-void

    :cond_7
    monitor-enter p0

    :try_start_8
    iget-object v0, p0, Lio/grpc/Context;->f:Ljava/util/ArrayList;

    if-nez v0, :cond_e

    monitor-exit p0

    return-void

    :cond_e
    iget-object v0, p0, Lio/grpc/Context;->f:Ljava/util/ArrayList;

    const/4 v1, 0x0

    iput-object v1, p0, Lio/grpc/Context;->f:Ljava/util/ArrayList;

    monitor-exit p0
    :try_end_14
    .catchall {:try_start_8 .. :try_end_14} :catchall_60

    const/4 v1, 0x0

    const/4 v2, 0x0

    :goto_16
    invoke-virtual {v0}, Ljava/util/ArrayList;->size()I

    move-result v3

    if-ge v2, v3, :cond_36

    invoke-virtual {v0, v2}, Ljava/util/ArrayList;->get(I)Ljava/lang/Object;

    move-result-object v3

    check-cast v3, Lio/grpc/Context$ExecutableListener;

    invoke-static {v3}, Lio/grpc/Context$ExecutableListener;->b(Lio/grpc/Context$ExecutableListener;)Lio/grpc/Context$CancellationListener;

    move-result-object v3

    instance-of v3, v3, Lio/grpc/Context$ParentListener;

    if-nez v3, :cond_33

    invoke-virtual {v0, v2}, Ljava/util/ArrayList;->get(I)Ljava/lang/Object;

    move-result-object v3

    check-cast v3, Lio/grpc/Context$ExecutableListener;

    invoke-static {v3}, Lio/grpc/Context$ExecutableListener;->a(Lio/grpc/Context$ExecutableListener;)V

    :cond_33
    add-int/lit8 v2, v2, 0x1

    goto :goto_16

    :cond_36
    :goto_36
    invoke-virtual {v0}, Ljava/util/ArrayList;->size()I

    move-result v2

    if-ge v1, v2, :cond_56

    invoke-virtual {v0, v1}, Ljava/util/ArrayList;->get(I)Ljava/lang/Object;

    move-result-object v2

    check-cast v2, Lio/grpc/Context$ExecutableListener;

    invoke-static {v2}, Lio/grpc/Context$ExecutableListener;->b(Lio/grpc/Context$ExecutableListener;)Lio/grpc/Context$CancellationListener;

    move-result-object v2

    instance-of v2, v2, Lio/grpc/Context$ParentListener;

    if-eqz v2, :cond_53

    invoke-virtual {v0, v1}, Ljava/util/ArrayList;->get(I)Ljava/lang/Object;

    move-result-object v2

    check-cast v2, Lio/grpc/Context$ExecutableListener;

    invoke-static {v2}, Lio/grpc/Context$ExecutableListener;->a(Lio/grpc/Context$ExecutableListener;)V

    :cond_53
    add-int/lit8 v1, v1, 0x1

    goto :goto_36

    :cond_56
    iget-object v0, p0, Lio/grpc/Context;->h:Lio/grpc/Context$CancellableCo