-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
finagle-core: Rename c.t.f.context.Retries to c.t.f.context.Requeues
Problem `c.t.f.context.Retries` is not an accurate name because it actually stores the number of *requeues* a request has had. Solution Rename it to `c.t.f.context.Requeues`. Differential Revision: https://phabricator.twitter.biz/D1104878
- Loading branch information
Showing
14 changed files
with
159 additions
and
110 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
23 changes: 13 additions & 10 deletions
23
...-base-http/src/main/scala/com/twitter/finagle/http/codec/context/HttpRetriesContext.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,26 @@ | ||
package com.twitter.finagle.http.codec.context | ||
|
||
import com.twitter.finagle.context.{Contexts, Retries} | ||
import com.twitter.util.{Return, Throw, Try} | ||
import com.twitter.finagle.context.Contexts | ||
import com.twitter.finagle.context.Requeues | ||
import com.twitter.util.Return | ||
import com.twitter.util.Throw | ||
import com.twitter.util.Try | ||
import scala.util.control.NonFatal | ||
|
||
private object HttpRetries extends HttpContext { | ||
private object HttpRequeues extends HttpContext { | ||
|
||
type ContextKeyType = Retries | ||
val key: Contexts.broadcast.Key[Retries] = Retries | ||
type ContextKeyType = Requeues | ||
val key: Contexts.broadcast.Key[Requeues] = Requeues | ||
|
||
def toHeader(retries: Retries): String = { | ||
retries.attempt.toString | ||
def toHeader(requeues: Requeues): String = { | ||
requeues.attempt.toString | ||
} | ||
|
||
def fromHeader(header: String): Try[Retries] = { | ||
def fromHeader(header: String): Try[Requeues] = { | ||
try { | ||
Return(Retries(header.toInt)) | ||
Return(Requeues(header.toInt)) | ||
} catch { | ||
case NonFatal(e) => Throw(new NumberFormatException) | ||
case NonFatal(_) => Throw(new NumberFormatException) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
46 changes: 46 additions & 0 deletions
46
finagle-core/src/main/scala/com/twitter/finagle/context/Requeues.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
package com.twitter.finagle.context | ||
|
||
import com.twitter.io.Buf | ||
import com.twitter.io.BufByteWriter | ||
import com.twitter.io.ByteReader | ||
import com.twitter.util.Return | ||
import com.twitter.util.Throw | ||
import com.twitter.util.Try | ||
|
||
/** | ||
* Requeues contains the number of times a request has been requeued. | ||
* | ||
* @param attempt which retry attempt this is. Will be 0 | ||
* if the request is not a requeue. | ||
*/ | ||
case class Requeues(attempt: Int) | ||
|
||
/** | ||
* Note: The context id is "c.t.f.Retries" and not "c.t.f.Requeues" because we have renamed the | ||
* Retries context to Requeues (to reflect what it actually contains, which is the requeues), but we | ||
* don't want to break existing users/deployments using this context by changing the key. | ||
*/ | ||
object Requeues extends Contexts.broadcast.Key[Requeues]("com.twitter.finagle.Retries") { | ||
|
||
def current: Option[Requeues] = | ||
Contexts.broadcast.get(Requeues) | ||
|
||
override def marshal(requeues: Requeues): Buf = { | ||
val bw = BufByteWriter.fixed(4) | ||
bw.writeIntBE(requeues.attempt) | ||
bw.owned() | ||
} | ||
|
||
override def tryUnmarshal(buf: Buf): Try[Requeues] = { | ||
if (buf.length != 4) { | ||
Throw( | ||
new IllegalArgumentException( | ||
s"Could not extract Requeues from Buf. Length ${buf.length} but required 4" | ||
) | ||
) | ||
} else { | ||
val attempt: Int = ByteReader(buf).readIntBE() | ||
Return(Requeues(attempt)) | ||
} | ||
} | ||
} |
37 changes: 0 additions & 37 deletions
37
finagle-core/src/main/scala/com/twitter/finagle/context/Retries.scala
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.