remove sequence id generator (#399)
This commit is contained in:
parent
5e3ac25490
commit
6bdce7f95b
1 changed files with 0 additions and 21 deletions
|
|
@ -13,8 +13,6 @@ import org.apache.pekko.annotation.InternalApi
|
|||
|
||||
import java.security.SecureRandom
|
||||
import java.util.concurrent.ThreadLocalRandom
|
||||
import java.util.concurrent.atomic.AtomicInteger
|
||||
import scala.annotation.tailrec
|
||||
|
||||
/**
|
||||
* INTERNAL API
|
||||
|
|
@ -59,23 +57,4 @@ private[pekko] object IdGenerator {
|
|||
def random(rand: java.util.Random): IdGenerator = new IdGenerator {
|
||||
override def nextId(): Short = rand.nextInt(Short.MaxValue).toShort
|
||||
}
|
||||
|
||||
/**
|
||||
* @return a predictable sequence of ids for tests
|
||||
*/
|
||||
def sequence(): IdGenerator = new IdGenerator {
|
||||
val requestId: AtomicInteger = new AtomicInteger(0)
|
||||
|
||||
@tailrec
|
||||
override final def nextId(): Short = {
|
||||
val oldId = requestId.get()
|
||||
val newId = (oldId + 1) % Short.MaxValue
|
||||
|
||||
if (requestId.compareAndSet(oldId, newId.intValue())) {
|
||||
newId.toShort
|
||||
} else {
|
||||
nextId()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue