QueueDispatcher.smali 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247
  1. .class public Lokhttp3/mockwebserver/QueueDispatcher;
  2. .super Lokhttp3/mockwebserver/Dispatcher;
  3. .source ""
  4. # static fields
  5. .field private static final DEAD_LETTER:Lokhttp3/mockwebserver/MockResponse;
  6. .field private static final logger:Ljava/util/logging/Logger;
  7. # instance fields
  8. .field private failFastResponse:Lokhttp3/mockwebserver/MockResponse;
  9. .field protected final responseQueue:Ljava/util/concurrent/BlockingQueue;
  10. .annotation system Ldalvik/annotation/Signature;
  11. value = {
  12. "Ljava/util/concurrent/BlockingQueue<",
  13. "Lokhttp3/mockwebserver/MockResponse;",
  14. ">;"
  15. }
  16. .end annotation
  17. .end field
  18. # direct methods
  19. .method static constructor <clinit>()V
  20. .locals 2
  21. new-instance v0, Lokhttp3/mockwebserver/MockResponse;
  22. invoke-direct {v0}, Lokhttp3/mockwebserver/MockResponse;-><init>()V
  23. const-string v1, "HTTP/1.1 503 shutting down"
  24. invoke-virtual {v0, v1}, Lokhttp3/mockwebserver/MockResponse;->setStatus(Ljava/lang/String;)Lokhttp3/mockwebserver/MockResponse;
  25. move-result-object v0
  26. sput-object v0, Lokhttp3/mockwebserver/QueueDispatcher;->DEAD_LETTER:Lokhttp3/mockwebserver/MockResponse;
  27. const-class v0, Lokhttp3/mockwebserver/QueueDispatcher;
  28. invoke-virtual {v0}, Ljava/lang/Class;->getName()Ljava/lang/String;
  29. move-result-object v0
  30. invoke-static {v0}, Ljava/util/logging/Logger;->getLogger(Ljava/lang/String;)Ljava/util/logging/Logger;
  31. move-result-object v0
  32. sput-object v0, Lokhttp3/mockwebserver/QueueDispatcher;->logger:Ljava/util/logging/Logger;
  33. return-void
  34. .end method
  35. .method public constructor <init>()V
  36. .locals 1
  37. invoke-direct {p0}, Lokhttp3/mockwebserver/Dispatcher;-><init>()V
  38. new-instance v0, Ljava/util/concurrent/LinkedBlockingQueue;
  39. invoke-direct {v0}, Ljava/util/concurrent/LinkedBlockingQueue;-><init>()V
  40. iput-object v0, p0, Lokhttp3/mockwebserver/QueueDispatcher;->responseQueue:Ljava/util/concurrent/BlockingQueue;
  41. return-void
  42. .end method
  43. # virtual methods
  44. .method public dispatch(Lokhttp3/mockwebserver/RecordedRequest;)Lokhttp3/mockwebserver/MockResponse;
  45. .locals 3
  46. .annotation system Ldalvik/annotation/Throws;
  47. value = {
  48. Ljava/lang/InterruptedException;
  49. }
  50. .end annotation
  51. invoke-virtual {p1}, Lokhttp3/mockwebserver/RecordedRequest;->getRequestLine()Ljava/lang/String;
  52. move-result-object p1
  53. if-eqz p1, :cond_0
  54. const-string v0, "GET /favicon.ico HTTP/1.1"
  55. invoke-virtual {p1, v0}, Ljava/lang/String;->equals(Ljava/lang/Object;)Z
  56. move-result v0
  57. if-eqz v0, :cond_0
  58. sget-object v0, Lokhttp3/mockwebserver/QueueDispatcher;->logger:Ljava/util/logging/Logger;
  59. new-instance v1, Ljava/lang/StringBuilder;
  60. invoke-direct {v1}, Ljava/lang/StringBuilder;-><init>()V
  61. const-string v2, "served "
  62. invoke-virtual {v1, v2}, Ljava/lang/StringBuilder;->append(Ljava/lang/String;)Ljava/lang/StringBuilder;
  63. invoke-virtual {v1, p1}, Ljava/lang/StringBuilder;->append(Ljava/lang/String;)Ljava/lang/StringBuilder;
  64. invoke-virtual {v1}, Ljava/lang/StringBuilder;->toString()Ljava/lang/String;
  65. move-result-object p1
  66. invoke-virtual {v0, p1}, Ljava/util/logging/Logger;->info(Ljava/lang/String;)V
  67. new-instance p1, Lokhttp3/mockwebserver/MockResponse;
  68. invoke-direct {p1}, Lokhttp3/mockwebserver/MockResponse;-><init>()V
  69. const/16 v0, 0x194
  70. invoke-virtual {p1, v0}, Lokhttp3/mockwebserver/MockResponse;->setResponseCode(I)Lokhttp3/mockwebserver/MockResponse;
  71. move-result-object p1
  72. return-object p1
  73. :cond_0
  74. iget-object p1, p0, Lokhttp3/mockwebserver/QueueDispatcher;->failFastResponse:Lokhttp3/mockwebserver/MockResponse;
  75. if-eqz p1, :cond_1
  76. iget-object p1, p0, Lokhttp3/mockwebserver/QueueDispatcher;->responseQueue:Ljava/util/concurrent/BlockingQueue;
  77. invoke-interface {p1}, Ljava/util/concurrent/BlockingQueue;->peek()Ljava/lang/Object;
  78. move-result-object p1
  79. if-nez p1, :cond_1
  80. iget-object p1, p0, Lokhttp3/mockwebserver/QueueDispatcher;->failFastResponse:Lokhttp3/mockwebserver/MockResponse;
  81. return-object p1
  82. :cond_1
  83. iget-object p1, p0, Lokhttp3/mockwebserver/QueueDispatcher;->responseQueue:Ljava/util/concurrent/BlockingQueue;
  84. invoke-interface {p1}, Ljava/util/concurrent/BlockingQueue;->take()Ljava/lang/Object;
  85. move-result-object p1
  86. check-cast p1, Lokhttp3/mockwebserver/MockResponse;
  87. sget-object v0, Lokhttp3/mockwebserver/QueueDispatcher;->DEAD_LETTER:Lokhttp3/mockwebserver/MockResponse;
  88. if-ne p1, v0, :cond_2
  89. iget-object v1, p0, Lokhttp3/mockwebserver/QueueDispatcher;->responseQueue:Ljava/util/concurrent/BlockingQueue;
  90. invoke-interface {v1, v0}, Ljava/util/concurrent/BlockingQueue;->add(Ljava/lang/Object;)Z
  91. :cond_2
  92. return-object p1
  93. .end method
  94. .method public enqueueResponse(Lokhttp3/mockwebserver/MockResponse;)V
  95. .locals 1
  96. iget-object v0, p0, Lokhttp3/mockwebserver/QueueDispatcher;->responseQueue:Ljava/util/concurrent/BlockingQueue;
  97. invoke-interface {v0, p1}, Ljava/util/concurrent/BlockingQueue;->add(Ljava/lang/Object;)Z
  98. return-void
  99. .end method
  100. .method public peek()Lokhttp3/mockwebserver/MockResponse;
  101. .locals 1
  102. iget-object v0, p0, Lokhttp3/mockwebserver/QueueDispatcher;->responseQueue:Ljava/util/concurrent/BlockingQueue;
  103. invoke-interface {v0}, Ljava/util/concurrent/BlockingQueue;->peek()Ljava/lang/Object;
  104. move-result-object v0
  105. check-cast v0, Lokhttp3/mockwebserver/MockResponse;
  106. if-eqz v0, :cond_0
  107. return-object v0
  108. :cond_0
  109. iget-object v0, p0, Lokhttp3/mockwebserver/QueueDispatcher;->failFastResponse:Lokhttp3/mockwebserver/MockResponse;
  110. if-eqz v0, :cond_1
  111. return-object v0
  112. :cond_1
  113. invoke-super {p0}, Lokhttp3/mockwebserver/Dispatcher;->peek()Lokhttp3/mockwebserver/MockResponse;
  114. move-result-object v0
  115. return-object v0
  116. .end method
  117. .method public setFailFast(Lokhttp3/mockwebserver/MockResponse;)V
  118. .locals 0
  119. iput-object p1, p0, Lokhttp3/mockwebserver/QueueDispatcher;->failFastResponse:Lokhttp3/mockwebserver/MockResponse;
  120. return-void
  121. .end method
  122. .method public setFailFast(Z)V
  123. .locals 1
  124. if-eqz p1, :cond_0
  125. new-instance p1, Lokhttp3/mockwebserver/MockResponse;
  126. invoke-direct {p1}, Lokhttp3/mockwebserver/MockResponse;-><init>()V
  127. const/16 v0, 0x194
  128. invoke-virtual {p1, v0}, Lokhttp3/mockwebserver/MockResponse;->setResponseCode(I)Lokhttp3/mockwebserver/MockResponse;
  129. move-result-object p1
  130. goto :goto_0
  131. :cond_0
  132. const/4 p1, 0x0
  133. :goto_0
  134. invoke-virtual {p0, p1}, Lokhttp3/mockwebserver/QueueDispatcher;->setFailFast(Lokhttp3/mockwebserver/MockResponse;)V
  135. return-void
  136. .end method
  137. .method public shutdown()V
  138. .locals 2
  139. iget-object v0, p0, Lokhttp3/mockwebserver/QueueDispatcher;->responseQueue:Ljava/util/concurrent/BlockingQueue;
  140. sget-object v1, Lokhttp3/mockwebserver/QueueDispatcher;->DEAD_LETTER:Lokhttp3/mockwebserver/MockResponse;
  141. invoke-interface {v0, v1}, Ljava/util/concurrent/BlockingQueue;->add(Ljava/lang/Object;)Z
  142. return-void
  143. .end method