Use long uid in artery remoting and cluster #20644

This commit is contained in:
Johan Andrén 2016-09-26 15:34:59 +02:00 committed by GitHub
parent e9c4393f7b
commit 8ae0c9a888
37 changed files with 932 additions and 151 deletions

View file

@ -11,7 +11,9 @@ import akka.actor.ExtensionId
import akka.actor.ExtensionIdProvider
/**
* Extension that holds a uid that is assigned as a random `Int`.
* Extension that holds a uid that is assigned as a random `Long` or `Int` depending
* on which version of remoting that is used.
*
* The uid is intended to be used together with an [[akka.actor.Address]]
* to be able to distinguish restarted actor system using the same host
* and port.
@ -22,15 +24,26 @@ object AddressUidExtension extends ExtensionId[AddressUidExtension] with Extensi
override def lookup = AddressUidExtension
override def createExtension(system: ExtendedActorSystem): AddressUidExtension = new AddressUidExtension(system)
}
class AddressUidExtension(val system: ExtendedActorSystem) extends Extension {
private def arteryEnabled = system.provider.asInstanceOf[RemoteActorRefProvider].remoteSettings.Artery.Enabled
val longAddressUid: Long = {
// FIXME we should use a long here, but then we need to change in Cluster and RemoteWatcher also
//ThreadLocalRandom.current.nextLong()
ThreadLocalRandom.current.nextInt()
val tlr = ThreadLocalRandom.current
if (arteryEnabled) tlr.nextLong()
// with the old remoting we need to make toInt.toLong return the same number
// to keep wire compatibility
else tlr.nextInt().toLong
}
// used by old remoting and part of public api
@deprecated("Use longAddressUid instead", "2.4.x")
val addressUid: Int = longAddressUid.toInt
lazy val addressUid: Int = {
if (arteryEnabled) {
throw new IllegalStateException("Int UID must never be used with Artery")
} else longAddressUid.toInt
}
}