HostCacheManager.smali
.class Lio/rong/imlib/httpdns/HostCacheManager;
.super Ljava/lang/Object;
.source "HostCacheManager.java"
# annotations
.annotation system Ldalvik/annotation/MemberClasses;
value = {
Lio/rong/imlib/httpdns/HostCacheManager$HostEntry;
}
.end annotation
# instance fields
.field private final dnsPrefix:Ljava/lang/String;
.field private final hostCache:Landroid/util/LruCache;
.annotation system Ldalvik/annotation/Signature;
value = {
"Landroid/util/LruCache<",
"Ljava/lang/String;",
"Lio/rong/imlib/httpdns/HostCacheManager$HostEntry;",
">;"
}
.end annotation
.end field
.field private strictCachePolicy:Z
# direct methods
.method constructor <init>(Ljava/lang/String;Z)V
.registers 5
.line 1
invoke-direct {p0}, Ljava/lang/Object;-><init>()V
.line 2
invoke-static {}, Ljava/lang/Runtime;->getRuntime()Ljava/lang/Runtime;
move-result-object v0
invoke-virtual {v0}, Ljava/lang/Runtime;->maxMemory()J
move-result-wide v0
long-to-int v1, v0
.line 3
new-instance v0, Landroid/util/LruCache;
div-int/lit8 v1, v1, 0x10
invoke-direct {v0, v1}, Landroid/util/LruCache;-><init>(I)V
iput-object v0, p0, Lio/rong/imlib/httpdns/HostCacheManager;->hostCache:Landroid/util/LruCache;
.line 4
iput-object p1, p0, Lio/rong/imlib/httpdns/HostCacheManager;->dnsPrefix:Ljava/lang/String;
.line 5
iput-boolean p2, p0, Lio/rong/imlib/httpdns/HostCacheManager;->strictCachePolicy:Z
return-void
.end method
# virtual methods
.method clearHostCacheMemory()V
.registers 4
.line 1
iget-object v0, p0, Lio/rong/imlib/httpdns/HostCacheManager;->hostCache:Landroid/util/LruCache;
invoke-virtual {v0}, Landroid/util/LruCache;->evictAll()V
const/4 v0, 0x1
.line 2
new-array v0, v0, [Ljava/lang/Object;
iget-object v1, p0, Lio/rong/imlib/httpdns/HostCacheManager;->dnsPrefix:Ljava/lang/String;
const/4 v2, 0x0
aput-object v1, v0, v2
const-string v1, "Clear %s cache"
invoke-static {v1, v0}, Lio/rong/imlib/httpdns/Logger;->printLog(Ljava/lang/String;[Ljava/lang/Object;)V
return-void
.end method
.method getAllHosts()Ljava/util/ArrayList;
.registers 3
.annotation system Ldalvik/annotation/Signature;
value = {
"()",
"Ljava/util/ArrayList<",
"Ljava/lang/String;",
">;"
}
.end annotation
.line 1
new-instance v0, Ljava/util/ArrayList;
invoke-direct {v0}, Ljava/util/ArrayList;-><init>()V
.line 2
iget-object v1, p0, Lio/rong/imlib/httpdns/HostCacheManager;->hostCache:Landroid/util/LruCache;
invoke-virtual {v1}, Landroid/util/LruCache;->snapshot()Ljava/util/Map;
move-result-object v1
.line 3
invoke-interface {v1}, Ljava/util/Map;->keySet()Ljava/util/Set;
move-result-object v1
.line 4
invoke-virtual {v0, v1}, Ljava/util/ArrayList;->addAll(Ljava/util/Collection;)Z
return-object v0
.end method
.method getHostCacheEntry(Ljava/lang/String;)Lio/rong/imlib/httpdns/HostCacheManager$HostEntry;
.registers 5
.line 1
iget-object v0, p0, Lio/rong/imlib/httpdns/HostCacheManager;->hostCache:Landroid/util/LruCache;
invoke-virtual {v0, p1}, Landroid/util/LruCache;->get(Ljava/lang/Object;)Ljava/lang/Object;
move-result-object v0
check-cast v0, Lio/rong/imlib/httpdns/HostCacheManager$HostEntry;
if-eqz v0, :cond_2b
.line 2
invoke-virtual {v0}, Lio/rong/imlib/httpdns/HostCacheManager$HostEntry;->isExpired()Z
move-result v1
if-eqz v1, :cond_2b
iget-boolean v1, p0, Lio/rong/imlib/httpdns/HostCacheManager;->strictCachePolicy:Z
if-eqz v1, :cond_2b
.line 3
iget-object v0, p0, Lio/rong/imlib/httpdns/HostCacheManager;->hostCache:Landroid/util/LruCache;
invoke-virtual {v0, p1}, Landroid/util/LruCache;->remove(Ljava/lang/Object;)Ljava/lang/Object;
const/4 v0, 0x2
.line 4
new-array v0, v0, [Ljava/lang/Object;
const/4 v1, 0x0
iget-object v2, p0, Lio/rong/imlib/httpdns/HostCacheManager;->dnsPrefix:Ljava/lang/String;
aput-object v2, v0, v1
const/4 v1, 0x1
aput-object p1, v0, v1
const-string p1, "Remove expired entry from %s cache while reading, host(%s)"
invoke-static {p1, v0}, Lio/rong/imlib/httpdns/Logger;->printLog(Ljava/lang/String;[Ljava/lang/Object;)V
const/4 p1, 0x0
return-object p1
:cond_2b
return-object v0
.end method
.method isStrictCachePolicy()Z
.registers 2
.line 1
iget-boolean v0, p0, Lio/rong/imlib/httpdns/HostCacheManager;->strictCachePolicy:Z
return v0
.end method
.method removeExpiredEntry(Ljava/lang/String;)V
.registers 5
.line 1
invoke-virtual {p0, p1}, Lio/rong/imlib/httpdns/HostCacheManager;->getHostCacheEntry(Ljava/lang/String;)Lio/rong/imlib/httpdns/HostCacheManager$HostEntry;
move-result-object v0
if-eqz v0, :cond_22
.line 2
invoke-virtual {v0}, Lio/rong/imlib/httpdns/HostCacheManager$HostEntry;->isExpired()Z
move-result v0
if-nez v0, :cond_d
return-void
.line 3
:cond_d
iget-object v0, p0, Lio/rong/imlib/httpdns/HostCacheManager;->hostCache:Landroid/util/LruCache;
invoke-virtual {v0, p1}, Landroid/util/LruCache;->remove(Ljava/lang/Object;)Ljava/lang/Object;
const/4 v0, 0x2
.line 4
new-array v0, v0, [Ljava/lang/Object;
const/4 v1, 0x0
iget-object v2, p0, Lio/rong/imlib/httpdns/HostCacheManager;->dnsPrefix:Ljava/lang/String;
aput-object v2, v0, v1
const/4 v1, 0x1
aput-object p1, v0, v1
const-string p1, "Remove expired entry from %s cache, host(%s)"
invoke-static {p1, v0}, Lio/rong/imlib/httpdns/Logger;->printLog(Ljava/lang/String;[Ljava/lang/Object;)V
:cond_22
return-void
.end method
.method setHostCacheEntry(Ljava/lang/String;Lio/rong/imlib/httpdns/HostCacheManager$HostEntry;)V
.registers 8
.line 1
invoke-virtual {p2}, Lio/rong/imlib/httpdns/HostCacheManager$HostEntry;->getIpv4List()Ljava/util/ArrayList;
move-result-object v0
.line 2
invoke-virtual {p2}, Lio/rong/imlib/httpdns/HostCacheManager$HostEntry;->getIpv6List()Ljava/util/ArrayList;
move-result-object v1
if-eqz v0, :cond_10
.line 3
invoke-virtual {v0}, Ljava/util/ArrayList;->isEmpty()Z
move-result v2
if-eqz v2, :cond_19
:cond_10
if-eqz v1, :cond_4e
.line 4
invoke-virtual {v1}, Ljava/util/ArrayList;->isEmpty()Z
move-result v2
if-eqz v2, :cond_19
goto :goto_4e
.line 5
:cond_19
iget-object v2, p0, Lio/rong/imlib/httpdns/HostCacheManager;->hostCache:Landroid/util/LruCache;
invoke-virtual {v2, p1, p2}, Landroid/util/LruCache;->put(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;
const/4 v2, 0x5
.line 6
new-array v2, v2, [Ljava/lang/Object;
const/4 v3, 0x0
iget-object v4, p0, Lio/rong/imlib/httpdns/HostCacheManager;->dnsPrefix:Ljava/lang/String;
aput-object v4, v2, v3
const/4 v3, 0x1
aput-object p1, v2, v3
const/4 p1, 0x2
const/4 v3, 0x0
if-eqz v0, :cond_32
.line 7
invoke-virtual {v0}, Ljava/util/ArrayList;->toString()Ljava/lang/String;
move-result-object v0
goto :goto_33
:cond_32
move-object v0, v3
:goto_33
aput-object v0, v2, p1
const/4 p1, 0x3
if-eqz v1, :cond_3c
.line 8
invoke-virtual {v1}, Ljava/util/ArrayList;->toString()Ljava/lang/String;
move-result-object v3
:cond_3c
aput-object v3, v2, p1
const/4 p1, 0x4
invoke-virtual {p2}, Lio/rong/imlib/httpdns/HostCacheManager$HostEntry;->getTtl()J
move-result-wide v0
invoke-static {v0, v1}, Ljava/lang/Long;->valueOf(J)Ljava/lang/Long;
move-result-object p2
aput-object p2, v2, p1
const-string p1, "Set entry to %s cache, host(%s), ipv4List(%s), ipv6List(%s), ttl(%d)"
.line 9
invoke-static {p1, v2}, Lio/rong/imlib/httpdns/Logger;->printLog(Ljava/lang/String;[Ljava/lang/Object;)V
:cond_4e
:goto_4e
return-void
.end method
.method setStrictCachePolicy(Z)V
.registers 2
.line 1
iput-boolean p1, p0, Lio/rong/imlib/httpdns/HostCacheManager;->strictCachePolicy:Z
return-void
.end method